-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[BUG] Fix UlyssesSPAttentionHF.register_with_transformers() crash with PEFT models #7737
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] Fix UlyssesSPAttentionHF.register_with_transformers() crash with PEFT models #7737
Conversation
|
hey @sfc-gh-truwase can we look into this change too? |
PEFT models do not inherit from transformers.PreTrainedModel, causing the isinstance check to fail and falling back to AutoConfig.from_pretrained() which expects a string path, leading to a TypeError/OSError. This commit adds a duck-typing check for the attribute, allowing PeftModel and other wrappers to work correctly with UlyssesSPAttentionHF.register_with_transformers(). Signed-off-by: Rakshit-gen <[email protected]>
2b4c45f to
5db0c45
Compare
|
@Rakshit-gen, while this looks good to me, I will ask an expert to take a look. Can you please add a unit test as well? Thanks. |
Add test_ulysses_sp_hf_with_peft_model to verify that register_with_transformers works correctly with PEFT models that have a config attribute but don't inherit from PreTrainedModel. This test uses a mock PEFT model to verify the duck-typing check introduced in the fix. Signed-off-by: Rakshit-gen <[email protected]>
|
@sfc-gh-truwase i had the tests written, just thought they wont be needed, added those! |
Combine the hasattr and isinstance checks into a single condition since they both extract the config attribute in the same way. Signed-off-by: Rakshit-gen <[email protected]>
stas00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix, @Rakshit-gen
|
@stas00 You're welcome. Glad I could help. If you notice anything else, feel free to let me know. |
Description
This PR fixes a crash in
UlyssesSPAttentionHF.register_with_transformers()when a PEFT-wrapped model (e.g.,PeftModel) is passed as themodel_name_or_pathargument.The Issue
The function previously used an overly strict
isinstance(model_name_or_path, PreTrainedModel)check. Since PEFT models do not subclassPreTrainedModel(though they forward to one), the check would fail. The logic then fell through to theelseblock, treating the model object as a string path and callingAutoConfig.from_pretrained(model_name_or_path), which immediately raised aTypeErrororOSError.Changes
.configattribute, we treat it as a model and access the configuration directly.AutoConfig.Validation
Verified that:
PreTrainedModelobjects still register correctly.AutoConfig.from_pretrainedas expected.Fixes #7729