训练
租卡
下载工程
git clone https://github.com/QwenLM/Qwen.git
cd Qwen
安装依赖
pip install deepspeed transformers4.32.0 peft pydantic1.10.13 transformers_stream_generator einops tiktoken
pip install modelscope
pip install “peft<0.8.0” deepspeed
apt-get update
apt-get install libaio-dev
下载模型
modelscope download --model qwen/Qwen-1_8B-Chat
定位模型位置
sudo apt install mlocate语句下载locate包
locate Qwen-1_8B-Chat
# cp -r /root/.local/share/Trash/files/Qwen-1_8B-Chat /root/Qwen/Qwen-1_8B-Chat
安装数据
开始训练
bash finetune/finetune_ds.sh
fp16精度问题:True改为False
量化微调后模型
pip install auto-gptq optimum
pip install auto-gptq[cuda]
mkdir -p /root/Qwen/models
mv /root/.cache/modelscope/hub/qwen/Qwen-1_8B-Chat /root/Qwen/models/
python run_gptq.py
–model_name_or_path /root/Qwen/models/Qwen-1_8B-Chat
–data_path /root/Qwen/conversations_l.json
–out_path /root/Qwen/output_qwen
–bits 4
成功
接下来, 将原模型中所有 *.py, *.cu, *.cpp 文件和 generation_config.json 文件复制到输出模型目录下。同时,使用官方对应版本的量化模型的 config.json 文件覆盖输出模型目录下的文件 (例如, 如果你微调了 Qwen-7B-Chat和–bits 4, 那么你可以从 Qwen-7B-Chat-Int4 仓库中找到对应的config.json )。 并且,你需要将 gptq.safetensors 重命名为 model.safetensors。
modelscope download --model qwen/Qwen-1_8B-Chat-int4
mv /root/.cache/modelscope/hub/qwen/Qwen-1_8B-Chat-int4 /root/Qwen/models/
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("/root/Qwen/output_qwen/", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"/root/Qwen/output_qwen/",
device_map="auto",
trust_remote_code=True
).eval()
response, history = model.chat(tokenizer, "你好", history=None)
print(response)
No module named ‘gradio’
pip install gradio