Skip to content

Conversation

@Rakshit-gen
Copy link
Contributor

Description
This PR fixes a crash in UlyssesSPAttentionHF.register_with_transformers() when a PEFT-wrapped model (e.g., PeftModel) is passed as the model_name_or_path argument.

The Issue
The function previously used an overly strict isinstance(model_name_or_path, PreTrainedModel) check. Since PEFT models do not subclass PreTrainedModel (though they forward to one), the check would fail. The logic then fell through to the else block, treating the model object as a string path and calling AutoConfig.from_pretrained(model_name_or_path), which immediately raised a TypeError or OSError.

Changes

  • Updated the logic to use duck-typing: if the input object has a .config attribute, we treat it as a model and access the configuration directly.
  • Hugging Face string paths (Hub IDs or local paths) continue to be handled by the fallback to AutoConfig.

Validation
Verified that:

  1. PEFT-wrapped models now successfully register without crashing.
  2. Standard PreTrainedModel objects still register correctly.
  3. String paths successfully trigger AutoConfig.from_pretrained as expected.

Fixes #7729

@Rakshit-gen
Copy link
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 <[email protected]>
@Rakshit-gen Rakshit-gen force-pushed the fix/ulysses-peft-crash branch from 2b4c45f to 5db0c45 Compare December 19, 2025 17:44
@sfc-gh-truwase
Copy link
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 <[email protected]>
@Rakshit-gen Rakshit-gen requested a review from loadams as a code owner December 19, 2025 17:48
@Rakshit-gen
Copy link
Contributor Author

@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]>
Copy link
Collaborator

@stas00 stas00 left a 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 stas00 enabled auto-merge (squash) December 19, 2025 18:20
@Rakshit-gen
Copy link
Contributor Author

@stas00 You're welcome. Glad I could help. If you notice anything else, feel free to let me know.

@stas00 stas00 merged commit b6f4e20 into deepspeedai:master Dec 19, 2025
11 checks passed
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

Successfully merging this pull request may close these issues.

[BUG] UlyssesSPAttentionHF.register_with_transformers() crashes with PEFT models due to overly strict isinstance(model, PreTrainedModel) check

3 participants