作为智谱AI推出的开源对话模型,其应用场景覆盖企业服务、内容创作、教育辅助、多模态交互 等多个领域,核心围绕“自然语言理解与生成”能力展开 建议:60G存储的服务器
1.提前更新准备:
1.更新软件包
1 2 3 4 sudo apt update 2.sudo apt upgrade
3.安装git
1 2 3 4 4.安装项目 git clone https://github.com/THUDM/ChatGLM3.git 如果克隆失败可以加学术加速 source /etc/network_turbo
5.创建虚拟环境
1 2 3 4 conda create --name myenv python 或者sudo apt install python3.12-venv python3 -m venv myenv 激活环境:source myenv/bin/activate
6.初始化conda
7.激活虚拟环境
1 2 conda activate myenv 或者source myenv/bin/activate
8.进入项目目录
9.更新pip包
1 pip install --upgrade pip
10.下载相应依赖包(可以选择soure /etc/network_turbo)
1 2 3 4 pip install -r requirements.txt pip install jupyter_client
下载模型三种方式:
第一种:(huggingface直接拉取)(推荐)
切换目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 更新软件包 sudo apt update 安装git-lfs sudo apt-get install git-lfs 启动学术加速(可选) source /etc/network_turbo 初始化git-lfs git lfs install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 克隆项目的小文件 git clone https://huggingface.co/THUDM/chatglm3-6b(选这个命令) (unset http_proxy && unset https_proxy) git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git(备选) 初始化git-lfs git lfs install Ctrl键+c退出 进入项目目录 cd chatglm3-6b 拉取大文件 git lfs pull 验证文件完整性 git lfs ls-files (备用方法) 第二种(百度网盘下载) 链接:https://pan.baidu.com/s/1L_4-Ico1T64Hn7hhhvbMjQ 提取码:0000 下载到本地后上传到自己的阿里云盘 再从阿里云盘下载到autodl的项目目录(一般是autodl-tmp,不用管) (备用方法) 第三种(镜像站下载模型) 地址:https://hf-mirror.com/THUDM/chatglm3-6b/tree/main 下载到本地后上传阿里云盘 再从阿里云盘下载到autodl的项目目录(一般是autodl-tmp,不用管)
THUDM/chatglm3-6b?(不用管)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 修改模型地址(如果选择不同启动方式,修改对应的文件) /root/autodl-tmp/chatglm3-6b wq保存 # 1. 确认虚拟环境激活 which python python --version # 2. 安装 transformers pip install transformers # 3. 如果还缺其他依赖,一起装 pip install torch transforme # 查看是否有依赖文件 ls ~/ChatGLM3/requirements.txt # 如果有就用它安装所有依赖 pip install -r ~/ChatGLM3/requirements.txt 启动项目(测试能否启动) python cli_demo.py(终端启动) python web_demo.py(网页启动) python web_demo.py 粘贴来的命令:ssh -p 21133 root@connect.westb.seetacloud.com(将root@connect.westb.seetacloud.com替换下面的对应位置1)(24712替换下面对应位置2) 修改后的命令:ssh -CNg -L 6006:127.0.0.1:8501 root@connect.westb.seetacloud.com -p 21133 密码:Ap/u32aKvCAY http://127.0.0.1:6006
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 多轮对话微调 (先激活虚拟环境,如果已经激活了就不用了) 安装依赖 pip install transformers==4.30.2 accelerate sentencepiece astunparse deepspeed 克隆项目 cd ~ git clone https://github.com/tangqiaoyu/ToolAlpaca.git 调整数据格式 chmod +x /root/ChatGLM3/finetune_chatmodel_demo/scripts/format_tool_alpaca.py(视频里没有这一步,但也必须要执行) /root/ChatGLM3/finetune_chatmodel_demo/scripts/format_tool_alpaca.py --path "/root/ToolAlpaca/data/train_data.json" 进入修改参数 cd /root/ChatGLM3/finetune_chatmodel_demo/scripts 找到这个文件 finetune_pt_multiturn.sh 进入修改训练数据路径 BASE_MODEL_PATH=/root/autodl-tmp/chatglm3-6b DATASET_PATH=看自己情况(一般是:/root/formatted_data/tool_alpaca.jsonl) 微调开始 cd /root/ChatGLM3/finetune_chatmodel_demo chmod +x /root/ChatGLM3/finetune_chatmodel_demo/scripts/finetune_pt_multiturn.sh(视频里没有这一步,但也必须要执行) /root/ChatGLM3/finetune_chatmodel_demo/scripts/finetune_pt_multiturn.sh 微调结束(大概3个小时)(微调显示) {'train_runtime': 12381.253, 'train_samples_per_second': 1.292, 'train_steps_per_second': 0.081, 'train_loss': 0.26453141117095946, 'epoch': 3.95} 100%|█████████████████████████████████████████████████████████████| 1000/1000 [3:26:21<00:00, 12.38s/it] Saving PrefixEncoder [INFO|configuration_utils.py:458] 2023-11-11 00:32:07,299 >> Configuration saved in output/tool_alpaca_pt-20231110-210524-128-2e-2/config.json [INFO|configuration_utils.py:364] 2023-11-11 00:32:07,300 >> Configuration saved in output/tool_alpaca_pt-20231110-210524-128-2e-2/generation_config.json [INFO|modeling_utils.py:1853] 2023-11-11 00:32:07,310 >> Model weights saved in output/tool_alpaca_pt-20231110-210524-128-2e-2/pytorch_model.bin [INFO|tokenization_utils_base.py:2194] 2023-11-11 00:32:07,311 >> tokenizer config file saved in output/tool_alpaca_pt-20231110-210524-128-2e-2/tokenizer_config.json [INFO|tokenization_utils_base.py:2201] 2023-11-11 00:32:07,311 >> Special tokens file saved in output/tool_alpaca_pt-20231110-210524-128-2e-2/special_tokens_map.json, 调用微调模型 进入对应目录 cd /root/ChatGLM3/composite_demo 启动微调后的模型 MODEL_PATH="/root/autodl-tmp/chatglm3-6b" PT_PATH="/root/ChatGLM3/finetune_chatmodel_demo/output/tool_alpaca_pt-20231110-210524-128-2e-2" streamlit run main.py 粘贴来的命令:ssh -p 17077 root@connect.westb.seetacloud.com(将root@connect.westb.seetacloud.com替换下面的对应位置1)(24712替换下面对应位置2) 修改后的命令:ssh -CNg -L 6006:127.0.0.1:8501 root@connect.westb.seetacloud.com -p 17077 密码:12cClLO9/KdN http://127.0.0.1:6006
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 输入-输出格式微调 (先激活虚拟环境,如果已经激活了就不用了) 安装依赖 pip install transformers==4.30.2 accelerate sentencepiece astunparse deepspeed 下载数据集 cd ~ wget -O AdvertiseGen.tar.gz https://cloud.tsinghua.edu.cn/f/b3f119a008264b1cabd1/?dl=1 tar -xzvf AdvertiseGen.tar.gz 调整数据格式 chmod +x /root/ChatGLM3/finetune_chatmodel_demo/scripts/format_advertise_gen.py(视频里没有这一步,但也必须要执行) /root/ChatGLM3/finetune_chatmodel_demo/scripts/format_advertise_gen.py --path "/root/AdvertiseGen/train.json" 进入修改参数 cd /root/ChatGLM3/finetune_chatmodel_demo/scripts 找到这个文件 finetune_pt.sh 进入修改训练数据路径 BASE_MODEL_PATH=/root/autodl-tmp/chatglm3-6b DATASET_PATH=看自己情况(一般是:/root/formatted_data/advertise_gen.jsonl) 微调开始 cd /root/ChatGLM3/finetune_chatmodel_demo pip install astunparse(视频里没有这一步,但也必须要执行) chmod +x /root/ChatGLM3/finetune_chatmodel_demo/scripts/finetune_pt.sh(视频里没有这一步,但也必须要执行) /root/ChatGLM3/finetune_chatmodel_demo/scripts/finetune_pt.sh 调用微调模型 进入对应目录 cd /root/ChatGLM3/finetune_chatmodel_demo 测试模型 python inference.py \ --pt-checkpoint "/root/ChatGLM3/finetune_chatmodel_demo/output/advertise_gen_pt-20231201-155239-128-2e-2" \ --model /root/autodl-tmp/chatglm3-6b 启动微调后的模型 cd /root/ChatGLM3/composite_demo MODEL_PATH="/root/autodl-tmp/chatglm3-6b" PT_PATH="/root/ChatGLM3/finetune_chatmodel_demo/output/advertise_gen_pt-20231201-155239-128-2e-2" streamlit run main.py 粘贴来的命令:ssh -p 26185 root@connect.westb.seetacloud.com(将root@connect.westb.seetacloud.com替换下面的对应位置1)(24712替换下面对应位置2) 修改后的命令:ssh -CNg -L 6006:127.0.0.1:8501 root@connect.westb.seetacloud.com -p 26185 密码:KbUhLQF47v44 http://127.0.0.1:6006
文档著者:GT / github:morniakr.git.io