Skip to content

Commit

Permalink
Add ONNX export support for Maskformer
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Aug 30, 2024
1 parent 09ae91a commit 96afc91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/source/exporters/onnx/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Supported architectures from [🤗 Transformers](https://huggingface.co/docs/tra
- M2-M100
- Marian
- MarkupLM
- Maskformer
- MBart
- Mistral
- MobileBert
Expand Down
16 changes: 16 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,22 @@ class MobileNetV2OnnxConfig(MobileNetV1OnnxConfig):
pass


class MaskformerOnnxConfig(ViTOnnxConfig):
# torch.onnx.errors.UnsupportedOperatorError: Exporting the operator 'aten::einsum' to ONNX opset version 11 is not supported.
# Support for this operator was added in version 12, try exporting with this version.
DEFAULT_ONNX_OPSET = 12

@property
def outputs(self) -> Dict[str, Dict[int, str]]:
if self.task == "image-segmentation":
return {
"class_queries_logits": {0: "batch_size", 1: "num_queries"},
"masks_queries_logits": {0: "batch_size", 1: "num_queries", 2: "height", 3: "width"},
}
else:
return super().outputs


class DonutSwinOnnxConfig(ViTOnnxConfig):
DEFAULT_ONNX_OPSET = 11

Expand Down
7 changes: 6 additions & 1 deletion optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TasksManager:
"feature-extraction": "AutoModel",
"fill-mask": "AutoModelForMaskedLM",
"image-classification": "AutoModelForImageClassification",
"image-segmentation": ("AutoModelForImageSegmentation", "AutoModelForSemanticSegmentation"),
"image-segmentation": ("AutoModelForImageSegmentation", "AutoModelForSemanticSegmentation", "AutoModelForInstanceSegmentation", "AutoModelForUniversalSegmentation"),
"image-to-image": "AutoModelForImageToImage",
"image-to-text": "AutoModelForVision2Seq",
"mask-generation": "AutoModel",
Expand Down Expand Up @@ -797,6 +797,11 @@ class TasksManager:
"question-answering",
onnx="MarkupLMOnnxConfig",
),
"maskformer": supported_tasks_mapping(
"feature-extraction",
"image-segmentation",
onnx="MaskformerOnnxConfig",
),
"mbart": supported_tasks_mapping(
"feature-extraction",
"feature-extraction-with-past",
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 @@ -115,6 +115,7 @@
"m2m-100": "hf-internal-testing/tiny-random-m2m_100",
"marian": "sshleifer/tiny-marian-en-de", # hf-internal-testing ones are broken
"markuplm": "hf-internal-testing/tiny-random-MarkupLMModel",
"maskformer": "hf-internal-testing/tiny-random-MaskFormerForInstanceSegmentation",
"mbart": "hf-internal-testing/tiny-random-mbart",
"mistral": "echarlaix/tiny-random-mistral",
"mobilebert": "hf-internal-testing/tiny-random-MobileBertModel",
Expand Down Expand Up @@ -248,6 +249,7 @@
"m2m-100": "hf-internal-testing/tiny-random-m2m_100", # Not using facebook/m2m100_418M because it takes too much time for testing.
"marian": "Helsinki-NLP/opus-mt-en-de",
"markuplm": "hf-internal-testing/tiny-random-MarkupLMModel",
"maskformer": "facebook/maskformer-swin-tiny-coco",
"mbart": "sshleifer/tiny-mbart",
"mobilebert": "google/mobilebert-uncased",
# "mobilenet_v1": "google/mobilenet_v1_0.75_192",
Expand Down

0 comments on commit 96afc91

Please sign in to comment.