
An extensible, convenient, and efficient toolbox for finetuning large machine learning models, designed to be user-friendly, speedy and reliable, and accessible to the entire community.

git checkout lmflow-nightly.chatml (see all templates here), and we are working on adding more preset templates. Adding corresponding --conversation_template in the shell script and you are all set! :rocket:More news...

pip install lmflow-finetune![2023-05-30] Release Robin-13B-v2 and Robin-33B-v2!
[2023-05-15] Release LMFlow-data, the training dataset of Robin-7B-v2. A new test data is also released.
Our package has been tested on Linux OS (Ubuntu 20.04). Other OS platforms (MacOS, Windows) are not fully tested, where you may encounter unexpected errors. If you are using LMFlow for the first time, we recommend you to try on a Linux machine or Google Colab.
git clone -b v0.0.9 https://github.com/OptimalScale/LMFlow.git
cd LMFlow
conda create -n lmflow python=3.9 -y
conda activate lmflow
conda install mpi4py
pip install -e .
for CUDA versions 10.3-11.7
git clone -b v0.0.5 https://github.com/OptimalScale/LMFlow.git
cd LMFlow
conda create -n lmflow python=3.9 -y
conda activate lmflow
conda install mpi4py
pip install -e .
[!TIP] We use WandB to track and visualize the training process by default. Before running the training scripts, users may need to log in to WandB using the command:
bash wandb loginFor detailed instructions, refer to the WandB Quickstart Guide. Step 1 (registration) and Step 2 (login using your WandB API key) should be sufficient to set up your environment.
Disabling wandb
One can disable wandb by either:
- Adding environment variable before running the training command.
bash export WANDB_MODE=disabled
- OR, specifying the integrations to report the results and logs to. In the training script, add:
bash --report_to none \
Please refer to our doc.
| Method | 0.5B | 3B | 7B | 14B | 30B | 70B | xB |
|---|---|---|---|---|---|---|---|
Full bf16/fp16 |
9GB | 55GB | 120GB | 240GB | 600GB | 1200GB | 18xGB |
| LoRA | 1GB | 6GB | 16GB | 32GB | 64GB | 160GB | 2xGB |
QLoRA quant_bit=8 |
0.7GB | 3GB | 10GB | 20GB | 40GB | 80GB | xGB |
QLoRA quant_bit=4 |
0.4GB | 1.5GB | 6GB | 12GB | 24GB | 48GB | x/2GB |
Full training updates all the parameters to finetune a language model. Here is an example to finetune a GPT-2 base model.
cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune.sh \
--model_name_or_path gpt2 \
--dataset_path data/alpaca/train_conversation \
--output_model_path output_models/finetuned_gpt2
[!TIP] For conversation dataset, specify a conversation template for better performance by adding
--conversation_templateto the command.
Llama-3-8B conversation dataset example
```bash cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune.sh \ --model_name_or_path meta-llama/Meta-Llama-3-8B \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama3 \ --output_model_path output_models/finetuned_llama3_8b ```
LISA is a memory-efficient finetuning algorithm that allows tradeoff between memory and the number of randomly unfreezed layers. This script currently is only tested in single gpus. Please stay tuned for our latest updates :smile:
cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune_with_lisa.sh \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--dataset_path data/alpaca/train_conversation \
--output_model_path output_models/finetuned_llama2_7b \
--lisa_activated_layers 1 \
--lisa_interval_steps 20
[!TIP]
Llama-2-7B conversation dataset example
```bash cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama2 \ --output_model_path output_models/finetuned_llama2_7b_lisa \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ```
LoRA is a parameter-efficient finetuning algorithm and is more efficient than full finetuning.
cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune_with_lora.sh \
--model_name_or_path facebook/galactica-1.3b \
--dataset_path data/alpaca/train_conversation \
--output_lora_path output_models/finetuned_galactica_lora
[!TIP]
Llama-2-7B conversation dataset example
```bash cd data && ./download.sh alpaca && cd -
bash ./scripts/run_finetune_with_lora.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama2 \ --output_model_path output_models/finetuned_llama2_7b_lora \ ```
Merge LoRA Weight
Merge LoRA weight and the base model into one using:
```sh bash
$ claude mcp add LMFlow \
-- python -m otcore.mcp_server <graph>