Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于cast_trainable_params_to_fp32导致lora predict发生错误 #4139

Closed
1 task done
wanghuii1 opened this issue Jun 7, 2024 · 4 comments
Closed
1 task done

关于cast_trainable_params_to_fp32导致lora predict发生错误 #4139

wanghuii1 opened this issue Jun 7, 2024 · 4 comments
Labels
solved This problem has been already solved

Comments

@wanghuii1
Copy link

Reminder

  • I have read the README and searched the existing issues.

System Info

LLaMA Factory, version 0.7.2.dev0

Reproduction

问题描述:
在lora sft训练中,如果扩充special token,则adapter_config会将modules_to_save 设置成input和output embedding层。
训练完成后,导入lora推理时,会在
https://github.com/hiyouga/LLaMA-Factory/blob/f8d8690bf4c2981f3151b4ccf07daeb4f3cd38a9/src/llamafactory/model/adapter.py#L173C1-L173C17

将input 和output embedding层设置成trainable,后续会在

if cast_trainable_params_to_fp32:

将embedding层设置成fp32,这个是和模型其他参数fp16不一致的,导致推理报参数类型不一致出错

Expected behavior

扩充special token的情况下,训练lora后能正常predict

Others

No response

@wanghuii1
Copy link
Author

建议在

if cast_trainable_params_to_fp32:

修改为
if cast_trainable_params_to_fp32 and is_trainable:

@hiyouga
Copy link
Owner

hiyouga commented Jun 7, 2024

推理命令是什么?

@wanghuii1
Copy link
Author

python src/train.py examples/lora_single_gpu/llama3_lora_predict.yaml
后续我尝试了
CUDA_VISIBLE_DEVICES=0,1,2,3 accelerate launch
--config_file examples/accelerate/single_config.yaml
src/train.py examples/lora_single_gpu/llama3_lora_predict.yaml
虽然input embedding(fp32)和proj weight(fp16)仍然不一致,但是没有报错,可以正常计算

@hiyouga hiyouga closed this as completed in cfd6228 Jun 7, 2024
@hiyouga hiyouga added the solved This problem has been already solved label Jun 7, 2024
@hiyouga
Copy link
Owner

hiyouga commented Jun 7, 2024

已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved This problem has been already solved
Projects
None yet
Development

No branches or pull requests

2 participants