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 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
21 changes: 21 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
}


class VisualBertOnnxConfig(TextAndVisionOnnxConfig):
DEFAULT_ONNX_OPSET = 11
echarlaix marked this conversation as resolved.
Show resolved Hide resolved

NORMALIZED_CONFIG_CLASS = NormalizedTextConfig

@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",
),
"visual_bert": supported_tasks_mapping(
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
"multiple-choice",
"question-answering",
"feature-extraction",
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",
],
},
"visual_bert": "hf-internal-testing/tiny-random-VisualBertModel",
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
}


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",
"visual_bert": "uclanlp/visualbert-vqa-coco-pre",
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
}

TENSORFLOW_EXPORT_MODELS = {
Expand Down
Loading