ONNX model conversion error
Author: kobiche
Pull request: no

### System Info

- `transformers` version: 4.30.1
- Platform: Linux-5.4.0-126-generic-x86_64-with-glibc2.29
- Python version: 3.8.10
- Huggingface_hub version: 0.15.1
- Safetensors version: 0.3.1
- PyTorch version (GPU?): 1.10.1+cu111 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no

I additionally have: 
- onnx==1.12.0
- protobuf==3.19.6

### Who can help?

@lewtun 

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

This is a follow up to the task #19320 where I tried to export the model mdeberta model to onnx format.

I saw that there is an issue with similar model configurations #16841, but still does not work for me. 
Please can someone review this?

This is a sample code
```
from collections import OrderedDict
from typing import Mapping
from pathlib import Path
from transformers.onnx import export
from transformers.onnx import OnnxConfig
from transformers import AutoTokenizer, AutoModel, AutoConfig


config = AutoConfig.from_pretrained('microsoft/mdeberta-v3-base')
base_model = AutoModel.from_pretrained('microsoft/mdeberta-v3-base')
tokenizer = AutoTokenizer.from_pretrained('microsoft/mdeberta-v3-base')

class DebertaConfig(OnnxConfig):
    @property
    def inputs(self) -> Mapping[str, Mapping[int, str]]:
        return OrderedDict(
            [
                ("input_ids", {0: "batch", 1: 'sequ_length'}),
                ("attention_mask", {0: "batch", 1: 'sequ_length'}),
                ("token_lengths", {0: 'sent-count'}),
                ("word_ids", {0: "batch", 1: 'sequ_length'}),
            ]
        )
    @property
    def outputs(self) -> Mapping[str, Mapping[int, str]]:
        return OrderedDict(
            [
                ("token_embeddings", {0: 'sent-count', 1: 'max_token_count', 2: 'token_embedding_size'}),
            ]
        )
    
	
onnx_config = DebertaConfig(config)
onnx_path = Path('mdeberta.onxx')
onnx_inputs, onnx_outputs = export(tokenizer, base_model, onnx_config, 13, onnx_path)
```

The code raise the following exception:

> File "/.../site-packages/transformers/models/deberta_v2/modeling_deberta_v2.py", line 136, in symbolic                                                               
>   g, self, r_mask, g.op("Constant", value_t=torch.tensor(torch.finfo(self.type().dtype()).min))                     
>   AttributeError: 'torch._C.TensorType' object has no attribute 'dtype'   

### Expected behavior

Serialized model in onnx format

Comments:
cc @michaelbenayoun 

I ran this script and didn't get any error, maybe because I don't have a GPU. I put a breakpoint before the relevant line and found this:

```
(Pdb) self
attention_scores defined in (%attention_scores : Float(*, *, *, *, strides=[768, 64, 8, 1], requires_grad=0, device=cpu) = onnx::Reshape(%612, %629), scope: transformers.models.deberta_v2.modeling_deberta_v2.DebertaV2Model::/transformers.models.deberta_v2.modeling_deberta_v2.DebertaV2Encoder::encoder/transformers.models.deberta_v2.modeling_deberta_v2.DebertaV2Layer::layer.0/transformers.models.deberta_v2.modeling_deberta_v2.DebertaV2Attention::attention/transformers.models.deberta_v2.modeling_deberta_v2.DisentangledSelfAttention::self # /home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:735:0
)
(Pdb) self.type().dtype()
torch.float32
(Pdb) type(self.type()) is torch._C.TensorType is torch.TensorType
True
(Pdb) torch._C
<module 'torch._C' from '/home/alex/work/transformers/venv/lib/python3.10/site-packages/torch/_C.cpython-310-x86_64-linux-gnu.so'>
```

<details>
<summary>Click to show all the warnings I got which may or may not be relevant</summary>
2023-06-20 18:59:48.309993: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2023-06-20 18:59:48.310119: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2023-06-20 18:59:48.310134: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
/home/alex/work/transformers/src/transformers/convert_slow_tokenizer.py:457: UserWarning: The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option which is not implemented in the fast tokenizers. In practice this means that the fast version of the tokenizer can produce unknown tokens whereas the sentencepiece version would have converted these unknown tokens into a sequence of byte tokens matching the original piece of text.
  warnings.warn(
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:561: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  torch.tensor(mid - 1).type_as(relative_pos),
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:565: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  torch.ceil(torch.log(abs_pos / mid) / torch.log(torch.tensor((max_position - 1) / mid)) * (mid - 1)) + mid
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:724: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  scale = torch.sqrt(torch.tensor(query_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:724: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  scale = torch.sqrt(torch.tensor(query_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:803: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  scale = torch.sqrt(torch.tensor(pos_key_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:803: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  scale = torch.sqrt(torch.tensor(pos_key_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:815: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  scale = torch.sqrt(torch.tensor(pos_query_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:815: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  scale = torch.sqrt(torch.tensor(pos_query_layer.size(-1), dtype=torch.float) * scale_factor)
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:816: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if key_layer.size(-2) != query_layer.size(-2):
/home/alex/work/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py:112: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  output = input.masked_fill(rmask, torch.tensor(torch.finfo(input.dtype).min))
</details>

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.