Fix AttributeError: add num_hidden_layers property to T5GemmaConfig#40920
Closed
avchauzov wants to merge 2 commits intohuggingface:mainfrom
avchauzov:fix-t5gemma-num-hidden-layers
Closed
Fix AttributeError: add num_hidden_layers property to T5GemmaConfig#40920avchauzov wants to merge 2 commits intohuggingface:mainfrom avchauzov:fix-t5gemma-num-hidden-layers
avchauzov wants to merge 2 commits intohuggingface:mainfrom
avchauzov:fix-t5gemma-num-hidden-layers
Conversation
- Add num_hidden_layers property that returns encoder.num_hidden_layers - Fixes issue with Seq2SeqTrainer and DynamicCache expecting config.num_hidden_layers - Resolves #40901
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: t5gemma |
SunMarc
reviewed
Sep 17, 2025
Comment on lines
+619
to
+620
| encoder_num_hidden_layers=self.model_tester.encoder_num_hidden_layers, | ||
| decoder_num_hidden_layers=self.model_tester.decoder_num_hidden_layers, |
Member
There was a problem hiding this comment.
not sure what you are trying to do here as it doesn't exist
Comment on lines
+193
to
+194
| encoder_num_hidden_layers=self.encoder_num_hidden_layers, | ||
| decoder_num_hidden_layers=self.decoder_num_hidden_layers, |
Comment on lines
+330
to
+341
| @property | ||
| def num_hidden_layers(self) -> int: | ||
| """Number of hidden layers in the encoder.""" | ||
| return self.encoder.num_hidden_layers | ||
|
|
||
| @num_hidden_layers.setter | ||
| def num_hidden_layers(self, value): | ||
| """Set number of hidden layers in the encoder.""" | ||
| raise NotImplementedError( | ||
| "This model does not support setting `num_hidden_layers`. " | ||
| "Please set `encoder.num_hidden_layers` and `decoder.num_hidden_layers` separately." | ||
| ) |
Member
There was a problem hiding this comment.
not sure if we want this, maybe it will be better to just fix the generation to get the right attribute ?
gante
suggested changes
Sep 18, 2025
Contributor
gante
left a comment
There was a problem hiding this comment.
Thank you for opening the PR @avchauzov, but the fix is already addressed in #40939 🤗
The actual fix consists in removing a bad overwrite, and then fixing a few subtle bugs :)
Member
|
Nice ! |
Contributor
Author
|
@gante Thank you! I'm closing this PR then! |
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.
What does this PR do?
This PR fixes an
AttributeErrorthat occurs when using T5Gemma models withSeq2SeqTrainer. The issue arises becauseDynamicCacheincache_utils.pyexpectsconfig.num_hidden_layersto exist, butT5GemmaConfigdoesn't have this attribute.Changes:
num_hidden_layersproperty toT5GemmaConfigthat returnsencoder.num_hidden_layersProblem: When training T5Gemma models with
Seq2SeqTrainer, the code fails with:AttributeError: 'T5GemmaConfig' object has no attribute 'num_hidden_layers'Solution: Follow the pattern used by other encoder-decoder models (ProphetNet, Funnel) by adding a computed property that returns the encoder's layer count.
Fixes #40901
Before submitting
Who can review?
@ArthurZucker @SunMarc
(T5Gemma model configuration and Seq2SeqTrainer integration)