Easy and Efficient Fine-tuning LLMs --- 简单高效的大语言模型训练/部署

January 15, 2025 · View on GitHub

 

GitHub Repo stars GitHub Code License GitHub last commit GitHub pull request issue resolution open issues Python 3.9+ Code style: black

👋🤗🤗👋 Join our WeChat.

Easy and Efficient Fine-tuning LLMs --- 简单高效的大语言模型训练/部署

中文 | English

Introduction

LLamaTuner is an efficient, flexible and full-featured toolkit for fine-tuning LLM (Llama3, Phi3, Qwen, Mistral, ...)

Efficient

  • Support LLM, VLM pre-training / fine-tuning on almost all GPUs. LLamaTuner is capable of fine-tuning 7B LLM on a single 8GB GPU, as well as multi-node fine-tuning of models exceeding 70B.
  • Automatically dispatch high-performance operators such as FlashAttention and Triton kernels to increase training throughput.
  • Compatible with DeepSpeed 🚀, easily utilizing a variety of ZeRO optimization techniques.

Flexible

  • Support various LLMs (Llama 3, Mixtral, Llama 2, ChatGLM, Qwen, Baichuan, ...).
  • Support VLM (LLaVA).
  • Well-designed data pipeline, accommodating datasets in any format, including but not limited to open-source and custom formats.
  • Support various training algorithms (QLoRA, LoRA, full-parameter fune-tune), allowing users to choose the most suitable solution for their requirements.

Full-featured

  • Support continuous pre-training, instruction fine-tuning, and agent fine-tuning.
  • Support chatting with large models with pre-defined templates.

Table of Contents

Supported Models

ModelModel sizeDefault moduleTemplate
Baichuan7B/13BW_packbaichuan
Baichuan27B/13BW_packbaichuan2
BLOOM560M/1.1B/1.7B/3B/7.1B/176Bquery_key_value-
BLOOMZ560M/1.1B/1.7B/3B/7.1B/176Bquery_key_value-
ChatGLM36Bquery_key_valuechatglm3
Command-R35B/104Bq_proj,v_projcohere
DeepSeek (MoE)7B/16B/67B/236Bq_proj,v_projdeepseek
Falcon7B/11B/40B/180Bquery_key_valuefalcon
Gemma/CodeGemma2B/7Bq_proj,v_projgemma
InternLM27B/20Bwqkvintern2
LLaMA7B/13B/33B/65Bq_proj,v_proj-
LLaMA-27B/13B/70Bq_proj,v_projllama2
LLaMA-38B/70Bq_proj,v_projllama3
LLaVA-1.57B/13Bq_proj,v_projvicuna
Mistral/Mixtral7B/8x7B/8x22Bq_proj,v_projmistral
OLMo1B/7Bq_proj,v_proj-
PaliGemma3Bq_proj,v_projgemma
Phi-1.5/21.3B/2.7Bq_proj,v_proj-
Phi-33.8Bqkv_projphi
Qwen1.8B/7B/14B/72Bc_attnqwen
Qwen1.5 (Code/MoE)0.5B/1.8B/4B/7B/14B/32B/72B/110Bq_proj,v_projqwen
StarCoder23B/7B/15Bq_proj,v_proj-
XVERSE7B/13B/65Bq_proj,v_projxverse
Yi (1/1.5)6B/9B/34Bq_proj,v_projyi
Yi-VL6B/34Bq_proj,v_projyi_vl
Yuan2B/51B/102Bq_proj,v_projyuan

Supported Training Approaches

ApproachFull-tuningFreeze-tuningLoRAQLoRA
Pre-Training:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Supervised Fine-Tuning:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Reward Modeling:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
PPO Training:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
DPO Training:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
KTO Training:white_check_mark::white_check_mark::white_check_mark::white_check_mark:
ORPO Training:white_check_mark::white_check_mark::white_check_mark::white_check_mark:

Supported Datasets

As of now, we support the following datasets, most of which are all available in the Hugging Face datasets library.

Supervised fine-tuning dataset
Preference datasets

Please refer to data/README.md to learn how to use these datasets. If you want to explore more datasets, please refer to the awesome-instruction-datasets. Some datasets require confirmation before using them, so we recommend logging in with your Hugging Face account using these commands.

pip install --upgrade huggingface_hub
huggingface-cli login

Data Preprocessing

We provide a number of data preprocessing tools in the data folder. These tools are intended to be a starting point for further research and development.

Model Zoo

We provide a number of models in the Hugging Face model hub. These models are trained with QLoRA and can be used for inference and finetuning. We provide the following models:

Base ModelAdapterInstruct DatasetsTrain ScriptLogModel on Huggingface
llama-7bFullFinetune---
llama-7bQLoRAopenassistant-guanacofinetune_lamma7bwandb logGaussianTech/llama-7b-sft
llama-7bQLoRAOL-CCfinetune_lamma7b
baichuan7bQLoRAopenassistant-guanacofinetune_baichuan7bwandb logGaussianTech/baichuan-7b-sft
baichuan7bQLoRAOL-CCfinetune_baichuan7bwandb log-

Requirement

MandatoryMinimumRecommend
python3.83.10
torch1.13.12.2.0
transformers4.37.24.41.0
datasets2.14.32.19.1
accelerate0.27.20.30.1
peft0.9.00.11.1
trl0.8.20.8.6
OptionalMinimumRecommend
CUDA11.612.2
deepspeed0.10.00.14.0
bitsandbytes0.39.00.43.1
vllm0.4.00.4.2
flash-attn2.3.02.5.8

Hardware Requirement

* estimated

MethodBits7B13B30B70B110B8x7B8x22B
FullAMP120GB240GB600GB1200GB2000GB900GB2400GB
Full1660GB120GB300GB600GB900GB400GB1200GB
Freeze1620GB40GB80GB200GB360GB160GB400GB
LoRA/GaLore/BAdam1616GB32GB64GB160GB240GB120GB320GB
QLoRA810GB20GB40GB80GB140GB60GB160GB
QLoRA46GB12GB24GB48GB72GB30GB96GB
QLoRA24GB8GB16GB24GB48GB18GB48GB

Getting Started

Clone the code

Clone this repository and navigate to the Efficient-Tuning-LLMs folder

git clone https://github.com/jianzhnie/LLamaTuner.git
cd LLamaTuner

Getting Started

main functionUseageScripts
train_full.pyFull finetune LLMs on SFT datasetsfull_finetune
train_lora.pyFinetune LLMs by using Lora (Low-Rank Adaptation of Large Language Models finetune)lora_finetune
train_qlora.pyFinetune LLMs by using QLora (QLoRA: Efficient Finetuning of Quantized LLMs)qlora_finetune

License

LLamaTuner is released under the Apache 2.0 license.

Acknowledgements

We thank the Huggingface team, in particular Younes Belkada, for their support integrating QLoRA with PEFT and transformers libraries.

We appreciate the work by many open-source contributors, especially:

Citation

Please cite the repo if you use the data or code in this repo.

@misc{Chinese-Guanaco,
  author = {jianzhnie},
  title = {LLamaTuner: Easy and Efficient Fine-tuning LLMs},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/jianzhnie/LLamaTuner}},
}