fixed max_length in beam_search() and group_beam_search() to use beam…
…_scorer.max_length

# What does this PR do?
Fixes the issue #11040
`beam_search()` and `group_beam_search()` uses `beam_scorer.max_length` if `max_length` is not explicitly passed.
<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes #11040 


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors which may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

hi @GeetDsa 

Thanks a lot for the PR. I understand the issue and IMO what should be done here is to make sure to pass the same `max_length` to the `BeamScorer` and `beam_search` instead of changing the method.

This is because the overall philosophy of `generate` is that whenever some argument is `None` its value should explicitly default to the value specified in `config`. This how all generation methods work.<|||||>Thanks for the issue & PR @GeetDsa! I agree with @patil-suraj that we should not change the way `max_length` is set in `beam_search`.

Overall, the problem IMO is actually that `BeamScorer` has a `max_length` attribute... => this shouldn't be the case IMO:
- `BeamHypotheses` has a `max_length` attribute that is unused and can be removed
- `BeamSearchScorer` has a `max_length` attribute that is only used for the function `finalize` => the better approach here would be too pass `max_length` as an argument to `finalize(...)` IMO

This solution will then ensure that only one `max_length` is being used and should also help to refactor out `max_length` cc @Narsil longterm.

Do you want to give it a try @GeetDsa ? :-)<|||||>> Thanks for the issue & PR @GeetDsa! I agree with @patil-suraj that we should not change the way `max_length` is set in `beam_search`.
> 
> Overall, the problem IMO is actually that `BeamScorer` has a `max_length` attribute... => this shouldn't be the case IMO:
> 
> * `BeamHypotheses` has a `max_length` attribute that is unused and can be removed
> * `BeamSearchScorer` has a `max_length` attribute that is only used for the function `finalize` => the better approach here would be too pass `max_length` as an argument to `finalize(...)` IMO
> 
> This solution will then ensure that only one `max_length` is being used and should also help to refactor out `max_length` cc @Narsil longterm.
> 
> Do you want to give it a try @GeetDsa ? :-)

I can give a try :)
<|||||>>  BeamHypotheses has a max_length attribute that is unused and can be removed

Nice !

>     BeamSearchScorer has a max_length attribute that is only used for the function finalize => the better approach here would be too pass max_length as an argument to finalize(...) IMO

Seems easier.
@GeetDsa Do you think you could also add a test that reproduces your issue without your fix and that passes with the fix ? That will make backward compatibility easier to test (we're heading towards a direction to remove `max_length` as much as possible while maintaining backward compatbility)<|||||>I have created a new pull request #11378 ; @Narsil, I think it will be little hard and time consuming for me to implement a test as I am not well-versed with it.<|||||>This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.