From a0b8d4942497db40020d59aa9edc52f78c94021a Mon Sep 17 00:00:00 2001 From: Lewis Tunstall Date: Fri, 10 Nov 2023 10:49:13 +0000 Subject: [PATCH] Rename recipe --- recipes/{zephyr-7b => zephyr-7b-beta}/README.md | 8 ++++---- .../dpo/config_full.yaml | 0 .../dpo/config_lora.yaml | 1 - .../sft/config_full.yaml | 0 .../sft/config_lora.yaml | 6 ++---- scripts/README.md | 16 +++++++++------- 6 files changed, 15 insertions(+), 16 deletions(-) rename recipes/{zephyr-7b => zephyr-7b-beta}/README.md (85%) rename recipes/{zephyr-7b => zephyr-7b-beta}/dpo/config_full.yaml (100%) rename recipes/{zephyr-7b => zephyr-7b-beta}/dpo/config_lora.yaml (96%) rename recipes/{zephyr-7b => zephyr-7b-beta}/sft/config_full.yaml (100%) rename recipes/{zephyr-7b => zephyr-7b-beta}/sft/config_lora.yaml (94%) diff --git a/recipes/zephyr-7b/README.md b/recipes/zephyr-7b-beta/README.md similarity index 85% rename from recipes/zephyr-7b/README.md rename to recipes/zephyr-7b-beta/README.md index 4e783ad..3960ba5 100644 --- a/recipes/zephyr-7b/README.md +++ b/recipes/zephyr-7b-beta/README.md @@ -12,18 +12,18 @@ See below for commands to train these models using either DeepSpeed ZeRO-3 or Lo ```shell # Step 1 - SFT -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_sft.py recipes/zephyr-7b/sft/config_full.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_sft.py recipes/zephyr-7b-beta/sft/config_full.yaml # Step 2 - DPO -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_dpo.py recipes/zephyr-7b/dpo/config_full.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_dpo.py recipes/zephyr-7b-beta/beta/beta/beta/dpo/config_full.yaml ``` ## LoRA training examples ```shell # Step 1 - SFT -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/multi_gpu.yaml --num_processes=1 scripts/run_sft.py recipes/zephyr-7b/sft/config_lora.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/multi_gpu.yaml --num_processes=1 scripts/run_sft.py recipes/zephyr-7b-beta/beta/sft/config_lora.yaml # Step 2 - DPO -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/multi_gpu.yaml --num_processes=1 scripts/run_dpo.py recipes/zephyr-7b/dpo/config_lora.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/multi_gpu.yaml --num_processes=1 scripts/run_dpo.py recipes/zephyr-7b-beta/dpo/config_lora.yaml ``` \ No newline at end of file diff --git a/recipes/zephyr-7b/dpo/config_full.yaml b/recipes/zephyr-7b-beta/dpo/config_full.yaml similarity index 100% rename from recipes/zephyr-7b/dpo/config_full.yaml rename to recipes/zephyr-7b-beta/dpo/config_full.yaml diff --git a/recipes/zephyr-7b/dpo/config_lora.yaml b/recipes/zephyr-7b-beta/dpo/config_lora.yaml similarity index 96% rename from recipes/zephyr-7b/dpo/config_lora.yaml rename to recipes/zephyr-7b-beta/dpo/config_lora.yaml index 2e9bb28..38ac36a 100644 --- a/recipes/zephyr-7b/dpo/config_lora.yaml +++ b/recipes/zephyr-7b-beta/dpo/config_lora.yaml @@ -26,7 +26,6 @@ preprocessing_num_workers: 12 bf16: true beta: 0.1 do_eval: true -ddp_find_unused_parameters: true evaluation_strategy: epoch eval_steps: 100 gradient_accumulation_steps: 32 diff --git a/recipes/zephyr-7b/sft/config_full.yaml b/recipes/zephyr-7b-beta/sft/config_full.yaml similarity index 100% rename from recipes/zephyr-7b/sft/config_full.yaml rename to recipes/zephyr-7b-beta/sft/config_full.yaml diff --git a/recipes/zephyr-7b/sft/config_lora.yaml b/recipes/zephyr-7b-beta/sft/config_lora.yaml similarity index 94% rename from recipes/zephyr-7b/sft/config_lora.yaml rename to recipes/zephyr-7b-beta/sft/config_lora.yaml index c4288bb..3106a01 100644 --- a/recipes/zephyr-7b/sft/config_lora.yaml +++ b/recipes/zephyr-7b-beta/sft/config_lora.yaml @@ -3,7 +3,7 @@ model_name_or_path: mistralai/Mistral-7B-v0.1 torch_dtype: auto use_flash_attention_2: true -# LORA +# LoRA arguments use_peft: true lora_r: 64 lora_alpha: 16 @@ -27,7 +27,6 @@ bf16: true do_eval: true evaluation_strategy: epoch gradient_accumulation_steps: 128 -ddp_find_unused_parameters: true gradient_checkpointing: true gradient_checkpointing_kwargs: use_reentrant: False @@ -50,5 +49,4 @@ report_to: - tensorboard save_strategy: "no" save_total_limit: null -seed: 42 -tf32: true \ No newline at end of file +seed: 42 \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md index dcaa063..6af993c 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -6,7 +6,7 @@ In the handbook, we provide three main ways to align LLMs for chat: - Full fine-tuning on a multi-GPU machine with DeepSpeed ZeRO-3 (tested on an 8 x A100 (80GB) node). -- LoRA fine-tuning on a single consumer 24GB GPU (tested on a RTX 4090). +- LoRA or QLoRA fine-tuning on a single consumer 24GB GPU (tested on a RTX 4090). - LoRA fine-tuning on a multi-GPU machine with DeepSpeed ZeRO-3 (tested on a 2 x A100s (80GB)). In practice, we find comparable performance for both full and LoRA fine-tuning, with the latter having the advantage of producing small adapter weights that are fast to upload and download from the Hugging Face Hub. Here's the two general commands to fine-tune your models: @@ -22,16 +22,18 @@ ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_con ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml --num_processes={num_gpus} scripts/run_{task}.py recipes/{model_name}/{task}/config_lora.yaml ``` -Here `{task}` refers to type of training you wish to run (SFT, DPO, etc), while `{model_name}` refers to the choice of recipe in the `recipes/` directory. For example, to replicate Zephyr 7B you can run: +Here `{task}` refers to type of training you wish to run (SFT, DPO, etc), while `{model_name}` refers to the choice of recipe in the `recipes` directory. For example, to replicate Zephyr-7B-β you can run: ```shell # Step 1 - train SFT policy -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_sft.py recipes/zephyr-7b/sft/config_full.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_sft.py recipes/zephyr-7b-beta/sft/config_full.yaml # Step 2 - align with DPO -ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_dpo.py recipes/zephyr-7b/dpo/config_full.yaml +ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/deepspeed_zero3.yaml scripts/run_dpo.py recipes/zephyr-7b-beta/dpo/config_full.yaml ``` +** 💡 Tip:** If you scale the up/down the number of GPUs, we recommend also scaling up the per-device batch size or number of gradient accumulation steps to keep the global batch size constant (and thus replicate our results). + By default, these scripts will push each model to your Hugging Face Hub username, i.e. `{username}/{model_name}-{task}`. You can override the parameters in each YAML config by appending them to the command as follows: ```shell @@ -56,9 +58,9 @@ sbatch --job-name=handbook_{task} --nodes=1 recipes/launch.slurm {model_name} {t Here `{model_name}` and `{task}` are defined as above, while `{precision}` refers to the type of training (full vs LoRA) and `{accelerator}` refers to the choice of 🤗 Accelerate config in `recipes/accelerate_configs`. Here's a concrete example to run SFT on 1 node of 8 GPUs: ```shell -sbatch --job-name=handbook_sft --nodes=1 recipes/launch.slurm zephyr-7b sft full deepspeed_zero3 +sbatch --job-name=handbook_sft --nodes=1 recipes/launch.slurm zephyr-7b-beta sft full deepspeed_zero3 ``` -You can scale the number of nodes by increasing the `--nodes` flag; in these cases we recommend also scaling up the per-device batch size or number of gradient accumulation steps to keep the global batch size constant (and thus replicate our results). +You can scale the number of nodes by increasing the `--nodes` flag. -**Note:** the configuration in `recipes/launch.slurm` is optimised for the Hugging Face Compute Cluster and may require tweaking to be adapted to your own compute nodes. \ No newline at end of file +**⚠️ Note:** the configuration in `recipes/launch.slurm` is optimised for the Hugging Face Compute Cluster and may require tweaking to be adapted to your own compute nodes. \ No newline at end of file