【求助帖】Function Call课后作业【进阶】 #194

Open
opened 2024-10-15 18:39:43 +08:00 by best_newnew · 0 comments

本地开源模型部署及调用(使用AutoGen)

安装fastgpt

pip3 install fschat[model_worker] -i https://mirrors.ustc.edu.cn/pypi/web/simple

启动服务模型

# 新建终端,输入如下命令
python -m fastchat.serve.controller --host 0.0.0.0
# 新建终端,输入如下命令
python -m fastchat.serve.model_worker --model-path /dataset/Llama-3-8B-Instruct/ --host 0.0.0.0 --num-gpus 4 --max-gpu-memory 15GiB
# 新建终端,输入如下命令
python -m fastchat.serve.openai_api_server --host 0.0.0.0

安装openai

# 这一步是在安装openai python SDK 以及 pyautogen
# 环境需要连接互联网才可用如下命令进行安装
pip install openai -i https://mirrors.ustc.edu.cn/pypi/web/simple
pip install pyautogen -i https://mirrors.ustc.edu.cn/pypi/web/simple

调用测试

python /code/openai_request.py

函数调用测试

# 平台配置联网
# 非平台环境【不要】执行如下命令
export http_proxy=http://10.10.9.50:3000
export https_proxy=http://10.10.9.50:3000
export no_proxy=localhost,127.0.0.1
# 计算器函数调用
python /code/autogen_calculations_function_call.py
# 汇率换算函数调用
python /code/autogen_exchanges.py
# 论文查询
python /code/autogen_search.py
# 股票查询
python /code/autogen_stocks.py

微调LLama3-8b-Instruct

设置环境

# 为了连接网络
export http_proxy=http://10.10.9.50:3000
export https_proxy=http://10.10.9.50:3000
export no_proxy=localhost,127.0.0.1
# 配置本地下载huggingface文件的cache目录
export HF_HOME=/code/huggingface-cache/
# 配置huggingface连接的镜像
export HF_ENDPOINT=https://hf-mirror.com

模型及数据集准备

模型:

Star平台上已经下载好了模型,在/dataset/Llama-3-8B-Instruct/路径下。

数据集:

这里我们选择下载到/code/Deepexi_function-calling-small_data目录下。

huggingface-cli download Deepexi/function-calling-small --repo-type dataset --revision main --local-dir-use-symlinks False --local-dir /code/Deepexi_function-calling-small_data

!直接使用格式有问题
尝试用与课件中文件相同方法转换格式还是有问题

如果 HuggingFace 上的相关数据集暂时无法被 XTuner 直接加载,因此我们首先要下载到本地,然后转换成 XTuner 直接可用的格式。

python /code/convert_agentflan.py /code/Deepexi_function-calling-small_data /code/data_converted_2

转换不了。

算法代码(llama3_8b_instruct_qlora_agentflan_3e.py)中数据集目录做对应修改:

模型训练

这里使用单机进行训练,保存路径点设置为/code/llama3-8b-ft/agent-flan_2。

xtuner train /code/llama3_8b_instruct_qlora_agentflan_3e.py --work-dir /code/llama3-8b-ft/agent-flan_2 --deepspeed deepspeed_zero3_offload

做不了做不了

🔔需要考虑xtuner如何适配这个数据集

不知道咋做啊

## 本地开源模型部署及调用(使用AutoGen) ### 安装fastgpt ```plain pip3 install fschat[model_worker] -i https://mirrors.ustc.edu.cn/pypi/web/simple ``` ### 启动服务模型 ```plain # 新建终端,输入如下命令 python -m fastchat.serve.controller --host 0.0.0.0 # 新建终端,输入如下命令 python -m fastchat.serve.model_worker --model-path /dataset/Llama-3-8B-Instruct/ --host 0.0.0.0 --num-gpus 4 --max-gpu-memory 15GiB # 新建终端,输入如下命令 python -m fastchat.serve.openai_api_server --host 0.0.0.0 ``` ### 安装openai ```plain # 这一步是在安装openai python SDK 以及 pyautogen # 环境需要连接互联网才可用如下命令进行安装 pip install openai -i https://mirrors.ustc.edu.cn/pypi/web/simple pip install pyautogen -i https://mirrors.ustc.edu.cn/pypi/web/simple ``` ### 调用测试 ```plain python /code/openai_request.py ``` ### 函数调用测试 ```plain # 平台配置联网 # 非平台环境【不要】执行如下命令 export http_proxy=http://10.10.9.50:3000 export https_proxy=http://10.10.9.50:3000 export no_proxy=localhost,127.0.0.1 # 计算器函数调用 python /code/autogen_calculations_function_call.py # 汇率换算函数调用 python /code/autogen_exchanges.py # 论文查询 python /code/autogen_search.py # 股票查询 python /code/autogen_stocks.py ``` ## 微调LLama3-8b-Instruct ### 设置环境 ```plain # 为了连接网络 export http_proxy=http://10.10.9.50:3000 export https_proxy=http://10.10.9.50:3000 export no_proxy=localhost,127.0.0.1 # 配置本地下载huggingface文件的cache目录 export HF_HOME=/code/huggingface-cache/ # 配置huggingface连接的镜像 export HF_ENDPOINT=https://hf-mirror.com ``` ### 模型及数据集准备 #### <font style="color:#333333;">模型:</font> <font style="color:#333333;">Star平台上已经下载好了模型,在</font><font style="color:#2972f4;">/dataset/Llama-3-8B-Instruct/</font><font style="color:#000000;">路径下。</font> #### 数据集: 这里我们选择下载到<font style="color:#117CEE;">/code/Deepexi_function-calling-small_data</font>目录下。 ```plain huggingface-cli download Deepexi/function-calling-small --repo-type dataset --revision main --local-dir-use-symlinks False --local-dir /code/Deepexi_function-calling-small_data ``` ![](https://cdn.nlark.com/yuque/0/2024/png/48516026/1728987834063-2551c65e-b8ea-4a0c-93ed-c655c8b03ad7.png) ##### <font style="color:#DF2A3F;">!直接使用格式有问题</font> ##### <font style="color:#DF2A3F;">尝试用与课件中文件相同方法转换格式还是有问题</font> <font style="color:#000000;">如</font><font style="color:#DF2A3F;">果 HuggingFace 上的相关数据集暂时无法被 XTuner 直接加载,因此我们首先要下载到本地,然后转换成 XTuner 直接可用的格式。</font> ```plain python /code/convert_agentflan.py /code/Deepexi_function-calling-small_data /code/data_converted_2 ``` ![](https://cdn.nlark.com/yuque/0/2024/png/48516026/1728988593315-655261a3-6f41-47b3-afc0-91cc87508f05.png) <font style="color:#DF2A3F;">转换不了。</font> <font style="color:#000000;"></font> #### 算法代码(llama3_8b_instruct_qlora_agentflan_3e.py)中数据集目录做对应修改: ![](https://cdn.nlark.com/yuque/0/2024/png/48516026/1728987642036-23677313-727b-48cd-a1e9-204aa34f4309.png) ### 模型训练 这里使用单机进行训练,保存路径点设置为/code/llama3-8b-ft/agent-flan_2。 ```plain xtuner train /code/llama3_8b_instruct_qlora_agentflan_3e.py --work-dir /code/llama3-8b-ft/agent-flan_2 --deepspeed deepspeed_zero3_offload ``` ![](https://cdn.nlark.com/yuque/0/2024/png/48516026/1728988644629-da1156eb-fab7-4261-9e55-b9cfba873cda.png) 做不了做不了 # <font style="color:#333333;">🔔</font><font style="color:#333333;">需要考虑xtuner如何适配这个数据集</font> 不知道咋做啊
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: HswOAuth/llm_course#194
No description provided.