[Bugfix] Use sys.modules.get() to avoid KeyError in modeling_utils#45043
Closed
Lidang-Jiang wants to merge 1 commit intohuggingface:mainfrom
Closed
[Bugfix] Use sys.modules.get() to avoid KeyError in modeling_utils#45043Lidang-Jiang wants to merge 1 commit intohuggingface:mainfrom
Lidang-Jiang wants to merge 1 commit intohuggingface:mainfrom
Conversation
…erts_implementation (huggingface#45003) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
No, sorry! The fix we need was still being discussed in the issue, so it is not helpful to open a full agent PR at this stage. |
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.
What does this PR do?
Fixes #45003.
_can_set_attn_implementationand_can_set_experts_implementationinmodeling_utils.pycrash withKeyErrorwhencls.__module__is absent fromsys.modules.This happens in real-world scenarios where frameworks manipulate
sys.modules(e.g., Griptape Nodes for Flux.1 ControlNets, vLLM CI with renamed image processor modules).Fix
Replace
sys.modules[cls.__module__]withsys.modules.get(cls.__module__)and add aNonecheck to the existing guard. ReturnsFalse(safe default = "don't try to dynamically set implementation") instead of crashing. This matches the pattern already used indynamic_module_utils.py:293andimport_utils.py:2373.4 lines changed in production code, 2 regression tests added.
Coordination
gh pr list --state open --search "45003 in:body"returns empty).Before / After
Before fix (KeyError on all three calls)
After fix (no crash, returns False, model init succeeds)
Regression tests
AI disclosure
This PR was developed with Claude Code assistance. I have reviewed every changed line and can defend the approach end-to-end.