Skip to content

Commit

Permalink
feat: add onnx for visualbert
Browse files Browse the repository at this point in the history
  • Loading branch information
tedasdf committed Nov 6, 2024
1 parent 35eebfe commit c7b7d21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
"token_type_ids": dynamic_axis,
}

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

0 comments on commit c7b7d21

Please sign in to comment.