Skip to content

fix: handle list-type _tied_weights_keys in _get_tied_weight_keys#44862

Closed
gh-wf wants to merge 1 commit intohuggingface:mainfrom
gh-wf:fix/get-tied-weight-keys-list-type
Closed

fix: handle list-type _tied_weights_keys in _get_tied_weight_keys#44862
gh-wf wants to merge 1 commit intohuggingface:mainfrom
gh-wf:fix/get-tied-weight-keys-list-type

Conversation

@gh-wf
Copy link
Copy Markdown

@gh-wf gh-wf commented Mar 19, 2026

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.

What does this PR do?

_get_tied_weight_keys in modeling_utils.py calls .keys() on the _tied_weights_keys attribute, assuming it's
always a dict. However, some models (e.g. Nemotron-H) define _tied_weights_keys as a list, causing an
AttributeError when 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-4B via Unsloth Studio with Transformers 5.3.0 crashes at
checkpoint save.

Fixes #44861

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor
    guideline
    ,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a
    link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting
    docstrings
    .
  • Did you write any new necessary tests?

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_pretrained code path

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_get_tied_weight_keys crashes with AttributeError when _tied_weights_keys is a list

3 participants