[examples] UserWarning: `max_length` is deprecated
Author: stas00
Pull request: no

Not sure how many example scripts are affected by this:
```
src/transformers/generation_utils.py:963: UserWarning: `max_length` is deprecated in this function, use 
`stopping_criteria=StoppingCriteriaList(MaxLengthCriteria(max_length=max_length))` instead.
```
getting this with at least `examples/pytorch/translation/run_translation.py`



Comments:
This one also having same warning `examples/pytorch/summarization/run_summarization.py `

Would you like to tackle this one, @bhadreshpsavani, next? Absolutely no need to say yes ;)

Sure, I will take this issue,
I don't have any extra issue with me apart from this!

Hi @stas00,
I am not very sure that if this is expected behavior or needed to fix,
It's coming from this code blocks
https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/src/transformers/generation_utils.py#L962-L966
Generally, a warning is for a good purpose, right?

we are not passing any `max_length` but still this warning is coming so I think I need to fix that part in the code somewhere

Because of the below default value, the warning is coming,
https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/examples/pytorch/translation/run_translation.py#L139-L144
https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/examples/pytorch/summarization/run_summarization.py#L150-L155
We are passing it in trainer and it uses generation utils at below code
https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/examples/legacy/seq2seq/seq2seq_trainer.py#L220-L224

Thank you for this investigation, @bhadreshpsavani - that's very helpful. It looks like the change was introduced just a day before I filed this Issue.

@Narsil, could we please check with you on this deprecation you introduced in https://github.com/huggingface/transformers/commit/aad95c7cdebc24e780e5a5cf39d832c015e40075

1. Unless I'm missing something the deprecation doesn't seem to be complete since `max_length` is actively used in the same function:

https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/src/transformers/generation_utils.py#L919

I am not sure how a deprecated variable is still used normally in the logic...

Also it's not documented as deprecated:
```
            max_length (:obj:`int`, `optional`, defaults to 20):
                The maximum length of the sequence to be generated.
```

2. it now generates warnings in the example scripts like `run_translation.py` and `run_summarization.py` - so if there is a new way could we please atomically adjust all the places that are now impacted by this change? The examples ideally should be in sync with API changes, since their purpose is to correctly demonstrate how to use the library.

The main entry point leading to this warning in seq2seq examples is:

https://github.com/huggingface/transformers/blob/4e7bf94e7280d2b725ac4644dbe9808560afa5d8/src/transformers/trainer_seq2seq.py#L161-L171

Thank you!


Hi @stas00 ,

Yes, it's my fault 1 deprecation too much on the `generate` function ! 
Just submitted a new PR to remove this extra warnings (which is incorrect).

`max_length`  is used by `generate` but not by the subsequent functions.