当前位置:   article > 正文

安装LLaMA-Factory微调chatglm3,修改自我认知_python src/export_model.py \ --model_name_or_path

python src/export_model.py \ --model_name_or_path

安装git clone https://github.com/hiyouga/LLaMA-Factory.git
conda create -n llama_factory python=3.10
conda activate llama_factory
cd LLaMA-Factory
pip install -r requirements.txt

之后运行

单卡训练,

CUDA_VISIBLE_DEVICES=0 python src/train_web.py,按如下配置

demo_tran.sh

  1. CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \
  2. --stage sft \
  3. --model_name_or_path /data/models/llm/chatglm3-lora/ \
  4. --do_train \
  5. --overwrite_output_dir \
  6. --dataset self_cognition \
  7. --template chatglm3 \
  8. --finetuning_type lora \
  9. --lora_target query_key_value \
  10. --output_dir export_chatglm3 \
  11. --overwrite_cache \
  12. --per_device_train_batch_size 4 \
  13. --gradient_accumulation_steps 4 \
  14. --lr_scheduler_type cosine \
  15. --logging_steps 10 \
  16. --save_steps 1000 \
  17. --learning_rate 1e-3 \
  18. --num_train_epochs 10.0 \
  19. --plot_loss \
  20. --fp16

 export_model.sh

  1. python src/export_model.py \
  2. --model_name_or_path /data/models/llm/chatglm3-lora/ \
  3. --template chatglm3 \
  4. --finetuning_type lora \
  5. --checkpoint_dir /data/projects/LLaMA-Factory/export_chatglm3 \
  6. --export_dir lora_merge_chatglm3

 cli_demo.sh

  1. python src/cli_demo.py \
  2. --model_name_or_path /data/models/llm/chatglm3-lora/ \
  3. --template default \
  4. --finetuning_type lora

注意合并模型的时候,最后复制chatglm3的tokenizer.model和tokenizer_config.json到合并后模型覆盖之后,要修改

 不覆盖会有这个错误,

 Use DeepSpeed方法

  1. deepspeed --num_gpus 3 --master_port=9901 src/train_bash.py \
  2. --deepspeed ds_config.json \
  3. --stage sft \
  4. --model_name_or_path /media/cys/65F33762C14D581B/chatglm2-6b \
  5. --do_train True \
  6. --finetuning_type lora \
  7. --template chatglm2 \
  8. --flash_attn False \
  9. --shift_attn False \
  10. --dataset_dir data \
  11. --dataset self_cognition,sharegpt_zh \
  12. --cutoff_len 1024 \
  13. --learning_rate 0.001 \
  14. --num_train_epochs 10.0 \
  15. --max_samples 1000 \
  16. --per_device_train_batch_size 4 \
  17. --gradient_accumulation_steps 4 \
  18. --lr_scheduler_type cosine \
  19. --max_grad_norm 1.0 \
  20. --logging_steps 10 \
  21. --save_steps 1000 \
  22. --warmup_steps 0 \
  23. --neft_alpha 0 \
  24. --train_on_prompt False \
  25. --upcast_layernorm False \
  26. --lora_rank 8 \
  27. --lora_dropout 0.1 \
  28. --lora_target query_key_value \
  29. --resume_lora_training True \
  30. --output_dir saves/ChatGLM2-6B-Chat/lora/train_2023-12-12-23-26-49 \
  31. --fp16 True \
  32. --plot_loss True

 ds_config.json的格式下面的:

  1. {
  2. "train_batch_size": "auto",
  3. "train_micro_batch_size_per_gpu": "auto",
  4. "gradient_accumulation_steps": "auto",
  5. "gradient_clipping": "auto",
  6. "zero_allow_untested_optimizer": true,
  7. "fp16": {
  8. "enabled": "auto",
  9. "loss_scale": 0,
  10. "initial_scale_power": 16,
  11. "loss_scale_window": 1000,
  12. "hysteresis": 2,
  13. "min_loss_scale": 1
  14. },
  15. "zero_optimization": {
  16. "stage": 2,
  17. "allgather_partitions": true,
  18. "allgather_bucket_size": 5e8,
  19. "reduce_scatter": true,
  20. "reduce_bucket_size": 5e8,
  21. "overlap_comm": false,
  22. "contiguous_gradients": true
  23. }
  24. }

 跑成功的效果图:

如果出现下面 这个问题,

[E ProcessGroupNCCL.cpp:916] [Rank 3] NCCL watchdog thread terminated with exception: CUDA error: the launch timed out and was terminated CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.

可能原因是显卡坏了或者显卡不是同一个型号!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/45707
推荐阅读
相关标签
  

闽ICP备14008679号