fix: use bool instead of uint8/byte in Deberta/DebertaV2/SEW-D to make it compatible with TensorRT
Author: uchuhimo
Pull request: yes

# What does this PR do?

TensorRT cannot accept onnx graph with uint8/byte intermediate tensors. This PR uses bool tensors instead of unit8/byte tensors to make the exported onnx file compatible with TensorRT.


Comments:
_The documentation is not available anymore as the PR was closed or merged._

I also fix Deberta/SEW-D since they have the similar compatible issue.

> Could you add a very small snippet to reproduce this just to show the previous error make sure this actually works?

@ArthurZucker Use the following code to export DebertaV2 to ONNX file:

```python
# This script exports DebertaV2 models from HuggingFace directly.
import gc
import torch
from transformers import DebertaV2Model
from transformers.activations import FastGELUActivation
import mock


def make_log_bucket_position(relative_pos, bucket_size, max_position):
    sign = torch.sign(relative_pos.float())
    mid = bucket_size // 2
    abs_pos = torch.where(
        (relative_pos < mid) & (relative_pos > -mid),
        torch.tensor(mid - 1).type_as(relative_pos),
        torch.abs(relative_pos),
    )
    log_pos = (
        torch.ceil(
            torch.log(abs_pos / mid)
            / torch.log(torch.tensor((max_position - 1) / mid))
            * (mid - 1)
        )
        + mid
    )
    bucket_pos = torch.where(
        abs_pos <= mid, relative_pos.type_as(log_pos), log_pos * sign
    )
    return bucket_pos


# The following patch convert the input tensor of sign to float32 dtype,
# since sign op in TensorRT does not support int dtype.
@mock.patch(
    "transformers.models.deberta_v2.modeling_deberta_v2.make_log_bucket_position",
    make_log_bucket_position,
)
def export_deberta(model_name, max_seq_len, fast_gelu=False):
    model = DebertaV2Model.from_pretrained(model_name)

    gelu_tag = ""
    if fast_gelu:
        for layer in model.encoder.layer:
            layer.intermediate.intermediate_act_fn = FastGELUActivation()
        gelu_tag = "-gelu-tanh"

    input_ids = torch.zeros((1, max_seq_len // 2), dtype=torch.int)
    attention_mask = torch.zeros((1, max_seq_len // 2), dtype=torch.int)

    args = (
        input_ids,
        {"attention_mask": attention_mask},
    )

    base_model_name = model_name[model_name.rfind("/") + 1 :]
    torch.onnx.export(
        model,
        args,
        f"{base_model_name}{gelu_tag}.onnx",
        input_names=["input_ids", "attention_mask"],
        output_names=["last_hidden_state"],
        opset_version=13,
        dynamic_axes={
            "input_ids": {0: "batch", 1: "sequence"},
            "attention_mask": {0: "batch", 1: "sequence"},
            "last_hidden_state": {0: "batch", 1: "sequence"},
        },
    )


if __name__ == "__main__":
    export_deberta("microsoft/deberta-v3-large", 4096, True)
```

Use TensorRT to convert ONNX file to engine file:

```bash
trtexec --onnx=deberta-v3-large-gelu-tanh.onnx --explicitBatch --fp16 --shapes=input_ids:1x2048,attention_mask:1x2048 --memPoolSize=workspace:4096 --timingCacheFile=./deberta-v3-large-bs1-seq2048.cache --saveEngine=deberta-v3-large-bs1-seq2048 --buildOnly
```

You will see the following error log:

```
[05/24/2023-03:42:37] [E] [TRT] ModelImporter.cpp:800: While parsing node number 73 [Cast -> "/encoder/Cast_output_0"]:
[05/24/2023-03:42:37] [E] [TRT] ModelImporter.cpp:801: --- Begin node ---
input: "/encoder/Mul_output_0"
output: "/encoder/Cast_output_0"
name: "/encoder/Cast"
op_type: "Cast"
attribute {
  name: "to"
  i: 2
  type: INT
}

[05/24/2023-03:42:37] [E] [TRT] ModelImporter.cpp:802: --- End node ---
[05/24/2023-03:42:37] [E] [TRT] ModelImporter.cpp:804: ERROR: ModelImporter.cpp:239 In function parseNode:
[8] Assertion failed: legalUINT8 && "TensorRT does not support UINT8 types for intermediate tensors!"
[05/24/2023-03:42:37] [E] Failed to parse onnx file
[05/24/2023-03:42:38] [I] Finished parsing network model. Parse time: 15.5136
[05/24/2023-03:42:38] [E] Parsing model failed
[05/24/2023-03:42:38] [E] Failed to create engine from model or file.
[05/24/2023-03:42:38] [E] Engine set up failed
```

After used this MR, the error above will be gone.