fix bug because of implicit attention_mask argument in generation
# What does this PR do?


Fixes # (issue)
gpt2 prepares generation input with attention mask not in explicit way like beolw, and it conflicts with self._validate_model_kwargs which checks unused  arguments and gets error.

```
/usr/local/lib/python3.9/site-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
    113     def decorate_context(*args, **kwargs):
    114         with ctx_factory():
--> 115             return func(*args, **kwargs)
    116 
    117     return decorate_context

/usr/local/lib/python3.9/site-packages/transformers/generation/utils.py in generate(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, streamer, **kwargs)
   1229         model_kwargs = generation_config.update(**kwargs)  # All unused kwargs must be model kwargs
   1230         generation_config.validate()
-> 1231         self._validate_model_kwargs(model_kwargs.copy())
   1232 
   1233         # 2. Set generation parameters if not already defined

/usr/local/lib/python3.9/site-packages/transformers/generation/utils.py in _validate_model_kwargs(self, model_kwargs)
   1107 
   1108         if unused_model_args:
-> 1109             raise ValueError(
   1110                 f"The following `model_kwargs` are not used by the model: {unused_model_args} (note: typos in the"
   1111                 " generate arguments will also show up in this list)"

ValueError: The following `model_kwargs` are not used by the model: ['attention_mask'] (note: typos in the generate arguments will also show up in this list)
```

below is gpt2 ln:1007 https://github.com/huggingface/transformers/blob/main/src/transformers/models/gpt2/modeling_gpt2.py
```
    def prepare_inputs_for_generation(self, input_ids, past_key_values=None, inputs_embeds=None, **kwargs):
        token_type_ids = kwargs.get("token_type_ids", None)
        # only last token for inputs_ids if past is defined in kwargs
        if past_key_values:
            input_ids = input_ids[:, -1].unsqueeze(-1)
            if token_type_ids is not None:
                token_type_ids = token_type_ids[:, -1].unsqueeze(-1)

        attention_mask = kwargs.get("attention_mask", None)
        position_ids = kwargs.get("position_ids", None)
```

## Before submitting
- [v] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [v] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [v] 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.
- [v] 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?
@gante

_The documentation is not available anymore as the PR was closed or merged._<|||||>Hey @Soonhwan-Kwon 👋 

I am unable to reproduce the issue you describe (see script below). Can you share a reproducer for the exception you're seeing?

```py
from transformers import AutoModelForCausalLM, AutoTokenizer

tok = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained("gpt2")

inputs = tok(["This cat is"], return_tensors="pt")
gen_out = model.generate(inputs.input_ids, attention_mask=inputs.attention_mask, do_sample=True)
print(tok.decode(gen_out[0]))
```<|||||>> Hey @Soonhwan-Kwon 👋
> 
> I am unable to reproduce the issue you describe (see script below). Can you share a reproducer for the exception you're seeing?
> 
> ```python
> from transformers import AutoModelForCausalLM, AutoTokenizer
> 
> tok = AutoTokenizer.from_pretrained("gpt2")
> model = AutoModelForCausalLM.from_pretrained("gpt2")
> 
> inputs = tok(["This cat is"], return_tensors="pt")
> gen_out = model.generate(inputs.input_ids, attention_mask=inputs.attention_mask, do_sample=True)
> print(tok.decode(gen_out[0]))
> ```

Sure, it occurs in GPT2LMHeadModel and below is the reproduction code.
```
from transformers import AutoModelWithLMHead, AutoTokenizer
tok = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelWithLMHead.from_pretrained("gpt2")
# GPT2LMHeadModel
inputs = tok(["This cat is"], return_tensors="pt")
gen_out = model.generate(inputs.input_ids, attention_mask=inputs.attention_mask, do_sample=True)
print(tok.decode(gen_out[0]))
```<|||||>@Soonhwan-Kwon I can't reproduce the issue with the script you shared. What version of transformers are you using?