CUDA error: an illegal memory access was encountered
Author: zyh3826
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.3.3
- Platform: Ubuntu 18.04.5 LTS (x86_64)
- Python version: 3.8 (64-bit runtime)
- PyTorch version (GPU?): 1.7.1 with gpu
- Tensorflow version (GPU?):
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: No
- CUDA/cuDNN version: NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 CUDA Version: 10.2
- GPU models and configuration: RTX 2080Ti

### 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.
@LysandreJik maybe you can help me?
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: @Rocketknight1

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

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
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using (Bert, XLNet ...):
Glyce -Bert, Glyce is a Chinese char representation based on Chinese glyph information.
The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)
It‘s a Chinese STS task
## To reproduce

Steps to reproduce the behavior:

1.install transformers==4.3.3
tqdm
sklearn
tensorboardX
apex,
zhconv==1.4.0
pypinyin==0.34.1
pywubi==0.0.2
boto3
botocore
overrides
2.git clone https://github.com/ShannonAI/glyce.git
cd glyce
python3 setup.py develop
3.git clone https://github.com/zyh3826/GlyceBertTest.git
modify dataset path and model path in config.yaml
4.download BERT-Base, Chinese at https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip
convert tf checkpoint to pytorch;
copy the bert's pytorch_model.bin to glyce_bert/;
modify glyph_config.bert_model in glyce_bert/bert_config.json;
5. python3 my_trainer.py and wait. if you use LCQMC/dev.txt as train, eval, test.txt as test dataset the error will happen at the third evaluation loop

<!-- 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.-->

> Traceback (most recent call last):
  File "my_trainer.py", line 201, in <module>
    trainer.train()
  File "my_trainer.py", line 146, in train
    self.log(eval_dataloader, loss_item, outputs, labels, global_step, lr)
  File "/source/code/zhaoyhy/AI/src/toolFunction/trainer/trainer.py", line 289, in log
    eval_report = self.evaluate(eval_dataloader)
  File "/source/code/zhaoyhy/AI/src/toolFunction/trainer/trainer.py", line 227, in evaluate
    outputs, labels, loss = self.evaluate_step(batch)
  File "my_trainer.py", line 185, in evaluate_step
    outputs, _ = self.model(**inputs)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/source/code/zhaoyhy/AI/src/STS/GlyceBERT/model.py", line 30, in forward
    encoded_layers, _, glyph_cls_loss = self.glyph_transformer(
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/source/code/zhaoyhy/AI/src/STS/GlyceBERT/glyce_transformer.py", line 36, in forward
    outputs = self.bert_model(**inputs)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/transformers/models/bert/modeling_bert.py", line 939, in forward
    extended_attention_mask: torch.Tensor = self.get_extended_attention_mask(attention_mask, input_shape, device)
  File "/usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py", line 275, in get_extended_attention_mask
    extended_attention_mask = extended_attention_mask.to(dtype=self.dtype)  # fp16 compatibility
RuntimeError: CUDA error: an illegal memory access was encountered

## Expected behavior
no error
<!-- A clear and concise description of what you would expect to happen. -->


Comments: