Skip to content

Commit

Permalink
Clip vision model onnx export (#1920)
Browse files Browse the repository at this point in the history
clip vision model onnx export
  • Loading branch information
fxmarty authored Jul 11, 2024
1 parent 171020c commit 6772106
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 @@ -896,6 +896,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 @@ -448,6 +448,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 6772106

Please sign in to comment.