[BUG] Fix UlyssesSPAttentionHF.register_with_transformers() crash with PEFT models#7737
Merged
stas00 merged 5 commits intodeepspeedai:masterfrom Dec 19, 2025
Merged
Conversation
Contributor
Author
|
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 <sisodiarakshit456@gmail.com>
2b4c45f to
5db0c45
Compare
Collaborator
|
@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 <sisodiarakshit456@gmail.com>
Contributor
Author
|
@sfc-gh-truwase i had the tests written, just thought they wont be needed, added those! |
stas00
reviewed
Dec 19, 2025
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 <sisodiarakshit456@gmail.com>
stas00
approved these changes
Dec 19, 2025
Collaborator
stas00
left a comment
There was a problem hiding this comment.
Thank you for the fix, @Rakshit-gen
Contributor
Author
|
@stas00 You're welcome. Glad I could help. If you notice anything else, feel free to let me know. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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