Llama 3 五一超级课堂 笔记 ==> 第五节、Llama 3 Agent 能力体验与微调

环境准备

创建环境

conda create -n llama3 python=3.10
conda activate llama3
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia

安装 XTuner

cd ~
git clone -b v0.1.18 https://github.com/InternLM/XTuner
cd XTuner
pip install -e .[all]

clone 教程仓库

cd ~
git clone https://github.com/SmartFlowAI/Llama3-Tutorial

模型准备

InternStudio 软链的方式

mkdir -p ~/model
cd ~/model
ln -s /root/share/new_models/meta-llama/Meta-Llama-3-8B-Instruct .

已上这些在前面章节已经准备好,所以我选择 conda activate llama3直接进入环境。

数据准备

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

  • InternStudio

如果是在 InternStudio 上,我们已经准备好了一份转换好的数据,可以直接通过如下脚本准备好:

cd ~
cp -r /root/share/new_models/internlm/Agent-FLAN .
chmod -R 755 Agent-FLAN

微调

我们已经为大家准备好了可以一键启动的配置文件,主要是修改好了模型路径、对话模板以及数据路径。
我们使用如下指令以启动训练:

export MKL_SERVICE_FORCE_INTEL=1
xtuner train ~/Llama3-Tutorial/configs/llama3-agentflan/llama3_8b_instruct_qlora_agentflan_3e.py --work-dir ~/llama3_agent_pth --deepspeed deepspeed_zero2

在训练完成后,我们将权重转换为 HuggingFace 格式,并合并到原权重中。

# 转换权重
xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-agentflan/llama3_8b_instruct_qlora_agentflan_3e.py \
    ~/llama3_agent_pth/iter_18516.pth \
    ~/llama3_agent_pth/iter_18516_hf

上面数据准备和微调,我就不弄了,直接用老师准备的hf

老师为大家准备好了已经训练好且转换为 HuggingFace 格式的权重,可以直接使用。路径位于 /share/new_models/agent-flan/iter_2316_hf
接下来合并模型

export MKL_SERVICE_FORCE_INTEL=1
xtuner convert merge /root/model/Meta-Llama-3-8B-Instruct \
    /share/new_models/agent-flan/iter_2316_hf \
    ~/llama3_agent_pth/merged

Lagent Web Demo

安装 lagent

pip install lagent

效果

启动web demo 使用 微调后的模型
运行命令

streamlit run ~/Llama3-Tutorial/tools/agent_web_demo.py /root/llama3_agent_pth/merged

询问:查找Llama3 的技术报告
class-5-2.png
启动web demo 使用 微调前的模型
运行命令

streamlit run ~/Llama3-Tutorial/tools/agent_web_demo.py /root/model/Meta-Llama-3-8B-Instruct

询问:查找Llama3 的技术报告class-5-3.png

在运行的时候有一个报错OSError: [Errno 28] inotify watch limit reached

我等待了一会就好了。
下面是网上的方案
OSError: [Errno 28] inotify watch limit reached · Issue #3189 · chatchat-space/Langchain-Chatchat

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值