Add QDQBert model and quantization examples of SQUAD task
Author: shangz-ai
Pull request: yes

# What does this PR do?

<!--
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.
-->

This PR includes:

1. Add support of Q/DQ BERT model based on HF BERT model.
(**src/transformers/models/qdqbert/**)

QDQBERT model add fake quantization operations (pair of QuantizeLinear/DequantizeLinear ops) to:
- linear layer inputs and weights
- matmul inputs
- residual add inputs

in BERT model.

QDQBERT model will be able to load from any checkpoint of HF BERT model, and perform Quantization Aware Training/Post Training Quantization with the support from [PyTorch-Quantization toolkit](https://github.com/NVIDIA/TensorRT/tree/master/tools/pytorch-quantization).

2. Add an example of SQUAD tasks finetuned by the QDQBERT model and inferenced by TensorRT
(**transformers/examples/research_projects/quantization-qdqbert/**)

In the example, we use qdqbert model to do Quantization Aware Training from pretrained HF BERT model on SQUAD task. Then [TensorRT](https://github.com/NVIDIA/TensorRT) can run the inference of the generated  ONNX model for optimal INT8 performance out-of-the-box.

## 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?
- [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.

A related discussion on this topic [Issue 10639](https://github.com/huggingface/transformers/issues/10639)
- [x] 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 who 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

 -->


Comments:
@LysandreJik @sgugger Thanks!

Some CIs failed since QDQBERT model needs the dependency of Pytorch Quantization Toolkit (https://github.com/NVIDIA/TensorRT/tree/master/tools/pytorch-quantization). This dependency is good to go with simple one-line installation as:
`pip install pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com
`

I'm thinking of either adding the one line installation change to CI or adding quantization toolkit installation to transformers installation (or any other suggestions which are smooth and neat for the HF community) if we want to upstream the model. @LysandreJik @sgugger 

Thanks!

As for the CI failure of check_code_quality, `import pycuda.autoinit` is needed, even if not used, so to initialize CUDA environment. Any suggestions to resolve this?

For the other two check failures, I'm not super sure about what is the root cause. Glad to get insights about how to fix that.

Thanks for working on this! It seems the code quality is not yet passing, could you run the quality scripts? You can do so with the following, from the root of your clone:
```
pip install -e ".[quality]"
make fixup
```

> Thanks for working on this! It seems the code quality is not yet passing, could you run the quality scripts? You can do so with the following, from the root of your clone:
> 
> ```
> pip install -e ".[quality]"
> make fixup
> ```

Thanks for the comments! This is actually somewhere I want to check.

The code quality failure is from the TensorRT inference script `import pycuda.autoinit`. This line of code is needed, but not used, to initialize CUDA environment. Is there a way that I can keep this line of code in the script and pass the code quality test? @patrickvonplaten @LysandreJik @sgugger 

Think there is just one small clean-up left to do:

```
examples/research_projects/quantization-qdqbert/evaluate-hf-trt-qa.py:29:1: F401 'pycuda.autoinit' imported but unused
```

Think there is another line to clean up :-) `examples/research_projects/quantization-qdqbert/evaluate-hf-trt-qa.py:29:1: F401 'pycuda.autoinit' imported but unused`

> Think there is another line to clean up :-) `examples/research_projects/quantization-qdqbert/evaluate-hf-trt-qa.py:29:1: F401 'pycuda.autoinit' imported but unused`

@patrickvonplaten Is there a workaround for it? The `pycuda.autoinit` is imported for cuda environment setup so it is needed in the script. Thanks!

You can add a a comment at the end of the import line `# noqa: F401` to have it be ignored by our styler. To check locally if the test will pass or not, just run `make quality`.

Note that with the merge of #14431, you will need to rebase your PR on master and replace the lines
```
        self.init_weights()
```
by
```
        # Initialize weights and apply final processing
        self.post_init()
```

Let us know if you need any help!

Rebase the PR but not sure why there is the model templates runner CI failure now.

Thanks again for all your work on this!