-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for SigLIP models (#473)
* Add support for SigLIP models * Skip siglip tokenizer tests * Move SigLIP-specific zero-shot-image-classification logic to pipeline
- Loading branch information
Showing
10 changed files
with
218 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Support exporting vision and text models separately: | ||
# Adapted from https://github.com/huggingface/optimum/issues/1186#issuecomment-1637641760 | ||
|
||
from optimum.exporters.onnx.model_configs import SiglipTextOnnxConfig, ViTOnnxConfig | ||
from typing import Dict | ||
|
||
|
||
class SiglipVisionOnnxConfig(ViTOnnxConfig): | ||
pass | ||
|
||
|
||
class SiglipTextModelOnnxConfig(SiglipTextOnnxConfig): | ||
@property | ||
def outputs(self) -> Dict[str, Dict[int, str]]: | ||
return { | ||
"last_hidden_state": {0: "batch_size", 1: "sequence_length"}, | ||
"pooler_output": {0: "batch_size"}, | ||
} | ||
|
||
def generate_dummy_inputs(self, framework: str = "pt", **kwargs): | ||
dummy_inputs = super().generate_dummy_inputs(framework=framework, **kwargs) | ||
if framework == "pt": | ||
import torch | ||
dummy_inputs["input_ids"] = dummy_inputs["input_ids"].to(dtype=torch.int64) | ||
return dummy_inputs | ||
|
||
class SiglipVisionModelOnnxConfig(SiglipVisionOnnxConfig): | ||
@property | ||
def outputs(self) -> Dict[str, Dict[int, str]]: | ||
return { | ||
"last_hidden_state": {0: "batch_size"}, | ||
"pooler_output": {0: "batch_size"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters