# Max\_length parameter in T5

**URL:** <https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448>\
**Category:** 🤗Transformers\
**Created:** [March 9, 2023, 6:22pm UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448 "2023-03-09T18:22:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![navjordj](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@navjordj](https://discuss.huggingface.co/u/navjordj)\
**Post date:** [March 9, 2023, 6:22pm UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/1 "2023-03-09T18:22:25Z")

</div>

I am trying to finetune a set of T5 models and it is going well.

However, I have noticed a “max\_length” parameter showing up in the config parameters in W&B. I am using [this](https://github.com/huggingface/transformers/blob/main/examples/pytorch/summarization/run_summarization.py) example script for summarization.

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/f/fedf6d0bc5393804c80b315bd50756d6dccae6ed.png)

I thought that during training the model keeps predicting tokens autoregressively until the eos token gets generated. If the model only predicts a maximum of 20 tokens during training it might explain why my validation loss is lower than my train loss (I am using generation\_max\_length = 80 for validation metrics).

 ![losses](https://us1.discourse-cdn.com/hellohellohello/original/2X/0/050fb5bf45307bacba765e325faaea6ef4fe8ebc.png)

I have not found any info about this parameter in the documentation or where it comes from.

If anyone is familiar with the parameter, I would appreciate an explanation of it.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![navjordj](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@navjordj](https://discuss.huggingface.co/u/navjordj)\
**Post date:** [March 9, 2023, 7:29pm UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/2 "2023-03-09T19:29:45Z")

</div>

After some further research, it seems like the parameter comes from PretrainedConfig in [configuration\_utils.py](https://github.com/huggingface/transformers/blob/main/src/transformers/configuration_utils.py#L284)

I am still not sure if this parameter is used during training or what effect it has.

---

<div class="post-metadata">

**Author:** ![tsei902](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@tsei902](https://discuss.huggingface.co/u/tsei902)\
**Post date:** [March 22, 2023, 10:44am UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/3 "2023-03-22T10:44:38Z")

</div>

Hi navjordj, i also use T5 & wandb, and modified my max\_length to another parameter. Also for me max\_length=20 keeps appearing and I dont know why. Did you find out anything else so far?

---

<div class="post-metadata">

**Author:** ![navjordj](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@navjordj](https://discuss.huggingface.co/u/navjordj)\
**Post date:** [March 22, 2023, 11:24am UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/4 "2023-03-22T11:24:20Z")

</div>

Hello tsei902! 🤗

I discovered that the parameter originates from [configuration\_utils.py](https://github.com/huggingface/transformers/blob/main/src/transformers/configuration_utils.py#L284), which is inherited by the T5 configuration.

Upon examining the source code, I couldn’t find any instances where this parameter is utilized. My best guess is that if generation\_max\_length is not provided, it defaults to max\_length.

Please let me know if you find out of the parameter is used or has a effect.

---

<div class="post-metadata">

**Author:** ![tsei902](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@tsei902](https://discuss.huggingface.co/u/tsei902)\
**Post date:** [March 22, 2023, 1:22pm UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/5 "2023-03-22T13:22:48Z")

</div>

Yes, I found that now too. It seems that parameter is T5 default and doesnt get overwritten in wandb, even though I pass another max\_length value during generation. E.g. the default parameter of max\_length=20 is only taken if no other value is given.

---

<div class="post-metadata">

**Author:** ![kartiksrma](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kartiksrma/32/31208_2.png) [@kartiksrma](https://discuss.huggingface.co/u/kartiksrma)\
**Post date:** [September 4, 2024, 3:40am UTC](https://discuss.huggingface.co/t/max-length-parameter-in-t5/33448/6 "2024-09-04T03:40:44Z")

</div>

hi @tsei902, where do I have to override this parameter,
