官方仓:https://github.com/THUDM/CogVLM2
说明:本仓代码仅为适配官方仓脚本,执行训练与推理需要在官方仓cogvlm2项目路径下进行。
本仓已支持以下模型任务类型。
模型 | 模型大小 | 任务类型 | 是否支持 |
---|---|---|---|
CogVLM2 | cogvlm2-llama3-chinese-chat-19B | lora微调 | ✅ |
CogVLM仓: https://github.com/THUDM/CogVLM2
commit id: 3adb5ce3243a9c81c1df5336d3297c94d0f9e1cc
参考链接:https://github.com/THUDM/CogVLM2/tree/3adb5ce3243a9c81c1df5336d3297c94d0f9e1cc
url=https://gitee.com/ascend/ModelZoo-PyTorch.git
code_path=PyTorch/built-in/foundation/CogVLM2
请参考昇腾社区中《Pytorch框架训练环境准备》文档搭建昇腾环境,本仓已支持表1中软件版本。
表 1 昇腾软件版本支持表
软件类型 | 支持版本 |
---|---|
FrameworkPTAdapter | 6.0.RC3 |
CANN | 8.0.RC3 |
昇腾NPU固件 | 24.1.RC3 |
昇腾NPU驱动 | 24.1.RC3 |
表 2 三方库版本支持表
三方库 | 支持版本 |
---|---|
PyTorch | 2.1.0 |
pip install -r requirements.txt
主要提供基于CogVLM-SFT-311K数据集微调的lora微调训练脚本。
替换和新增本仓authority_repository/finetune_demo下的文件到cogvlm2官方仓的finetune_demo/文件下 替换和新增本仓llama3_chinese_chat_19B下的文件到预训练权重文件下
替换authority_repository/finetune_demo/cogvlm2_lora_finetune.sh文件中的"训练数据路径","预训练权重路径"和"模型保存路径"为实际路径
CogVLM2官方仓下执行训练,如下命令:
cd finetune_demo
bash cogvlm2_lora_finetune.sh
芯片 | 卡数 | s/it | micro_batch_size | AMP_Type | Torch_Version |
---|---|---|---|---|---|
竞品A | 8p | 3.3 | 1 | bf16 | 2.1 |
Atlas 900 A2 PODc | 8p | 3.9 | 1 | bf16 | 2.1 |
替换authority_repository/finetune_demo/cogvlm2_lora_finetune_2nodes.sh文件中的"训练数据路径","预训练权重路径"和"模型保存路径"为实际路径
authority_repository/finetune_demo/hostfile中的内容为服务器名(server1和server2)和每台服务器的卡数
由于torch.util.data中的DataLoader在shuffle为False的情况下广播容易超时,所以多机情况下peft_lora.py中DataLoader的shuffle参数建议不要设置为False,不影响模型收敛
双机配置可参考"配置双机通信环境"
CogVLM2官方仓下执行训练,如下命令:
cd finetune_demo
bash cogvlm2_lora_finetune_2nodes.sh
git clone https://github.com/chaos/pdsh/archive/refs/tags/pdsh-2.29.tar.gz
tar -zxvf pdsh-2.29.tar.gz
cd pdsh-2.29
./configure --with-ssh --with-rsh --with-mrsh --with-mqshel --with-qshell --with-dshgroups --with-machines=/etc/pdsh/machines --without-pam
make
make install
安装完成后,执行pdsh -h
命令。显示如下信息,表示安装成功。
# pdsh -h
Usage: pdsh [-options] command ...
-S return largest of remote command return values
-h output usage menu and quit
-V output version information and quit
-q list the option settings and quit
-b disable ^C status feature (batch mode)
-d enable extra debug information from ^C status
-l user execute remote commands as user
-t seconds set connect timeout (default is 10 sec)
-u seconds set command timeout (no default)
-f n use fanout of n nodes
-w host,host,... set target node list on command line
-x host,host,... set node exclusion list on command line
-R name set rcmd module to name
-M name,... select one or more misc modules to initialize first
-N disable hostname: labels on output lines
-L list info on all loaded modules and exit
-g groupname target hosts in dsh group "groupname"
-X groupname exclude hosts in dsh group "groupname"
-a target all nodes
available rcmd modules: ssh,rsh,exec (default: rsh)
```shell
node1 server1
node2 server2
然后,我们需要执行以下命令来生成sshkey。
ssh-keygen -t rsa
接着,将ssh-key拷贝到每个节点,本机也要拷贝。
ssh-copy-id root@server1
ssh-copy-id root@server2
然后,在每个节点上运行以下代码,首次执行时需要手动输入yes
,然后执行exit
退出。再次执行以下命令时,如果不需要输入密码,则表示配置成功。
ssh server1
ssh server2
模型中包含多种随机问题,会影响loss曲线和竞品的对齐,用户可根据需要自行修改,部分确定性问题本代码不做更换:
import torch_npu
from torch_npu.contrib import transfer_to_npu
export ASCEND_RT_VISIBLE_DEVICES=1
原内容:
TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8 else torch.float16
修改为:
TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() else torch.float16
python peft_infer.py
暂无。
2024.08.08:CogVLM2 bf16微调任务首次发布。
暂无。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。