From 1bf437694cfc924d71140c5a0513d98862b40234 Mon Sep 17 00:00:00 2001 From: MervinPraison Date: Sun, 4 Aug 2024 09:57:37 +0100 Subject: [PATCH] Install conda for praisonai train --- .praisoninclude | 3 +- Dockerfile | 2 +- config.yaml | 58 ++++++++++++++++++++++++++++++ docs/api/praisonai/deploy.html | 2 +- praisonai.rb | 2 +- praisonai/cli.py | 34 ++++++++++++++++-- praisonai/deploy.py | 2 +- praisonai/setup/config.yaml | 58 ++++++++++++++++++++++++++++++ praisonai/setup/setup_conda_env.sh | 32 +++++++++++------ pyproject.toml | 2 +- 10 files changed, 177 insertions(+), 18 deletions(-) create mode 100644 config.yaml create mode 100644 praisonai/setup/config.yaml diff --git a/.praisoninclude b/.praisoninclude index 1762e91b..fb93548b 100644 --- a/.praisoninclude +++ b/.praisoninclude @@ -1,2 +1,3 @@ # praisonai/ui/context.py -# /Users/praison/miniconda3/envs/praisonai-package/lib/python3.11/site-packages/llama_index/packs/code_hierarchy/code_hierarchy.py \ No newline at end of file +# /Users/praison/miniconda3/envs/praisonai-package/lib/python3.11/site-packages/llama_index/packs/code_hierarchy/code_hierarchy.py +praisonai/setup \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index baf1117c..cbc12b2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.11-slim WORKDIR /app COPY . . -RUN pip install flask praisonai==0.0.59rc5 gunicorn markdown +RUN pip install flask praisonai==0.0.59rc6 gunicorn markdown EXPOSE 8080 CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"] diff --git a/config.yaml b/config.yaml new file mode 100644 index 00000000..29d2c10e --- /dev/null +++ b/config.yaml @@ -0,0 +1,58 @@ +model_name: "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit" +hf_model_name: "mervinpraison/llama-3.1-tamilan-8B-test" +max_seq_length: 2048 +load_in_4bit: true +lora_r: 16 +lora_target_modules: + - "q_proj" + - "k_proj" + - "v_proj" + - "o_proj" + - "gate_proj" + - "up_proj" + - "down_proj" +lora_alpha: 16 +lora_dropout: 0 +lora_bias: "none" +use_gradient_checkpointing: "unsloth" +random_state: 3407 +use_rslora: false +loftq_config: null + +dataset: + - name: "yahma/alpaca-cleaned" + split_type: "train" + processing_func: "format_prompts" + rename: + input: "input" + output: "output" + instruction: "instruction" + filter_data: false + filter_column_value: "id" + filter_value: "alpaca" + num_samples: 20000 + +dataset_text_field: "text" +dataset_num_proc: 2 +packing: false + +per_device_train_batch_size: 2 +gradient_accumulation_steps: 2 +warmup_steps: 5 +num_train_epochs: 1 +max_steps: 10 +learning_rate: 2.0e-4 +logging_steps: 1 +optim: "adamw_8bit" +weight_decay: 0.01 +lr_scheduler_type: "linear" +seed: 3407 +output_dir: "outputs" + +quantization_method: + - "q4_k_m" + - "q8_0" + - "q5_k_m" + +ollama_model: "llama3.1-tamilan-test" +model_parameters: "8b" \ No newline at end of file diff --git a/docs/api/praisonai/deploy.html b/docs/api/praisonai/deploy.html index 41d48fef..557bf348 100644 --- a/docs/api/praisonai/deploy.html +++ b/docs/api/praisonai/deploy.html @@ -110,7 +110,7 @@

Raises

file.write("FROM python:3.11-slim\n") file.write("WORKDIR /app\n") file.write("COPY . .\n") - file.write("RUN pip install flask praisonai==0.0.59rc5 gunicorn markdown\n") + file.write("RUN pip install flask praisonai==0.0.59rc6 gunicorn markdown\n") file.write("EXPOSE 8080\n") file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n') diff --git a/praisonai.rb b/praisonai.rb index c0967985..6f67cf14 100644 --- a/praisonai.rb +++ b/praisonai.rb @@ -3,7 +3,7 @@ class Praisonai < Formula desc "AI tools for various AI applications" homepage "https://github.com/MervinPraison/PraisonAI" - url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59rc5.tar.gz" + url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59rc6.tar.gz" sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum license "MIT" diff --git a/praisonai/cli.py b/praisonai/cli.py index f9a851ff..4db1c173 100644 --- a/praisonai/cli.py +++ b/praisonai/cli.py @@ -100,12 +100,42 @@ def main(self): return if args.agent_file == 'train': + import subprocess + package_root = os.path.dirname(os.path.abspath(__file__)) + config_yaml_source = os.path.join(package_root, 'setup', 'config.yaml') + config_yaml_destination = os.path.join(os.getcwd(), 'config.yaml') + + if not os.path.exists(config_yaml_destination): + try: + shutil.copyfile(config_yaml_source, config_yaml_destination) + print("config.yaml copied to the current directory.") + except FileExistsError: + print("config.yaml already exists in the current directory. Skipping copy.") + else: + print("config.yaml already exists in the current directory. Skipping copy.") + if 'init' in sys.argv: from praisonai.setup.setup_conda_env import main as setup_conda_main setup_conda_main() - from .train import main as train_main + print("All packages installed") + return + + try: + result = subprocess.check_output(['conda', 'env', 'list']) + if 'unsloth_env' in result.decode('utf-8'): + print("Conda environment 'unsloth_env' found.") + else: + raise subprocess.CalledProcessError(1, 'grep') + except subprocess.CalledProcessError: + print("Conda environment 'unsloth_env' not found. Setting it up...") + from praisonai.setup.setup_conda_env import main as setup_conda_main + setup_conda_main() + print("All packages installed.") + + train_args = sys.argv[2:] # Get all arguments after 'train' - train_main() + train_script_path = os.path.join(package_root, 'train.py') + subprocess.check_call(['conda', 'run', '--name', 'unsloth_env', 'python', train_script_path]) return invocation_cmd = "praisonai" diff --git a/praisonai/deploy.py b/praisonai/deploy.py index 53026146..d9c41d03 100644 --- a/praisonai/deploy.py +++ b/praisonai/deploy.py @@ -56,7 +56,7 @@ def create_dockerfile(self): file.write("FROM python:3.11-slim\n") file.write("WORKDIR /app\n") file.write("COPY . .\n") - file.write("RUN pip install flask praisonai==0.0.59rc5 gunicorn markdown\n") + file.write("RUN pip install flask praisonai==0.0.59rc6 gunicorn markdown\n") file.write("EXPOSE 8080\n") file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n') diff --git a/praisonai/setup/config.yaml b/praisonai/setup/config.yaml new file mode 100644 index 00000000..29d2c10e --- /dev/null +++ b/praisonai/setup/config.yaml @@ -0,0 +1,58 @@ +model_name: "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit" +hf_model_name: "mervinpraison/llama-3.1-tamilan-8B-test" +max_seq_length: 2048 +load_in_4bit: true +lora_r: 16 +lora_target_modules: + - "q_proj" + - "k_proj" + - "v_proj" + - "o_proj" + - "gate_proj" + - "up_proj" + - "down_proj" +lora_alpha: 16 +lora_dropout: 0 +lora_bias: "none" +use_gradient_checkpointing: "unsloth" +random_state: 3407 +use_rslora: false +loftq_config: null + +dataset: + - name: "yahma/alpaca-cleaned" + split_type: "train" + processing_func: "format_prompts" + rename: + input: "input" + output: "output" + instruction: "instruction" + filter_data: false + filter_column_value: "id" + filter_value: "alpaca" + num_samples: 20000 + +dataset_text_field: "text" +dataset_num_proc: 2 +packing: false + +per_device_train_batch_size: 2 +gradient_accumulation_steps: 2 +warmup_steps: 5 +num_train_epochs: 1 +max_steps: 10 +learning_rate: 2.0e-4 +logging_steps: 1 +optim: "adamw_8bit" +weight_decay: 0.01 +lr_scheduler_type: "linear" +seed: 3407 +output_dir: "outputs" + +quantization_method: + - "q4_k_m" + - "q8_0" + - "q5_k_m" + +ollama_model: "llama3.1-tamilan-test" +model_parameters: "8b" \ No newline at end of file diff --git a/praisonai/setup/setup_conda_env.sh b/praisonai/setup/setup_conda_env.sh index 4cb9aecf..051387b9 100755 --- a/praisonai/setup/setup_conda_env.sh +++ b/praisonai/setup/setup_conda_env.sh @@ -35,8 +35,16 @@ fi # Create and activate the Conda environment ENV_NAME="unsloth_env" if conda info --envs | grep -q $ENV_NAME; then - echo "Environment $ENV_NAME already exists. Activating..." - conda activate $ENV_NAME + echo "Environment $ENV_NAME already exists. Recreating..." + conda env remove -y -n $ENV_NAME # Remove existing environment + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS (both Intel and M1/M2) + conda create --name $ENV_NAME python=3.10 pytorch=2.3.0 -c pytorch -y + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + conda create --name $ENV_NAME python=3.10 pytorch=2.3.0 cudatoolkit=11.8 -c pytorch -c nvidia -y + fi + # conda activate $ENV_NAME else echo "Creating new environment $ENV_NAME..." if [[ "$OSTYPE" == "darwin"* ]]; then @@ -45,16 +53,20 @@ else elif [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux conda create --name $ENV_NAME python=3.10 pytorch=2.3.0 cudatoolkit=11.8 -c pytorch -c nvidia -y - conda activate $ENV_NAME - pip install xformers==0.0.26.post1 fi + # conda activate $ENV_NAME fi -source $HOME/miniconda/bin/activate $ENV_NAME +# source $HOME/miniconda/bin/activate $ENV_NAME + +# Get full path of pip +PIP_FULL_PATH=$(conda run -n $ENV_NAME which pip) -# Install other packages -pip install --upgrade pip -pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git@4e570be9ae4ced8cdc64e498125708e34942befc" -pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes +# Install other packages within the activated environment +# Use PIP_FULL_PATH to run pip commands +$PIP_FULL_PATH install --upgrade pip +$PIP_FULL_PATH install "xformers==0.0.26.post1" +$PIP_FULL_PATH install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git@4e570be9ae4ced8cdc64e498125708e34942befc" +$PIP_FULL_PATH install --no-deps "trl<0.9.0" peft accelerate bitsandbytes -echo "Setup completed successfully!" \ No newline at end of file +echo "Setup completed successfully!" diff --git a/pyproject.toml b/pyproject.toml index f55ad2d0..53e63193 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PraisonAI" -version = "0.0.59rc5" +version = "0.0.59rc6" description = "PraisonAI application combines AutoGen and CrewAI or similar frameworks into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customization, and efficient human-agent collaboration." authors = ["Mervin Praison"] license = ""