fix: handle list-type _tied_weights_keys in _get_tied_weight_keys#44862
Closed
gh-wf wants to merge 1 commit intohuggingface:mainfrom
Closed
fix: handle list-type _tied_weights_keys in _get_tied_weight_keys#44862gh-wf wants to merge 1 commit intohuggingface:mainfrom
gh-wf wants to merge 1 commit intohuggingface:mainfrom
Conversation
Some models (e.g. Nemotron-H) define _tied_weights_keys as a list, which caused AttributeError: 'list' object has no attribute 'keys' when calling save_pretrained during full finetuning. 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.
Some models (e.g. Nemotron-H) define
_tied_weights_keysas a list, which causedAttributeError: 'list' object has no attribute 'keys'when callingsave_pretrainedduring full finetuning.What does this PR do?
_get_tied_weight_keysinmodeling_utils.pycalls.keys()on the_tied_weights_keysattribute, assuming it'salways a dict. However, some models (e.g. Nemotron-H) define
_tied_weights_keysas a list, causing anAttributeErrorwhen saving checkpoints during full finetuning.This fix handles both list/tuple and dict types for
_tied_weights_keys.Traceback:
File "transformers/modeling_utils.py", line 341, in _get_tied_weight_keys
tied_weight_keys.extend([f"{name}.{k}" if name else k for k in tied.keys()])
AttributeError: 'list' object has no attribute 'keys'
Reproduction: Full finetune of
NVIDIA-Nemotron-3-Nano-4Bvia Unsloth Studio with Transformers 5.3.0 crashes atcheckpoint save.
Fixes #44861
Before submitting
guideline,
Pull Request section?
link
to it if that's the case.
documentation guidelines, and
here are tips on formatting
docstrings.
AI Disclosure: This PR was developed with assistance from Claude Code (Claude Opus 4.6). All changes were reviewed
and validated by a human.
Who can review?
@Cyrilvallez — model loading /
save_pretrainedcode path