Skip to content

Fix an edge case for get_encoder() - #42295

Merged
ArthurZucker merged 7 commits into
huggingface:mainfrom
zucchini-nlp:get-submodels
Nov 27, 2025
Merged

Fix an edge case for get_encoder()#42295
ArthurZucker merged 7 commits into
huggingface:mainfrom
zucchini-nlp:get-submodels

Conversation

@zucchini-nlp

@zucchini-nlp zucchini-nlp commented Nov 20, 2025

Copy link
Copy Markdown
Member

What does this PR do?

As per title, fixes #42156 (comment) and adjusts the test case slightly

I didn't not change the setter, we don't call set_encoder unless we're sure there is an encoder right?

@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.

@BenjaminBossan BenjaminBossan 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.

Thanks for fixing this quickly.

@zucchini-nlp
zucchini-nlp enabled auto-merge (squash) November 20, 2025 10:21

@molbap molbap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SGTM, thanks!

Comment thread src/transformers/modeling_utils.py
Comment thread tests/utils/test_modeling_utils.py
BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Nov 20, 2025
When using mixed adapter batches (i.e. using different LoRA adapters in
the same batch), users have to pass adapter_names. When simultaneously
using beam search, these adapter names have to be extended by the number
of beams. For encoder-decoder models, even when applying beam search,
the encoder part of the model should, however, not use the extended
adapter_names. This is because the encoder still uses the original,
non-extended samples.

The need for this used to be checked by calling model.get_encoder().
However, with transformers v5, every PretrainedModel will have a
get_encoder method. The new convention is that it will return self if
there is no encoder. This is now what's being checked.

huggingface/transformers#42156

Note that said PR contains a small bug that leads to self not always
being returned. Therefore, for the full fix of the issue on transformers
main, we also need to await this PR:

huggingface/transformers#42295
@zucchini-nlp

Copy link
Copy Markdown
Member Author

CI is not feeling good today

BenjaminBossan added a commit to huggingface/peft that referenced this pull request Nov 20, 2025
When using mixed adapter batches (i.e. using different LoRA adapters in
the same batch), users have to pass adapter_names. When simultaneously
using beam search, these adapter names have to be extended by the number
of beams. For encoder-decoder models, even when applying beam search,
the encoder part of the model should, however, not use the extended
adapter_names. This is because the encoder still uses the original,
non-extended samples.

The need for this used to be checked by calling model.get_encoder().
However, with transformers v5, every PretrainedModel will have a
get_encoder method. The new convention is that it will return self if
there is no encoder. This is now what's being checked.

huggingface/transformers#42156

Note that said PR contains a small bug that leads to self not always
being returned. Therefore, for the full fix of the issue on transformers
main, we also need to await this PR:

huggingface/transformers#42295
Conzel pushed a commit to Conzel/peft that referenced this pull request Nov 25, 2025
When using mixed adapter batches (i.e. using different LoRA adapters in
the same batch), users have to pass adapter_names. When simultaneously
using beam search, these adapter names have to be extended by the number
of beams. For encoder-decoder models, even when applying beam search,
the encoder part of the model should, however, not use the extended
adapter_names. This is because the encoder still uses the original,
non-extended samples.

The need for this used to be checked by calling model.get_encoder().
However, with transformers v5, every PretrainedModel will have a
get_encoder method. The new convention is that it will return self if
there is no encoder. This is now what's being checked.

huggingface/transformers#42156

Note that said PR contains a small bug that leads to self not always
being returned. Therefore, for the full fix of the issue on transformers
main, we also need to await this PR:

huggingface/transformers#42295
@zucchini-nlp

Copy link
Copy Markdown
Member Author

My last try to pass the flaky test 🤞🏻

@ArthurZucker
ArthurZucker merged commit a33943e into huggingface:main Nov 27, 2025
21 of 23 checks passed
Arlaz pushed a commit to obvious-research/peft that referenced this pull request Jan 9, 2026
When using mixed adapter batches (i.e. using different LoRA adapters in
the same batch), users have to pass adapter_names. When simultaneously
using beam search, these adapter names have to be extended by the number
of beams. For encoder-decoder models, even when applying beam search,
the encoder part of the model should, however, not use the extended
adapter_names. This is because the encoder still uses the original,
non-extended samples.

The need for this used to be checked by calling model.get_encoder().
However, with transformers v5, every PretrainedModel will have a
get_encoder method. The new convention is that it will return self if
there is no encoder. This is now what's being checked.

huggingface/transformers#42156

Note that said PR contains a small bug that leads to self not always
being returned. Therefore, for the full fix of the issue on transformers
main, we also need to await this PR:

huggingface/transformers#42295
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
* fix and edge case

* ci must turn green

* ci must turn green - second try
iambogeumkim pushed a commit to iambogeumkim/peft that referenced this pull request Jun 21, 2026
When using mixed adapter batches (i.e. using different LoRA adapters in
the same batch), users have to pass adapter_names. When simultaneously
using beam search, these adapter names have to be extended by the number
of beams. For encoder-decoder models, even when applying beam search,
the encoder part of the model should, however, not use the extended
adapter_names. This is because the encoder still uses the original,
non-extended samples.

The need for this used to be checked by calling model.get_encoder().
However, with transformers v5, every PretrainedModel will have a
get_encoder method. The new convention is that it will return self if
there is no encoder. This is now what's being checked.

huggingface/transformers#42156

Note that said PR contains a small bug that leads to self not always
being returned. Therefore, for the full fix of the issue on transformers
main, we also need to await this PR:

huggingface/transformers#42295
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.

5 participants