Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ONNX support for ImageGPT #819

Merged
5 changes: 4 additions & 1 deletion optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class CodeGenOnnxConfig(GPT2OnnxConfig):
pass


class ImageGPTOnnxConfig(GPT2OnnxConfig):
pass


class GPTNeoOnnxConfig(TextDecoderOnnxConfig):
DEFAULT_ONNX_OPSET = 13
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig.with_args(num_attention_heads="num_heads")
Expand Down Expand Up @@ -1035,7 +1039,6 @@ def inputs(self) -> Dict[str, Dict[int, str]]:

if self.use_past_in_inputs:
self.add_past_key_values(common_inputs, direction="inputs")

if self._behavior is ConfigBehavior.DECODER:
common_inputs["encoder_outputs"] = {0: "batch_size", 1: "encoder_sequence_length"}

Expand Down
5 changes: 5 additions & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ class TasksManager:
"question-answering",
onnx="IBertOnnxConfig",
),
"imagegpt": supported_tasks_mapping(
"default",
"image-classification",
onnx="ImageGPTOnnxConfig",
),
"layoutlm": supported_tasks_mapping(
"default",
"masked-lm",
Expand Down
1 change: 1 addition & 0 deletions optimum/utils/normalized_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class NormalizedConfigManager:
"gpt_neo": NormalizedTextConfig.with_args(num_attention_heads="num_heads"),
"gpt_neox": NormalizedTextConfig,
"gptj": GPT2LikeNormalizedTextConfig,
"imagegpt": GPT2LikeNormalizedTextConfig,
"longt5": T5LikeNormalizedTextConfig,
"marian": BartLikeNormalizedTextConfig,
"mbart": BartLikeNormalizedTextConfig,
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 @@ -59,6 +59,7 @@
"gptj": "hf-internal-testing/tiny-random-GPTJModel",
"groupvit": "hf-internal-testing/tiny-random-groupvit",
"ibert": "hf-internal-testing/tiny-random-IBertModel",
"imagegpt": "hf-internal-testing/tiny-random-ImageGPTModel",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add an entry below in PYTORCH_EXPORT_MODELS_LARGE for this model for instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"levit": "hf-internal-testing/tiny-random-LevitModel",
"layoutlm": "hf-internal-testing/tiny-random-LayoutLMModel",
"layoutlmv3": "hf-internal-testing/tiny-random-LayoutLMv3Model",
Expand Down Expand Up @@ -158,6 +159,7 @@
"gptj": "anton-l/gpt-j-tiny-random", # TODO
"groupvit": "nvidia/groupvit-gcc-yfcc",
"ibert": "kssteven/ibert-roberta-base",
"imagegpt": "openai/imagegpt-small",
"levit": "facebook/levit-128S",
"layoutlm": "microsoft/layoutlm-base-uncased",
"layoutlmv3": "microsoft/layoutlmv3-base",
Expand Down