Fix model loading crash with transformers 5.0.0#194
Open
LostSunset wants to merge 1 commit into1038lab:mainfrom
Open
Fix model loading crash with transformers 5.0.0#194LostSunset wants to merge 1 commit into1038lab:mainfrom
LostSunset wants to merge 1 commit into1038lab:mainfrom
Conversation
Set __file__ attribute on dynamically created module to prevent AttributeError in transformers' _can_set_experts_implementation(). Without this, transformers 5.0.0 fails at sys.modules[cls.__module__].__file__ because the module created via types.ModuleType() lacks __file__. The fallback path also fails due to meta tensor .item() calls during from_pretrained() initialization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
__file__attribute on dynamically created module inRMBGModel.load_model()to fixAttributeErrorwith transformers 5.0.0transformers.modeling_utils._can_set_experts_implementation()crashes accessingsys.modules[cls.__module__].__file__on the module created viatypes.ModuleType()from_pretrained()path also fails due to meta tensor.item()calls during model initializationReproduction
Using
transformers==5.0.0+torch==2.10.0, loading any RMBG-2.0 model produces:Fix
One-line change: add
module.__file__ = birefnet_pathaftertypes.ModuleType()creation (line 190).Test plan
🤖 Generated with Claude Code