Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visualbert onnx suport #2091

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
}


class VisualBertOnnxConfig(TextAndVisionOnnxConfig):
DEFAULT_ONNX_OPSET = 11

@property
def inputs(self) -> Dict[str, Dict[int, str]]:
return {
"input_ids": {0: "batch_size", 1: "sequence_length"},
"attention_mask": {0: "batch_size", 1: "sequence_length"},
"pixel_values": {0: "batch_size", 1: "num_channels", 2: "height", 3: "width"},
}

@property
def outputs(self) -> Dict[str, Dict[int, str]]:
return {
"last_hidden_state": {0: "batch_size", 1: "sequence_length"},
"pooler_output": {0: "batch_size"},
}


class AlbertOnnxConfig(BertOnnxConfig):
DEFAULT_ONNX_OPSET = 14 # now uses F.scaled_dot_product_attention by default for torch>=2.1.1.

Expand Down
6 changes: 6 additions & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,12 @@ class TasksManager:
"text-to-audio",
onnx="VitsOnnxConfig",
),
"visualbert": supported_tasks_mapping(
"multiple-choice",
"question-answering",
"image-to-text",
onnx="VisualBertOnnxConfig",
),
"wavlm": supported_tasks_mapping(
"feature-extraction",
"automatic-speech-recognition",
Expand Down
2 changes: 2 additions & 0 deletions tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"document-question-answering-with-past",
],
},
"visualbert": "hf-internal-testing/tiny-random-VisualBertModel",
}


Expand Down Expand Up @@ -286,6 +287,7 @@
"speech-to-text": "codenamewei/speech-to-text",
"xlm": "xlm-clm-ende-1024",
"xlm-roberta": "Unbabel/xlm-roberta-comet-small",
"visualbert": "unc-nlp/visualbert-uncased",
}

TENSORFLOW_EXPORT_MODELS = {
Expand Down