Skip to content

[fix] Use the correct _tied_weights_keys for CamembertForCausalLM#45031

Merged
Cyrilvallez merged 1 commit into
huggingface:mainfrom
tomaarsen:fix/camembert_causal_lm
Mar 26, 2026
Merged

[fix] Use the correct _tied_weights_keys for CamembertForCausalLM#45031
Cyrilvallez merged 1 commit into
huggingface:mainfrom
tomaarsen:fix/camembert_causal_lm

Conversation

@tomaarsen

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up for #44931, which added weight tying for Camembert.
Only the CamembertForMaskedLM class had the right _tied_weights_keys, the CamembertForCausalLM had the incorrect weight key.

Details

from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-camembert")
print(type(model))

On main:

Traceback (most recent call last):
  File "[sic]\demo_camembert.py", line 4, in <module>
    model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-camembert")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\models\auto\auto_factory.py", line 381, in from_pretrained
    return model_class.from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\modeling_utils.py", line 4087, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\models\camembert\modeling_camembert.py", line 1171, in __init__
    self.post_init()
  File "[sic]\src\transformers\modeling_utils.py", line 1298, in post_init   
    self.all_tied_weights_keys = self.get_expanded_tied_weights_keys(all_submodels=False)   
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   
  File "[sic]\src\transformers\modeling_utils.py", line 2490, in get_expanded_tied_weights_keys
    raise ValueError(
ValueError: There is an issue with your definition of `tie_weights_keys` for ^camembert.embeddings.word_embeddings.weight:^lm_head.decoder.weight. We found [] to tie into ['lm_head.decoder.weight']

On this PR:

<class 'transformers.models.camembert.modeling_camembert.CamembertForCausalLM'>

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

I wrote the code and PR description myself

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?

Who can review?

@ArthurZucker @Cyrilvallez

  • Tom Aarsen

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: camembert

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@Cyrilvallez Cyrilvallez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn indeed! Thanks!

@Cyrilvallez Cyrilvallez added this pull request to the merge queue Mar 26, 2026
Merged via the queue into huggingface:main with commit 882ffdb Mar 26, 2026
23 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Mar 27, 2026
…uggingface#45031)

Use the correct _tied_weights_keys for CamembertForCausalLM
NielsRogge pushed a commit to NielsRogge/transformers that referenced this pull request Mar 30, 2026
…uggingface#45031)

Use the correct _tied_weights_keys for CamembertForCausalLM
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.

3 participants