modelscope / ms-swift

Use PEFT or Full-parameter to finetune 400+ LLMs or 100+ MLLMs. (LLM: Qwen2.5, Llama3.2, GLM4, Internlm2.5, Yi1.5, Mistral, Baichuan2, DeepSeek, Gemma2, ...; MLLM: Qwen2-VL, Qwen2-Audio, Llama3.2-Vision, Llava, InternVL2, MiniCPM-V-2.6, GLM4v, Xcomposer2.5, Yi-VL, DeepSeek-VL, Phi3.5-Vision, ...)
https://swift.readthedocs.io/zh-cn/latest/Instruction/index.html
Apache License 2.0
4.34k stars 381 forks source link

UnboundLocalError: local variable 'linear_cls' referenced before assignment #2465

Closed cryrookie closed 3 days ago

cryrookie commented 4 days ago

使用界面训练总会出现这个,全默认设置第一个数据集,不知道是我传入参数的问题还是代码本身微调训练的find_all_linears这个函数的问题,具体报错为Traceback (most recent call last): File "/mnt/workspace/swift/swift/cli/sft.py", line 5, in sft_main() File "/mnt/workspace/swift/swift/utils/run_utils.py", line 32, in x_main result = llm_x(args, **kwargs) File "/mnt/workspace/swift/swift/llm/sft.py", line 544, in llm_sft model, template, callbacks = prepare_model_template_train(args, msg) File "/mnt/workspace/swift/swift/llm/sft.py", line 277, in prepare_model_template_train model, callbacks = prepare_model(model, args) File "/mnt/workspace/swift/swift/llm/tuner.py", line 99, in prepare_model handle_target_modules(model, args) File "/mnt/workspace/swift/swift/llm/tuner.py", line 31, in handle_target_modules target_modules += find_all_linears(model, args.quantization_bit, args.model_type, args.quant_method) File "/mnt/workspace/swift/swift/llm/utils/utils.py", line 594, in find_all_linears if not isinstance(module, tuple(linear_cls)): UnboundLocalError: local variable 'linear_cls' referenced before assignment

slin000111 commented 3 days ago

log中有训练命令行,找出来看看

cryrookie commented 3 days ago

log中有训练命令行,找出来看看

CUDA_VISIBLE_DEVICES=0 nohup swift sft --model_id_or_path 'qwen/Qwen2.5-7B-Instruct' --template_type 'qwen2_5' --system 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' --dataset 'alpaca-zh' --lora_target_modules 'ALL' --init_lora_weights 'True' --learning_rate '1e-4' --gradient_accumulation_steps '16' --eval_steps '500' --save_steps '500' --quant_method 'bnb' --eval_batch_size '1' --ref_model_type 'qwen-1_8b' --deepspeed default-zero2 --add_output_dir_suffix False --output_dir /mnt/workspace/output/qwen2_5-7b-instruct/v0-20241119-161803 --logging_dir /mnt/workspace/output/qwen2_5-7b-instruct/v0-20241119-161803/runs --ignore_args_error True > /mnt/workspace/output/qwen2_5-7b-instruct/v0-20241119-161803/runs/run.log 2>&1 & 不过我现在没有继续用ui界面了,而是命令行手动输入,这样输入只要不含量化相关参数就已经没有再触发这个错误

slin000111 commented 3 days ago

--ref_model_type 'qwen-1_8b'这个参数不是界面上填的吧

cryrookie commented 3 days ago

--ref_model_type 'qwen-1_8b'这个参数不是界面上填的吧

那可能就是问题了,因为是测试,我在界面上只填写了必须要填不然会直接报错的模型名字和数据集,其他统统都是默认的,没有修改,然后输出的命令就是这个,模型名字是qwen2_5-7b-instruct,数据集是选项的第一个

slin000111 commented 3 days ago

--ref_model_type 'qwen-1_8b'这个参数不是界面上填的吧

那可能就是问题了,因为是测试,我在界面上只填写了必须要填不然会直接报错的模型名字和数据集,其他统统都是默认的,没有修改,然后输出的命令就是这个,模型名字是qwen2_5-7b-instruct,数据集是选项的第一个

尝试换个gradio版本

cryrookie commented 3 days ago

gradio 做了如下更新 gradio-5.6.0 gradio-client-1.4.3 但并没有改变报错

slin000111 commented 3 days ago

gradio 做了如下更新 gradio-5.6.0 gradio-client-1.4.3 但并没有改变报错

Try 4.44.0

cryrookie commented 3 days ago

gradio 做了如下更新 gradio-5.6.0 gradio-client-1.4.3 但并没有改变报错

Try 4.44.0

在此版本的gradio下并未报错,问题解决了,十分感谢你的帮助