当前位置:   article > 正文

Qwen-14B-Chat-Int4 保姆级微调详细步骤_qwen-14b 微调

qwen-14b 微调

1、下载Qwen-14B-Chat-int4 模型

git clone https://www.modelscope.cn/qwen/Qwen-14B-Chat-Int4.git

2、下载

git clone https://github.com/Dao-AILab/flash-attention

3、下载 QWEN 代码  

git clone https://github.com/QwenLM/Qwen.git 

finetune 文件夹web_demo.py  finetune.py 一个文件夹 和两个PY文件 粘贴到 模型文件夹下

4、执行

  1. cd flash-attention
  2. # 下方安装可选,安装可能比较缓慢。
  3. pip install csrc/layer_norm
  4. # 如果flash-attn版本高于2.1.1,下方无需安装。
  5. pip install csrc/rotary

5、修改finetune 文件夹的 finetune_qlora_single_gpu.sh 文件里的MODEL、 DATA、 python 路径

  1. MODEL="/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4" # Set the path if you do not want to load from huggingface directly
  2. # ATTENTION: specify the path to your training data, which should be a json file consisting of a list of conversations.
  3. # See the section for finetuning in README for more information.
  4. DATA="/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4/finetune/total36-67.json"
  5. python /mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4/finetune.py \
  6. --deepspeed ds_config_zero2.json

6、修改output_qwen文件夹adapter_config.json文件的base_model_name_or_path

  1. {
  2. "alpha_pattern": {},
  3. "auto_mapping": null,
  4. "base_model_name_or_path": "/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4",
  5. "bias": "none",
  6. "fan_in_fan_out": false,
  7. "inference_mode": true,
  8. "init_lora_weights": true,
  9. "layers_pattern": null,
  10. "layers_to_transform": null,
  11. "loftq_config": {},
  12. "lora_alpha": 16,
  13. "lora_dropout": 0.05,
  14. "megatron_config": null,
  15. "megatron_core": "megatron.core",
  16. "modules_to_save": null,
  17. "peft_type": "LORA",
  18. "r": 64,
  19. "rank_pattern": {},
  20. "revision": null,
  21. "target_modules": [
  22. "w2",
  23. "c_proj",
  24. "c_attn",
  25. "w1"
  26. ],
  27. "task_type": "CAUSAL_LM"
  28. }

7、将json模型文件放到此目录下

8、执行 # 单卡训练

bash finetune_qlora_single_gpu.sh

模型微调成功后

9、然后 修改config.json文件在quantization_config

下添加"disable_exllama":true

  1. "quantization_config": {
  2. "bits": 4,
  3. "group_size": 128,
  4. "damp_percent": 0.01,
  5. "desc_act": false,
  6. "static_groups": false,
  7. "sym": true,
  8. "true_sequential": true,
  9. "model_name_or_path": null,
  10. "model_file_base_name": "model",
  11. "quant_method": "gptq",
  12. "disable_exllama":true
  13. },

10、在web_demo.py 添加

  1. # model = AutoModelForCausalLM.from_pretrained(
  2. # args.checkpoint_path,
  3. # device_map=device_map,
  4. # trust_remote_code=True,
  5. # resume_download=True,
  6. # ).eval()
  7. from peft import AutoPeftModelForCausalLM
  8. model = AutoPeftModelForCausalLM.from_pretrained(
  9. # 训练后生成的文件夹路径
  10. '/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4/finetune/output_qwen',
  11. device_map="auto",
  12. trust_remote_code=True
  13. ).eval()

并把以前的 model注释掉

11、修改web_demo.py  

DEFAULT_CKPT_PATH 

AutoPeftModelForCausalLM.from_pretrained  路径

  1. DEFAULT_CKPT_PATH = '/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4'
  2. model = AutoPeftModelForCausalLM.from_pretrained(
  3. # 训练后生成的文件夹路径
  4. '/mnt/workspace/Qwen/model/Qwen-14B-Chat-Int4/finetune/output_qwen',
  5. device_map="auto",
  6. trust_remote_code=True
  7. ).eval()

12、 启动

python web_demo.py

注意:这里的路径是根据个人下载的路径为准

最后执行 python web_demo.py 如果报错哪个包没有安装就安装哪个包

但是如果安装出现 提问后页面回答报错 控制台输出的时候 有可能是遇到gradio版本不兼容

更新到对应的版本即可 我的版本是3.40.0 希望大家不要踩坑

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号