An open platform for training, serving, and evaluating large language model based chatbots.
- 🔥 We released Vicuna: An Open-Source Chatbot Impressing GPT-4 with 90% ChatGPT Quality. Checkout the blog post and demo.
Join our Discord server and follow our Twitter to get the latest updates.
- Install
- Vicuna Weights
- Inference with Command Line Interface
- Serving with Web GUI
- API
- Evaluation
- Fine-tuning
# Install FastChat
pip3 install fschat
# Install the latest main branch of huggingface/transformers
pip3 install git+https://github.com/huggingface/transformers
- Clone this repository and navigate to the FastChat folder
git clone https://github.com/lm-sys/FastChat.git
cd FastChat
If you are running on Mac:
brew install rust cmake
- Install Package
pip3 install --upgrade pip # enable PEP 660 support
pip3 install -e .
We release Vicuna weights as delta weights to comply with the LLaMA model license. You can add our delta to the original LLaMA weights to obtain the Vicuna weights. Instructions:
- Get the original LLaMA weights in the huggingface format by following the instructions here.
- Use the following scripts to get Vicuna weights by applying our delta. They will automatically download delta weights from our Hugging Face account.
NOTE: Our released weights are only compatible with the latest main branch of huggingface/transformers. We install the correct version of transformers when fastchat is installed.
This conversion command needs around 30 GB of CPU RAM. If you do not have enough memory, you can create a large swap file that allows the operating system to automatically utilize the disk as virtual memory.
python3 -m fastchat.model.apply_delta \
--base /path/to/llama-7b \
--target /output/path/to/vicuna-7b \
--delta lmsys/vicuna-7b-delta-v1.1
This conversion command needs around 60 GB of CPU RAM. If you do not have enough memory, you can create a large swap file that allows the operating system to automatically utilize the disk as virtual memory.
python3 -m fastchat.model.apply_delta \
--base /path/to/llama-13b \
--target /output/path/to/vicuna-13b \
--delta lmsys/vicuna-13b-delta-v1.1
See docs/weights_version.md for all versions of weights and their differences.
(Experimental Feature: You can specify --style rich
to enable rich text output and better text streaming quality for some non-ASCII content. This may not work properly on certain terminals.)
The command below requires around 28GB of GPU memory for Vicuna-13B and 14GB of GPU memory for Vicuna-7B. See the "No Enough Memory" section below if you do not have enough memory.
python3 -m fastchat.serve.cli --model-path /path/to/vicuna/weights
You can use model parallelism to aggregate GPU memory from multiple GPUs on the same machine.
python3 -m fastchat.serve.cli --model-path /path/to/vicuna/weights --num-gpus 2
This runs on the CPU only and does not require GPU. It requires around 60GB of CPU memory for Vicuna-13B and around 30GB of CPU memory for Vicuna-7B.
python3 -m fastchat.serve.cli --model-path /path/to/vicuna/weights --device cpu
Use --device mps
to enable GPU acceleration on Mac computers (requires torch >= 2.0).
Use --load-8bit
to turn on 8-bit compression.
python3 -m fastchat.serve.cli --model-path /path/to/vicuna/weights --device mps --load-8bit
Vicuna-7B can run on a 32GB M1 Macbook with 1 - 2 words / second.
If you do not have enough memory, you can enable 8-bit compression by adding --load-8bit
to commands above.
This can reduce memory usage by around half with slightly degraded model quality.
It is compatible with the CPU, GPU, and Metal backend.
Vicuna-13B with 8-bit compression can run on a single NVIDIA 3090/4080/V100(16GB) GPU.
python3 -m fastchat.serve.cli --model-path /path/to/vicuna/weights --load-8bit
Besides, we are actively exploring more methods to make the model easier to run on more platforms. Contributions and pull requests are welcome.
To serve using the web UI, you need three main components: web servers that interface with users, model workers that host one or more models, and a controller to coordinate the webserver and model workers. Here are the commands to follow in your terminal:
python3 -m fastchat.serve.controller
This controller manages the distributed workers.
python3 -m fastchat.serve.model_worker --model-path /path/to/vicuna/weights
Wait until the process finishes loading the model and you see "Uvicorn running on ...". You can launch multiple model workers to serve multiple models concurrently. The model worker will connect to the controller automatically.
To ensure that your model worker is connected to your controller properly, send a test message using the following command:
python3 -m fastchat.serve.test_message --model-name vicuna-13b
python3 -m fastchat.serve.gradio_web_server
This is the user interface that users will interact with.
By following these steps, you will be able to serve your models using the web UI. You can open your browser and chat with a model now.
See fastchat/serve/huggingface_api.py
Coming soon.
Our AI-enhanced evaluation pipeline is based on GPT-4. This section provides a high-level summary of the pipeline. For detailed instructions, please refer to the evaluation documentation.
-
Generate answers from different models: Use
qa_baseline_gpt35.py
for ChatGPT, or specify the model checkpoint and runget_model_answer.py
for Vicuna and other models. -
Generate reviews with GPT-4: Use GPT-4 to generate reviews automatically. This step can also be performed manually if the GPT-4 API is not available to you.
-
Generate visualization data: Run
generate_webpage_data_from_table.py
to generate data for a static website, which allows you to visualize the evaluation data. -
Visualize the data: Serve a static website under the
webpage
directory. You can usepython3 -m http.server
to serve the website locally.
We use a data format encoded with JSON Lines for evaluation. The format includes information on models, prompts, reviewers, questions, answers, and reviews.
You can customize the evaluation process or contribute to our project by accessing the relevant data.
For detailed instructions, please refer to the evaluation documentation.
Vicuna is created by fine-tuning a LLaMA base model using approximately 70K user-shared conversations gathered from ShareGPT.com with public APIs. To ensure data quality, we convert the HTML back to markdown and filter out some inappropriate or low-quality samples. Additionally, we divide lengthy conversations into smaller segments that fit the model's maximum context length. For detailed instructions to clean the ShareGPT data, check out here.
Due to some concerns, we may not release the ShareGPT dataset at the moment. If you would like to try the fine-tuning code, you can run it with some dummy questions in dummy.json. You can follow the same format and plug in your own data.
Our code is based on Stanford Alpaca with additional support for multi-round conversations. We use similar hyperparameters as the Stanford Alpaca.
Hyperparameter | Global Batch Size | Learning rate | Epochs | Max length | Weight decay |
---|---|---|---|---|---|
Vicuna-13B | 128 | 2e-5 | 3 | 2048 | 0 |
You can use the following command to train Vicuna-7B with 4 x A100 (40GB).
torchrun --nproc_per_node=4 --master_port=20001 fastchat/train/train_mem.py \
--model_name_or_path ~/model_weights/llama-7b \
--data_path playground/data/dummy.json \
--bf16 True \
--output_dir output \
--num_train_epochs 3 \
--per_device_train_batch_size 2 \
--per_device_eval_batch_size 2 \
--gradient_accumulation_steps 16 \
--evaluation_strategy "no" \
--save_strategy "steps" \
--save_steps 1200 \
--save_total_limit 10 \
--learning_rate 2e-5 \
--weight_decay 0. \
--warmup_ratio 0.03 \
--lr_scheduler_type "cosine" \
--logging_steps 1 \
--fsdp "full_shard auto_wrap" \
--fsdp_transformer_layer_cls_to_wrap 'LlamaDecoderLayer' \
--tf32 True \
--model_max_length 2048 \
--gradient_checkpointing True \
--lazy_preprocess True
If you meet out-of-memory during model saving, see solutions here.
SkyPilot is a framework built by UC Berkeley for easily and cost effectively running ML workloads on any cloud (AWS, GCP, Azure, Lambda, etc.). To use SkyPilot, install it with the following command and setup the cloud credentials locally following the instructions here.
# Install skypilot from the master branch
pip install git+https://github.com/skypilot-org/skypilot.git
Vicuna can be trained on 8 A100 GPUs with 80GB memory. The following command will automatically launch a node satisfying the requirement, setup and run the training job on it.
sky launch -c vicuna -s scripts/train-vicuna.yaml --env WANDB_API_KEY
Other options are also valid:
# Launch it on managed spot to save 3x cost (train Vicuna-13B with around $300)
sky spot launch -n vicuna scripts/train-vicuna.yaml --env WANDB_API_KEY
# Train a 7B model
sky launch -c vicuna -s scripts/train-vicuna.yaml --env WANDB_API_KEY --env MODEL_SIZE=7
Note: Please make sure the WANDB_API_KEY
has been setup on your local machine. You can find the API key on your wandb profile page. If you would like to train the model without using wandb, you can replace the --env WANDB_API_KEY
flag with --env WANDB_MODE=offline
.