Add a default decoder_attention_mask for EncoderDecoderModel during training
Author: hackyon
Pull request: yes

# What does this PR do?

Add a default decoder_attention_mask for EncoderDecoderModel during training. Since we are already creating the default decoder_input_ids from the labels, we should also create a default decoder_attention_mask to go with it.

Before this fix, the user was shown a warning message ("we strongly recommend passing an attention mask") when following the [new suggested](https://huggingface.co/docs/transformers/model_doc/encoder-decoder#training) [method of training](https://github.com/huggingface/transformers/blob/bef02fd6b9cde975c51607fb936050ef706ff6d8/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py#L42-L47) for EncoderDecoderModel. Although there has been no report of the bug in the wild yet as it would be a silent bug, I suspect it will likely cause [this particular issue](https://huggingface.co/docs/transformers/troubleshooting#incorrect-output-when-padding-tokens-arent-masked) if the pad tokens in the default decoder_input_ids are not taken into account.

Fixes #25271 


## 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/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] 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/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] 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 who may be interested in your PR.

@ArthurZucker @StevenSong 



Comments:
Yup, training will be affected without this change if we followed the new recommended way of training EncoderDecoderModel (just passing in labels without specifying decoder_input_ids). I've updated the description.

We would show a warning. Although there is no crash, the training would be flawed since we would be attending to pad tokens in the label sequences (during decoding stage).

Thanks for this PR @hackyon!

> We would show a warning. Although there is no crash, the training would be flawed since we would be attending to pad tokens in the label sequences (during decoding stage).

Could you clarify when this warning would be given? Is this a warning if you _do_ specify both labels and decoder_input_ids?

> Thanks for this PR @hackyon!
> 
> > We would show a warning. Although there is no crash, the training would be flawed since we would be attending to pad tokens in the label sequences (during decoding stage).
> 
> Could you clarify when this warning would be given? Is this a warning if you _do_ specify both labels and decoder_input_ids?

I'm referring to the "we strongly recommend passing an attention mask" warning that you brought up in #25271. This warning comes up when you specify just the labels, and leaving the decoder_input_ids/decoder_attention_mask to None.


Looks good to me too -- thank you for the contribution, @hackyon 🤗