Fix NameError: PeftConfigLike triggered by PreTrainedModel.__init_subclass__#45658
Merged
qgallouedec merged 2 commits intomainfrom Apr 27, 2026
Merged
Fix NameError: PeftConfigLike triggered by PreTrainedModel.__init_subclass__#45658qgallouedec merged 2 commits intomainfrom
NameError: PeftConfigLike triggered by PreTrainedModel.__init_subclass__#45658qgallouedec merged 2 commits intomainfrom
Conversation
albertvillanova
approved these changes
Apr 27, 2026
Member
albertvillanova
left a comment
There was a problem hiding this comment.
Thanks for the quick fix!
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
ArthurZucker
pushed a commit
that referenced
this pull request
Apr 28, 2026
…subclass__` (#45658) * fix: update PeftConfigLike import to improve type hinting * style
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.
#45425 added a class-level
peft_configannotation inintegrations/peft.py:transformers/src/transformers/integrations/peft.py
Lines 407 to 428 in 63378d9
PeftConfigLikeis imported only underTYPE_CHECKING, so it does not exist in the module's runtime namespace.PreTrainedModelinherits fromPeftAdapterMixin, andmodeling_utils.py:1296runsget_type_hints(cls)inside__init_subclass__.transformers/src/transformers/modeling_utils.py
Lines 1285 to 1297 in 63378d9
get_type_hintswalks the MRO and eagerly evaluates every forward reference in each base's module globals, so the unresolved"PeftConfigLike"raisesNameErrorthe moment anyPreTrainedModelsubclass is defined.It's an import-time failure. It fires while
transformers.modeling_utilsitself is being imported (first triggered byPreTrainedAudioTokenizerBase), so any downstream library that imports a model (e.g.trl'sSFTTrainer) fails at collectionFix
Move
PeftConfigLikeout of theTYPE_CHECKINGblock so it's available at runtime, and drop the now-unneeded forward-reference quotes on the annotation.