中文 llama3 仿 openai api 实战 #84
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: HswOAuth/llm_course#84
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
中文 llama3 仿 openai api 实战
下载源码
安装 miniconda
创建虚拟环境
模型下载
直接使用命令下载
基于 screen 下载
如果在操作过程中断开了服务器连接,可以使用 screen -r model_download 恢复操作窗口
模型存储位置
使用 modelscope 下载完毕后,模型会存储在如下位置:
~/.cache/modelscope/hub/ChineseAlpacaGroup/llama-3-chinese-8b-instruct-v3,正常情
况下,可以看到如下内容:
开源版 openai 接口启动
中文 llama3 的开源版本实现在以下目录:/root/Chinese-LLaMA-Alpaca-3-3.0/scripts/oai_api_demo,下面分别是 GPU 和 CPU 版本的启动流程
推理脚本 BUG 修复
在启动 GPU 或者 CPU 版本的仿 openai 接口(stream 流式方式,类似 openai 打字机回复效
果)脚本之前,需要修复一个 bug,打开/root/Chinese-LLaMA-Alpaca-3-3.0/scripts/oai_api_demo/openai_api_server.py 文件:
加入上面的参数主要是为了兼容 llama3 特有的停止 token,不然流式接口返回的内容会不断
的自动重复,不停止。
GPU 版本
备份脚本
安装依赖
通过如下命令创建新的 requirements.txt
安装依赖:
启动服务
请注意--gpus 后面的参数 0,代表我们要使用第一块 GPU 卡运行大模型服务,如果您的机器只
有一块卡,您需要将该参数始终设置为 0,也就是--gpus 0
使用--load_in_8bit 或者--load_in_4bit可以开启量化加载。
测试效果
我们使用 ChatGPTNextWeb 工具测试我们的接口,如果您没有下载客户端,可以通过下面地址
下载:
Windows:https://github.com/ChatGPTNextWeb/ChatGPT-NextWeb/releases/download/v2.14.2/NextChat_2.14.2_x64-setup.exe
下载后,安装即可。
设置刚才部署的大模型服务,在平台部署,本地安装nextchat,平台无映射ip, 象征性表示。