Skip to content

Commit

Permalink
clip vision model onnx export
Browse files Browse the repository at this point in the history
  • Loading branch information
fxmarty committed Jun 25, 2024
1 parent aad4b8b commit a042ec4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,22 @@ class CLIPNormalizedConfig(NormalizedTextAndVisionConfig):
VISION_CONFIG = "vision_config"


class CLIPVisionModelOnnxConfig(VisionOnnxConfig):
NORMALIZED_CONFIG_CLASS = NormalizedVisionConfig

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

@property
def outputs(self) -> Dict[str, Dict[int, str]]:
common_outputs = super().outputs
common_outputs["last_hidden_state"] = {0: "batch_size"}
common_outputs["pooler_output"] = {0: "batch_size"}

return common_outputs


class CLIPOnnxConfig(TextAndVisionOnnxConfig):
NORMALIZED_CONFIG_CLASS = CLIPNormalizedConfig
DEFAULT_ONNX_OPSET = 14
Expand Down
4 changes: 4 additions & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ class TasksManager:
"zero-shot-image-classification",
onnx="CLIPOnnxConfig",
),
"clip-vision-model": supported_tasks_mapping(
"feature-extraction",
onnx="CLIPVisionModelOnnxConfig",
),
"codegen": supported_tasks_mapping(
"feature-extraction",
"feature-extraction-with-past",
Expand Down
1 change: 1 addition & 0 deletions tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"bloom": "hf-internal-testing/tiny-random-BloomModel",
"camembert": "hf-internal-testing/tiny-random-camembert",
"clip": "hf-internal-testing/tiny-random-CLIPModel",
"clip-vision-model": "fxmarty/clip-vision-model-tiny",
"convbert": "hf-internal-testing/tiny-random-ConvBertModel",
"convnext": "hf-internal-testing/tiny-random-convnext",
"convnextv2": "hf-internal-testing/tiny-random-ConvNextV2Model",
Expand Down

0 comments on commit a042ec4

Please sign in to comment.