做整装的网站,社交电商app,网站建设零金手指花总,开元酒店集团品牌建设chatglm3介绍
ChatGLM3-6B 是 ChatGLM 系列最新一代的开源模型#xff0c;在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上#xff0c;ChatGLM3-6B 引入了如下特性#xff1a;
更强大的基础模型#xff1a; ChatGLM3-6B 的基础模型 ChatGLM3-6B-Base 采用…chatglm3介绍
ChatGLM3-6B 是 ChatGLM 系列最新一代的开源模型在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上ChatGLM3-6B 引入了如下特性
更强大的基础模型 ChatGLM3-6B 的基础模型 ChatGLM3-6B-Base 采用了更多样的训练数据、更充分的训练步数和更合理的训练策略。在语义、数学、推理、代码、知识等不同角度的数据集上测评显示ChatGLM3-6B-Base 具有在 10B 以下的预训练模型中最强的性能。 更完整的功能支持 ChatGLM3-6B 采用了全新设计的 Prompt 格式除正常的多轮对话外。同时原生支持工具调用Function Call、代码执行Code Interpreter和 Agent 任务等复杂场景。 更全面的开源序列 除了对话模型 ChatGLM3-6B 外还开源了基础模型 ChatGLM-6B-Base、长文本对话模型 ChatGLM3-6B-32K。以上所有权重对学术研究完全开放在填写问卷进行登记后亦允许免费商业使用。
chatglm3调优
所有的调优的方式 均参照了chatglm的官方手册 需要至少准备拿没有足够的显存只能进行的lora 模型的调优
SFT 全量微调: 4张显卡平均分配每张显卡占用 48346MiB 显存。P-TuningV2 微调: 1张显卡占用 18426MiB 显存。LORA 微调: 1张显卡占用 14082MiB 显存。
lora是使用一张3060ti的显卡就能进行 P-tuningV2 需要12G以上的显卡建议是3080ti及以上
环境搭建
使用了推荐的conda的方式进行了依赖的安装
conda create -n chatglm python3.10
conda activate chatglm3
pip install -r requirementss.txt问题和修正
出现的问题点如下
问题一
import mpi4py 直接导入不报错
from mpi4py import MPI出现报错ImportError: libmpi.so.40: cannot open shared object file: No such file or directory网上找了好久的方法试了很多都不行 最后在这里找到了解决办法在终端下载openmpi就可以了
conda install -c conda-forge openmpi4.1.2问题二
The Open MPI wrapper compiler was unable to find the specified compilerx86_64-conda-linux-gnu-cc in your PATH.解决方案
conda install gxx_linux-64 gcc_linux-64数据准备
这里以 AdvertiseGen 数据集为例, 您可以从 Google Drive 或者 Tsinghua Cloud 下载 AdvertiseGen 数据集。 将解压后的 AdvertiseGen 目录放到 data 目录下并自行转换为如下格式数据集。
数据转换脚本内容如下
import jsondef transform_data(input_file_path, output_file_path):datas []# Read the content of the filewith open(input_file_path, r, encodingutf-8) as file:for line in file:conversations []if line.strip(): # Check if line is not empty# Parse the JSON stringitem json.loads(line)# Add user and assistant messagesuser_message {role: user,content: item[content]}assistant_message {role: assistant,content: item[summary]}# Append to conversations listconversations.extend([user_message, assistant_message])# Prepare the output structuredatas.append({conversations: conversations})# Write the output to a new filewith open(output_file_path, w, encodingutf-8) as out_file:json.dump(datas, out_file, ensure_asciiFalse, indent2)# Define the input and output file paths
input_file_path data/AdvertiseGen_back/dev.json # Update this path
output_file_path data/AdvertiseGen/formatted_data_dev.json # Update this path# Call the function to transform the data
transform_data(input_file_path, output_file_path)print(Data transformation complete. The formatted data is saved to, output_file_path)通过上面的脚本把里面的内容汇总成可以用来进行训练的数据转换完成之后将数据copy到data下面的AdvertiseGen 目录下面
调优
调优直接参照命令
lora 方式
通过以下代码执行 单机多卡/多机多卡 运行这是使用 deepspeed 作为加速方案的您需要安装 deepspeed。
cd finetune_demo
OMP_NUM_THREADS1 torchrun --standalone --nnodes1 --nproc_per_node8 finetune_hf.py data/AdvertiseGen/ THUDM/chatglm3-6b configs/lora.yaml通过以下代码执行 单机单卡 运行。
cd finetune_demo
python finetune_hf.py data/AdvertiseGen/ THUDM/chatglm3-6b configs/lora.yaml训练过程中是可以按照step继续的具体参照官方的文档
P tunV2方式
和lora的不同也就是把lora修改为ptun就行了
cd finetune_demo
python finetune_hf.py data/AdvertiseGen/ THUDM/chatglm3-6b configs/ptuning_v2.yamlSFT 方式
24G显存跑不起来 放弃了
测试ptuning_v2.yaml
在 inference_hf.py 中验证微调后的模型 可以在 finetune_demo/inference_hf.py 中使用我们的微调后的模型仅需要一行代码就能简单的进行测试。 这里tunning出来的内容被存储在了output目录里面
python inference_hf.py your_finetune_path --prompt your prompt测试代码如下 python inference_hf.py output/checkpoint-3000 --prompt 类型#裙*版型#显瘦*材质#网纱*风格#性感*裙型#百褶*裙下摆#压褶*裙长#连衣裙*裙衣门襟#拉链*裙衣门襟#套头*裙款式#拼接*裙款式#拉链*裙款式#木耳边*裙款式#抽褶*裙款式#不规则测试结果如下
参考链接 https://github.com/THUDM/ChatGLM3/blob/main/finetune_demo/README.md