rewrite state_dict in self.model.save_pretrained(), causing the '_metadata' it saved to be missing.
Author: changwangss
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.12.0.dev0
- Platform: linux
- Python version: 3.6
- PyTorch version (GPU?): 1.9.0
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

### Who can help
<!-- Your issue 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, DeBERTa, DeBERTa-v2, ELECTRA, MobileBert, SqueezeBert: @LysandreJik
- encoder-decoder models (For example, BlenderBot, BART, Marian, Pegasus, T5, ByT5): @patrickvonplaten, @patil-suraj
- Longformer, Reformer, TransfoXL, XLNet, FNet: @patrickvonplaten
- FSMT: @stas00
- Funnel: @sgugger
- GPT-2, GPT: @patrickvonplaten, @LysandreJik
- RAG, DPR: @patrickvonplaten, @lhoestq
- TensorFlow: @Rocketknight1
- JAX/Flax: @patil-suraj @patrickvonplaten 
- TAPAS, LayoutLM, LayoutLMv2, LUKE, ViT, BEiT, DEiT, DETR, CANINE: @NielsRogge
- GPT-Neo, GPT-J, CLIP: @patil-suraj
- Wav2Vec2, HuBERT, SpeechEncoderDecoder: @patrickvonplaten, @anton-l

If the model isn't in the list, ping @LysandreJik who will redirect you to the correct contributor.

Library:

- Benchmarks: @patrickvonplaten
- Deepspeed: @stas00
- Ray/raytune: @richardliaw, @amogkam
- Text generation: @patrickvonplaten
- Tokenizers: @LysandreJik
- Trainer: @sgugger
- Pipelines: @Narsil
- Speech: @patrickvonplaten, @anton-l
- Vision: @NielsRogge, @sgugger

Documentation: @sgugger

Model hub:

- for issues with a model, report at https://discuss.huggingface.co/ and tag the model's creator.

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

For research projetcs, please ping the contributor directly. For example, on the following projects:

- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->
function: [self.model.save_pretrained()](https://github.com/huggingface/transformers/blob/master/src/transformers/trainer.py#L2009)  in trainer.py @sgugger 
root cause: the [rewrite state_dict code](https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_utils.py#L1052) in modeling_utils.py added by @stas00 in PR(#8737) to ignore keys
## Information

I am using `Helsinki-NLP/opus-mt-en-ro` in translation task and make it quantized with `intel neural compressor(version 1.7)`.

I would load it from a pre-trained model, fine-tune it, quantize it, then save its state_dict. The issue happens when saving and reloading this quantized version. 

When DynamicQuantizedLinear generates keys, `nn.quantized.Linear`  uses this format:
`model.encoder.layers.0.self_attn.k_proj._packed_params._packed_params` 
corresponding **version=3**, but by using `trainer.save_model()` to save it to **version= 1** due to missing _metadata.
it will cause the quantized model reload failed.
For more information about version, you can see [here](https://github.com/pytorch/pytorch/blob/06e49ea088b36c998e12b7348bdcb4a845b9bb4d/torch/nn/quantized/modules/linear.py#L78) in pytorch repo.
```
    # Version 1
    #   self
    #   |--- weight : Tensor
    #   |--- bias : Tensor
    #
    # Version 2
    #   self
    #   |--- weight : Tensor
    #   |--- bias : Tensor
    #   |--- dtype : torch.dtype
    #
    # Version 3
    #   self
    #   |--- _packed_params : (Tensor, Tensor) representing (weight, bias)
    #                         of LinearPackedParams
    #   |--- dtype : torch.dtype
```
we found that the root cause is to rewrite state_dict in order to ignore keys, resulting in missing _metadata information which related with version choose.

code link: https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_utils.py#L1052
## To reproduce

Steps to reproduce the behavior:

1. load a pre-trained model `Helsinki-NLP/opus-mt-en-ro` , fine-tune it, quantize it with dynamic,
2. save the quantized model and Load it again, you will get an error.
### error
```
  File "/home2/changwa1/anaconda3/envs/inc_example/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1388, in load
    state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs)
  File "/home2/changwa1/anaconda3/envs/inc_example/lib/python3.6/site-packages/torch/nn/quantized/dynamic/modules/linear.py", line 72, in _load_from_state_dict
    missing_keys, unexpected_keys, error_msgs)
  File "/home2/changwa1/anaconda3/envs/inc_example/lib/python3.6/site-packages/torch/nn/quantized/modules/linear.py", line 220, in _load_from_state_dict
    weight = state_dict.pop(prefix + 'weight')
KeyError: 'model.encoder.layers.0.self_attn.k_proj.weight'

```
3. modify the code as following that remove unexpceted keys from state_dict directly instead of rewriting. you will success reload.
### modify
the [rewrite state_dict code](https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_utils.py#L1052) in modeling_utils.py  line 1052.
`origin`
```
        if self._keys_to_ignore_on_save is not None:
            state_dict = {k: v for k, v in state_dict.items() if k not in self._keys_to_ignore_on_save}
``` 
`change`
```
        if self._keys_to_ignore_on_save is not None:
            for item in self._keys_to_ignore_on_save:
                del state_dict[item]
```
<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->

You can modify it as I mentioned, it will be better if you have a more effective solution.

Comments:
I think your solution is very good, to avoid deleting that `_metadata` attribute of the state dict, would you like to make a PR out of it, since you found the fix?

PR has been committed, review please. @sgugger