基本信息#
FastChat 是一个开放平台,用于训练、推理和评估基于 LLM 的 ChatBot。FastChat 的核心功能包括:
- 优秀的大语言模型训练和评估代码。
- 具有 Web UI 和 OpenAI 兼容的 RESTful API 的分布式多模型服务系统。
支持的模型列表:
模型结构 | 模型名称 | 实际的模型 id 样例 |
AquilaForCausalLM | Aquila | BAAI/AquilaChat2-34B, BAAI/Aquila2-34B, etc. |
BaiChuanForCausalLM | Baichuan | baichuan-inc/Baichuan2-7B-Base, baichuan-inc/Baichuan2-13B-Base, etc. |
ChatGLMModel | ChatGLM | ZhipuAI/chatglm2-6b, ZhipuAI/chatglm3-6b, etc. |
InternLMForCausalLM | InternLM | internlm/internlm-7b, internlm/internlm-chat-7b, etc. |
QWenLMHeadModel | Qwen | qwen/Qwen-1_8B-Chat, qwen/Qwen-7B-Chat, qwen/Qwen-14B-Chat,qwen/Qwen-72B-Chat,etc. |
LlamaForCausalLM | LLaMa | Llama-2-7b-ms,Llama-2-13b-ms,Llama-2-70b-ms,etc. |
YiForCausalLM | Yi | 01ai/Yi-6B-Chat, 01ai/Yi-34B-Chat, etc. |
环境配置与安装 #
安装运行基础镜像
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda11.8.0-py310-torch2.1.0-tf2.14.0-1.10.0
docker run -itd --name fastchat -p 7788:8000 -v /nfs/data/models:/models registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda11.8.0-py310-torch2.1.0-tf2.14.0-1.10.0 bash
docker exec -it fastchat bash
安装 FastChat 最新包
pip3 install "fschat[model_worker,webui]"
git clone https://github.com/lm-sys/FastChat.git
cd FastChat
pip install .
pip install --upgrade transformers
使用 FastChat 实现发布 model worker (s),首先启动一个 controller:
python -m fastchat.serve.controller --host 0.0.0.0 &
发布一个 model worker (s),以千问 1.5 模型为例
python -m fastchat.serve.model_worker --host 0.0.0.0 --worker-address http://0.0.0.0:21002 --controller-address http://0.0.0.0:21001 --model-path /models/Qwen1.5-1.8B-Chat --revision v1.0.0 &
推理 cli(退出后杀 py 进程)
python -m fastchat.serve.cli --model-path /models/Qwen1.5-1.8B-Chat
推理测试
python -m fastchat.serve.test_message --model-name Qwen1.5-1.8B-Chat --message 你好
启动 WebUI 服务
python -m fastchat.serve.gradio_web_server --host 0.0.0.0 --port 8000 &
- 该模型使用 4700MiB GPU 显存 ^n4z8lb
API 服务#
启动 api server
python -m fastchat.serve.openai_api_server --host 0.0.0.0 --controller-address http://0.0.0.0:21001 --port 8000 &
获取模型列表
curl http://192.168.1.6:7788/v1/models
api 推理测试
curl http://192.168.1.6:7788/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen1.5-1.8B-Chat",
"messages": [{"role": "user", "content": "你是谁?你会做什么?"}]
}'
embedding 测试
curl http://192.168.1.6:7788/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen1.5-1.8B-Chat",
"input": "无代码"
}'
参考资料#
https://github.com/lm-sys/FastChat
https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md