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

Bug : there is a bug in the finetune.py, that would result to an empyt adapter checkpoint after training!!! #477

Open
DragonMengLong opened this issue May 24, 2023 · 4 comments

Comments

@DragonMengLong
Copy link

DragonMengLong commented May 24, 2023

In the finetune.py, lin line 246, where the original model.state_dict is changed into a lambda function of get_peft_model_state_dict()

get_peft_model_state_dict() will retuen a dict of only the Lora parameter and the keys of the parameter is regularized, the adapter_name in the key string is removed.
to_return = {k.replace(f".{adapter_name}", ""): v for k, v in to_return.items()}

Then when saving the model after Training, In the finetune.py line 275, use the model.save_pretrained() function, which is implemented by the PeftModel.save_pretrained(). Inside the PeftModel.save_pretrained(), get_peft_model_state_dict() is used again.

However, because the model.state_dict is already changed! The dict returened by it is regularized (changed keys' name), the the get_peft_model_state_dict() inside the PeftModel.save_pretrained() will remove all the parameter whose keys string doesn't contain the adapter_name, which is all! It will result in the final state_dict to be save is None!!!
to_return = {k: v for k, v in to_return.items() if (("lora_" in k and adapter_name in k) or ("bias" in k))}

@TianqiYe
Copy link

yea, I just realized that this morning after all-night training lol

@DragonMengLong DragonMengLong changed the title Bug:there is a bug in the finetune.py, that would result to an empyt adapter checkpoint after training!!! Bug : there is a bug in the finetune.py, that would result to an empyt adapter checkpoint after training!!! May 25, 2023
@minruigui
Copy link

I've identified the issue. It lies within the code:

old_state_dict = model.state_dict
model.state_dict = (
lambda self, *_, **__: get_peft_model_state_dict(
self, old_state_dict()
)
).get(model, type(model))

Commenting out this part will resolve the issue."

@vihangd
Copy link

vihangd commented May 30, 2023

I have tried to fix some of these issues in my QLoRA fork of alpaca-lora https://github.com/vihangd/alpaca-qlora Feel free to give it a go and report any issues that you might encounter.

@cwzhao
Copy link

cwzhao commented Jun 9, 2023

I just delete the adapter_name in k in perf. No idea if it will cause some other bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants