Skip to content

Commit

Permalink
fixes for modelsmith on local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pop John committed Aug 5, 2024
1 parent d80628c commit c375b51
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
13 changes: 9 additions & 4 deletions utils/setup_environment.sh → backend/setup_environment.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Copyright 2024 Cisco Systems, Inc. and its affiliates

# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,8 +16,6 @@

# SPDX-License-Identifier: Apache-2.0

#!/bin/bash

cd "$(dirname "$0")/.."
PROJECT_ROOT="$(pwd)"
backend_path="$PROJECT_ROOT/backend"
Expand Down Expand Up @@ -60,19 +60,24 @@ create_update_env_file() {
mkdir -p "$backend_path"

local machine_learning_core_path="../machine_learning_core"
echo -e "${YELLOW}Enter CONDA_SH_PATH:${NC}"
read -p "(e.g., ~/miniconda3/etc/profile.d/conda.sh): " conda_sh_path
echo -e "${YELLOW}Enter CONDA_SH_PATH (press Enter for default):${NC}"
read -p "(default: ~/miniconda3/etc/profile.d/conda.sh): " conda_sh_path
conda_sh_path=${conda_sh_path:-~/miniconda3/etc/profile.d/conda.sh}

if [[ $env_choice == "2" ]]; then
echo -e "${YELLOW}Enter MACHINE_LEARNING_CORE_PATH for VM:${NC}"
read -p "(e.g., /path/to/machine_learning_core on VM): " machine_learning_core_vm_path
machine_learning_core_path="$machine_learning_core_vm_path"
fi

echo -e "${YELLOW}Enter HUGGING_FACE_ACCESS_TOKEN:${NC}"
read -p "(e.g., your_hugging_face_access_token): " hugging_face_access_token

{
echo "PORT=3000"
echo "MACHINE_LEARNING_CORE_PATH=$machine_learning_core_path"
echo "CONDA_SH_PATH=$conda_sh_path"
echo "HUGGING_FACE_ACCESS_TOKEN=$hugging_face_access_token"
echo ""
} > "$env_file"

Expand Down
1 change: 1 addition & 0 deletions backend/src/facades/algorithmExecutionFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ScriptExecutor {
if (this.type === ALGORITHM_TYPES.MULTIFLOW) {
return `bash -c "source ${process.env.CONDA_SH_PATH} && cd ${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow && conda activate modelsmith && python3 ${algorithm} ${args}"`;
}

return `bash -c "source ${process.env.CONDA_SH_PATH} && conda activate modelsmith && python3 ${scriptPath}${algorithm} ${args}"`;
}

Expand Down
9 changes: 8 additions & 1 deletion backend/src/router/modelsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ router.get('/models-list/:type', checkSshConnection, (req, res) => {

res.status(OK).send(modelsWithTrainingInfo);
},
() => {},
() => {
const modelsAreNotTrained = models.map((modelName) => ({
name: modelName,
isTrained: false
}));

res.status(OK).send(modelsAreNotTrained);
},
(error) => {
if (error.includes('No such file or directory')) {
const modelsWithTrainingInfo = models.map((modelName) => ({
Expand Down
10 changes: 9 additions & 1 deletion docs/configure-modelsmith-on-vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ conda --version

## Phase 2: Configure the Environment

On your local machine, run the `setup_environment.sh` script located in the `utils` directory of the repository. This script configures the `.env` file for the backend server. When prompted for the environment for model training, select "2. VM" and provide the necessary SSH details for the primary and, optionally, backup VMs.
After configuring the Python environment, the next step involves setting up the project environment. This is done by executing the `setup_environment.sh` script located in the `backend` directory. The script performs several tasks, including setting up the `.env` file for the backend server.

Execute the script by running:

```bash
bash backend/setup_environment.sh
```

When asked about "Select the environment for model training:" -> choose 2. VM

### Example .env Configuration for VM Usage

Expand Down
2 changes: 2 additions & 0 deletions docs/configure-pruning-quant-ml.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Configure ModelSmith with Pruning, Quantization, and Machine Unlearning

**Note**: The training of models can also be performed from the frontend page after starting the app - [Model Training](http://localhost:4200/model-training).

This guide provides detailed steps to configure and train models using ModelSmith for pruning, quantization, and machine unlearning.

## Prerequisites
Expand Down
48 changes: 41 additions & 7 deletions docs/configure-the-project-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,75 @@ node -v

To get started, you need to set up the Python environment for ModelSmith. This involves creating a new Conda environment and installing the necessary packages. Follow these steps:

1. **Create and Activate a New Conda Environment**
1. **Install Miniconda**: Miniconda is a minimal installer for Conda, which is an open-source package management system and environment management system. Installing Miniconda on the VM will help manage the Python environment and dependencies required for the ModelSmith project. Here's how to download and install Miniconda:

1.1. Download the Miniconda installer for Linux:

```bash
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
```

1.2. Make the installer script executable:

```bash
chmod +x Miniconda3-latest-Linux-x86_64.sh
```

1.3. Run the installer script:

```bash
./Miniconda3-latest-Linux-x86_64.sh
```

Follow the on-screen prompts to complete the installation. It is generally safe to accept the default installation settings. Make sure to agree to initialize Miniconda by running `conda init`.

1.4. After installation, restart your terminal or source your `.bashrc` file to make the `conda` command available:

```bash
source ~/.bashrc
```

1.5. Verify the installation by checking the Conda version:

```bash
conda --version
```

2. **Create and Activate a New Conda Environment**
Open a terminal and run the following commands:

```bash
conda create -n modelsmith python=3.9
conda activate modelsmith
```

2. **Install PyTorch and Related Libraries**
3. **Install PyTorch and Related Libraries**
With the environment activated, install PyTorch, torchvision, and torchaudio for CUDA 11.8 by running:

```bash
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
```

3. **Configure Pruning, Quantization, Machine Unlearning Python Projects**:
4. **Configure Pruning, Quantization, Machine Unlearning Python Projects**:

Please refer to the [Pruning, Quantization, Machine Unlearning Configuration Guide](configure-pruning-quant-ml.md) for detailed instructions.

4. **Configure AutoAWQ for Model Quantization**:
5. **Configure AutoAWQ for Model Quantization**:

Please refer to the [AutoAWQ Configuration Guide](configure-autoawq.md) for detailed instructions.

5. **Configure Multiflow Python Project**:
6. **Configure Multiflow Python Project**:

Please refer to the [Multiflow Configuration Guide](configure-multiflow.md) for detailed instructions.

## Phase 2: Run the Environment Setup Script

After configuring the Python environment, the next step involves setting up the project environment. This is done by executing the `setup_environment.sh` script located in the `utils` directory. The script performs several tasks, including setting up the `.env` file for the backend server.
After configuring the Python environment, the next step involves setting up the project environment. This is done by executing the `setup_environment.sh` script located in the `backend` directory. The script performs several tasks, including setting up the `.env` file for the backend server.

Execute the script by running:

```bash
bash utils/setup_environment.sh
bash backend/setup_environment.sh
```

When asked about "Select the environment for model training:" -> choose 1. Local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<mat-expansion-panel-header>
<mat-panel-title class="paragraph-bold-p3-small-bold"> Statistics </mat-panel-title>
</mat-expansion-panel-header>
@if (summarizedRecord?.statistics | keyvalue; as statisticsItems) { @for (item of statisticsItems; track item;
@if (summarizedRecord.statistics | keyvalue; as statisticsItems) { @for (item of statisticsItems; track item;
let last = $last) {
<div class="key-value-container single">
<div class="key-value-pair space-between">
Expand All @@ -78,7 +78,7 @@
<mat-expansion-panel-header>
<mat-panel-title class="paragraph-bold-p3-small-bold"> Model training details </mat-panel-title>
</mat-expansion-panel-header>
@if (summarizedRecord?.modelTrainingDetails | hasKeys) { @for (item of summarizedRecord?.modelTrainingDetails |
@if (summarizedRecord.modelTrainingDetails | hasKeys) { @for (item of summarizedRecord.modelTrainingDetails |
keyvalue; track item; let last = $last) {
<div class="key-value-container single">
<div class="key-value-pair space-between">
Expand Down
2 changes: 1 addition & 1 deletion machine_learning_core/bash/kill_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi
PROCESS_NAME="$1"

# Fetch all processes that have the name $PROCESS_NAME
PIDS=$(ps aux | grep $PROCESS_NAME | grep -v grep | awk '{print $2}')
PIDS=$(ps -ef | grep "$PROCESS_NAME" | grep -v grep | awk '{print $2}')

if [ -z "$PIDS" ]; then
echo "No process found for $PROCESS_NAME"
Expand Down
2 changes: 1 addition & 1 deletion start_modelsmith.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ env_file="$PROJECT_ROOT/backend/.env"
# Check if .env file exists and call setup_environment.sh if needed
if [ ! -f "$env_file" ]; then
# Call the setup script from the utils directory
bash "$PROJECT_ROOT/utils/setup_environment.sh"
bash "$PROJECT_ROOT/backend/setup_environment.sh"
fi

# Start backend and frontend servers
Expand Down
3 changes: 2 additions & 1 deletion utils/deploy_vm_modelsmith_options.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Copyright 2024 Cisco Systems, Inc. and its affiliates

# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,7 +16,6 @@

# SPDX-License-Identifier: Apache-2.0

#!/bin/bash

# ANSI color codes
GREEN="\033[0;32m"
Expand Down

0 comments on commit c375b51

Please sign in to comment.