赞
踩
- wget https://us.download.nvidia.com/tesla/525.105.17/NVIDIA-Linux-x86_64-525.105.17.run
- sh NVIDIA-Linux-x86_64-525.105.17.run
-
- wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.runsudo
- sh cuda_12.0.0_525.60.13_linux.run
-
- /usr/local/cuda/bin/nvcc -V
安装anconda:略
创建虚拟环境
- conda create -n chatglm python=3.8.3
- conda activate chatglm
- #git工具的安装参考下面命令
- yum install git -y
cuda和pytorch版本关系如下要求 https://pytorch.org/get-started/previous-versions/
虚拟环境中,运行nvcc -V返回的是系统cuda版本(/usr/local/cuda),想要查看虚拟环境的cuda版本,使用print(torch.version.cuda)
- python
- >>>import torch
- print(torch.version.cuda)
- print(torch.cuda.is_available())
- print(torch.__version__)
- print(torch.cuda.get_device_name(0))
- print(torch.cuda.device_count())
- print(torch.cuda.current_device())
- #1、下载github上的ChatGLM-6B的模型启动对应的文件
- git clone https://github.com/THUDM/ChatGLM-6B.git
- cd chatglm-6b
- #安装依赖
- pip install -r requirements.txt
- #github clone下来的requirements包含的依赖较少,只包含了以下,未包含微调所需的datasets、deepspeed、jieba、rouge_chinese、nltk等,可以自行安装
- #protobuf
- #transformers==4.27.1
- #cpm_kernels
- #torch>=1.10
- #gradio
- #mdtex2html
- #sentencepiece
- #accelerate
-
- #2、下载模型文件,可从http://huggingface.co下载,由于模型文件太大,下载太慢,可先下小文件,之后用清华源下载大模型,采用如下爬虫脚本下载大模型文件
- vim download.py
- import requests
- url1='https://cloud.tsinghua.edu.cn/d/fb9f16d6dc8f482596c2/files/?p=%2Fpytorch_model-0000'
- url2='-of-00008.bin&dl=1'
- save_path1='pytorch_model-0000'
- save_path2='-of-00008.bin'
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
- # 循环获取models,总共有8个基础模型
- for i in range(8):
- url=url1+str(i+1)+url2
- save_path=save_path1+str(i+1)+save_path2
- res = requests.get(url,headers=headers)
- file1 =open(save_path,'wb')
- file1.write(res.content)
- file1.close()
- print("第{}个模型下载已完成".format(i+1))
-
- #注意:其他文件需要都下载,从https://www.huggingface.co/THUDM/chatglm-6b/tree/main,不然会报错ValueError: Unrecognized configuration class <class 'transformers_modules.local.configuration_chatglm.ChatGLMConfig'> to build an AutoTokenizer.
本地模型启动,需要把从Hugging Face Hub加载改为本地路径加载,在/root/ChatGLM-6B/下的cli_demo.py和web_demo.py文件中进行修改。
web_demo.py:基于Gradio 的网页版 Demo
web_demo2.py: 基于 Streamlit 的网页版 Demo
- (chatglm) [root@iv-ychkunxoyy5id7hu8o1o ChatGLM-6B]# vim web_demo.py
- (chatglm) [root@iv-ychkunxoyy5id7hu8o1o ChatGLM-6B]# python web_demo.py
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████| 8/8 [00:05<00:00, 1.60it/s]
- /root/anaconda3/envs/chatglm/lib/python3.8/site-packages/gradio/components/textbox.py:259: UserWarning: The `style` method is deprecated. Please set these arguments in the constructor instead.
- warnings.warn(
- Running on local URL: http://127.0.0.1:7860
-
- To create a public link, set `share=True` in `launch()`.
- cd ChatGLM-6B/ptuning
- //下载数据集文件
- wget --no-check-certificate -O AdvertiseGen.tar.gz https://cloud.tsinghua.edu.cn/f/b3f119a008264b1cabd1/?dl=1
- tar -xzvf AdvertiseGen.tar.gz
- #/root/ChatGLM-6B/ptuning/train.sh
- PRE_SEQ_LEN=128 #预序列长度
- LR=2e-2 #学习率
-
- CUDA_VISIBLE_DEVICES=0 python3 main.py \
- --do_train \ #是否进行训练
- --do_eval \ #是否进行预测
- --train_file AdvertiseGen/train.json \ #训练数据集相对路径
- --validation_file AdvertiseGen/dev.json \ #验证数据集相对路径
- --prompt_column content \ #提示信息字段
- --response_column summary \ #响应信息字段
- --overwrite_cache \ # 重写数据集缓存
- --model_name_or_path ChatGLM-6B/THUDM \ #模型文件名称或路径
- --output_dir output/adgen-chatglm-6b-pt-$PRE_SEQ_LEN-$LR \ #训练好的模型保存的地址
- --overwrite_output_dir \
- --max_source_length 64 \
- --max_target_length 64 \
- --per_device_train_batch_size 1 \ #每个设备上的训练批次大小,调整batch_size,显存利用率上升
- --per_device_eval_batch_size 1 \
- --gradient_accumulation_steps 16 \
- --predict_with_generate \
- --max_steps 3000 \
- --logging_steps 10 \
- --save_steps 1000 \
- --learning_rate $LR \
- --pre_seq_len $PRE_SEQ_LEN \
- # --quantization_bit 4
-
使用Deepspeed数据并行, 需要调整最大步长,batchsize,不然2卡A10跑不起来
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。