zhubao315

zhubao315

less is more
twitter
github

快速聊天推理環境部署

基本信息#

FastChat 是一個開放平台,用於訓練、推理和評估基於 LLM 的 ChatBot。FastChat 的核心功能包括:

  • 優秀的大語言模型訓練和評估程式碼。
  • 具有 Web UI 和 OpenAI 兼容的 RESTful API 的分佈式多模型服務系統。

支持的模型列表:

模型結構模型名稱實際的模型 id 樣例
AquilaForCausalLMAquilaBAAI/AquilaChat2-34B, BAAI/Aquila2-34B, etc.
BaiChuanForCausalLMBaichuanbaichuan-inc/Baichuan2-7B-Base, baichuan-inc/Baichuan2-13B-Base, etc.
ChatGLMModelChatGLMZhipuAI/chatglm2-6b, ZhipuAI/chatglm3-6b, etc.
InternLMForCausalLMInternLMinternlm/internlm-7b, internlm/internlm-chat-7b, etc.
QWenLMHeadModelQwenqwen/Qwen-1_8B-Chat, qwen/Qwen-7B-Chat, qwen/Qwen-14B-Chat,qwen/Qwen-72B-Chat,etc.
LlamaForCausalLMLLaMaLlama-2-7b-ms,Llama-2-13b-ms,Llama-2-70b-ms,etc.
YiForCausalLMYi01ai/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 &

Pasted image 20240308111425

  • 該模型使用 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

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。