当前位置: 首页 > news >正文

fintuning chatglm3

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 python=3.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 openmpi=4.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', encoding='utf-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', encoding='utf-8') as out_file:json.dump(datas, out_file, ensure_ascii=False, indent=2)# 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_THREADS=1 torchrun --standalone --nnodes=1 --nproc_per_node=8  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.yaml
SFT 方式

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

http://www.lryc.cn/news/361289.html

相关文章:

  • 草台班子啊草台班子:共享电源导致的BUG(供电不足)
  • java递归计算文件夹和文件大小
  • 硬币检测电路设计
  • 3.基础光照
  • Image Search-这是你的图像搜索
  • 对GPT-4o的评价:技术革新与未来展望
  • 【TB作品】msp430f5529单片机,dht22,烟雾传感器
  • uni-app全局弹窗的实现方案
  • Love-Yi情侣网站3.0存在SQL注入漏洞
  • 自然语言处理(NLP)—— 神经网络语言处理
  • SHA256计算原理
  • Mysql | select语句导入csv后再导入excel表格
  • SpringBoot:手动创建应用
  • 【LeetCode】39.组合总和
  • 用JS来控制遥控车(一行代码即可连接, 超简单!)
  • MyBatis-Plus如何优雅的配置多租户及分页
  • 国产操作系统上Vim的详解01--vim基础篇 _ 统信 _ 麒麟 _ 中科方德
  • 如何正确理解事件溯源架构模式?
  • 【漏洞复现】电信网关配置管理系统 rewrite.php 文件上传漏洞
  • 线性调整率:LINE REGULATION详解
  • Workfine默认首页功能详解
  • CSAPP Lab07——Malloc Lab完成思路
  • 简单、免费、无广告的高性能多线程文件下载工具
  • 【退役之重学 SQL】什么是笛卡尔积
  • Vue3禁止 H5 界面放大与缩小功能
  • 上位机图像处理和嵌入式模块部署(f407 mcu中tf卡读写和fatfs挂载)
  • 汽车识别项目
  • 【面试题-012】什么是Spring 它有哪些优势
  • ImageButton src图片会照成内存泄露吗 会使native内存增加吗?
  • 负载均衡与容错性:集群模式在分布式系统中的应用