type
status
date
slug
tags
summary
category
password
icon
FastChat is an open platform for training, serving, and evaluating chatbots based on large language models. This tutorial shows you how to use FastChat for a simple fine-tuning demonstration.
1. Installation
- Clone the repository.
git clone https://github.com/lm-sys/FastChat.git
- Navigate into the project directory.
cd FastChat
- Create a new conda environment.
conda create -n fastchat python==3.10.0
- Activate the environment.
conda activate fastchat
- Verify the pip and Python paths to ensure that packages are installed in the correct environment.
which pip
orwhich python
- Install FastChat
pip3 install --upgrade pip
pip3 install -e ".[model_worker,webui]"
To speed up the installation, you can use the Tsinghua source by appending
-i https://pypi.tuna.tsinghua.edu.cn/simple
to the command. For example, pip3 install ".[model_worker,webui]" -i https://pypi.tuna.tsinghua.edu.cn/simple
- Optional packages
- For inference using fine-tuned models:
pip install -e ".[model_worker,llm_judge]"
- For memory efficiency with FlashAttn:
- Ensure you have:
- CUDA 11.6 and above. Use the command
nvcc --version
to check the CUDA version. - PyTorch 1.12 and above. Use the
import torch
print(torch.__version__)
- Install FlashAttn with the command
pip install flash-attn
- If you want to use lora or qlora, install the required packages with the command
pip install deepspeed bitsandbytes scipy
2. Download the model weights
Refer to https://zhuanlan.zhihu.com/p/648377325 for more instructions.
- We use Llama2 models for fine-tuning. Start by filling out this form to obtain access.
- After downloading the weights, they will need to be converted to the Hugging Face Transformers format using the conversion script. The script can be called with the following (example) command:
3. Fine-tune Llama2
Use the script
train_vicuna_7b.sh
in directory scripts/
. Modify the following as per your setup:- nproc_per_node : your GPU_number;
- model_name_or_path : the path of fine-tune model
- data_path: the path of fine-tune datasets
If you do not want to use FlashAtt, replace
fastchat/train/train_mem.py
as fastchat/train/train.py
Note: Use default datasets
data/dummy_conversation.json
for a test run or use your own datasets with the same format.Others:
- If you want to modify the prompt, you can edit
get_conversation_template("vicuna")
in filefastchat/train/train.py
- If you want to use lora, use the following script:
Tips
- Quick Test Run: You can reducing the number of layers of model to make it simpler, ensuring a faster execution to verify if everything is set up correctly without waiting for a full-scale training.
- Open the
config.json
file located in the model directory. - modify
num_hidden_layers
to2
or other small number.
Bugs??
- Version Mismatch: If the outputs of
nvcc -V
andnvidia-smi
don't align, run:
Note: Replace
cuda-12.2
with your version, ensuring it exists in /usr/local/
.Happy Chatbotting with FastChat! 😃
- 作者:GraphPKU
- 链接:graphpku.cn/article/85a24f19-f282-41c4-93d5-c1d94bb71e91
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。