qwen微调量化测验

训练

租卡

AutoDL算力租用平台

下载工程

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

brain1234

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值