Merged
Conversation
|
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. |
zucchini-nlp
approved these changes
Feb 17, 2026
Member
zucchini-nlp
left a comment
There was a problem hiding this comment.
Thanks, that works much better tbh
src/transformers/modeling_utils.py
Outdated
Comment on lines
+2332
to
+2338
| # This check is for remote code that does NOT use either `torch.init` or `transformers.initialization` in `_init_weights` | ||
| # which allow to check the flag directly on param. As they don't and write the params in-place, params would be reinitialized | ||
| # otherwise | ||
| if all(getattr(param, "_is_hf_initialized", False) for param in module.parameters(recurse=False)) and all( | ||
| getattr(buffer, "_is_hf_initialized", False) | ||
| for buffer in module.buffers(recurse=False) | ||
| if buffer is not None |
Member
There was a problem hiding this comment.
nice, forgot that we can get bigger modules
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?
As per the title. The check that was added in #43768 is wrong, as a missing weight would NOT be reinitialized in some cases!
As for the pointers check, it is actually not needed at all since when modules (modules, not parameters) are shared (tied), loading only 1 param from the checkpoints will load both weights correctly as it calls
setattron the module which is the object shared already. So we simply have to remove them from missing keys, instead of an expensive (and sometimes wrong) check of the pointers.This change fixes #44060