Skip to content

Fix AttributeError for remote models with trust_remote_code=True#43951

Closed
lordaarush wants to merge 1 commit intohuggingface:mainfrom
lordaarush:fix-remote-model-tied-weights
Closed

Fix AttributeError for remote models with trust_remote_code=True#43951
lordaarush wants to merge 1 commit intohuggingface:mainfrom
lordaarush:fix-remote-model-tied-weights

Conversation

@lordaarush
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #43883

After #42270, all_tied_weights_keys is initialized in post_init(), but remote models loaded with trust_remote_code=True don't always call post_init() properly, causing AttributeError when loading models like Molmo.

This fix adds defensive checks in two methods:

  • _adjust_tied_keys_with_tied_pointers(): Initialize empty dict if missing, then detect tied weights via data pointers
  • mark_tied_weights_as_initialized(): Return early if attribute missing

This allows remote models to load successfully while maintaining tied weight detection.

Before submitting

  • 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 write any new necessary tests?

Who can review?

@Rocketknight1 @Cyrilvallez

Fixes huggingface#43883

After huggingface#42270, all_tied_weights_keys is initialized in post_init(), but remote models loaded with trust_remote_code=True don't always call post_init() properly, causing AttributeError when loading models like Molmo.

This fix adds defensive checks in two methods:
- _adjust_tied_keys_with_tied_pointers(): Initialize empty dict if missing, then detect tied weights via data pointers
- mark_tied_weights_as_initialized(): Return early if attribute missing

This allows remote models to load successfully while maintaining tied weight detection.
@Cyrilvallez
Copy link
Copy Markdown
Member

See my answer here #43883 (comment)! In the meantime, I'm closing the PR! Let me know if you need anything else 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'MolmoForCausalLM' object has no attribute 'all_tied_weights_keys'

2 participants