From 4774a57c7f001e9da8791ae1e3dcfe231ce6a679 Mon Sep 17 00:00:00 2001 From: rishab26201 Date: Fri, 23 Jun 2023 10:06:57 -0700 Subject: [PATCH 1/3] CvTOnnx --- optimum/exporters/onnx/model_configs.py | 5 +++++ optimum/exporters/tasks.py | 3 +++ optimum/utils/normalized_config.py | 1 + tests/exporters/exporters_utils.py | 1 + 4 files changed, 10 insertions(+) diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index da0570be00..d38cb861ea 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -550,6 +550,11 @@ def inputs(self) -> Dict[str, Dict[int, str]]: return {"pixel_values": {0: "batch_size", 1: "num_channels", 2: "height", 3: "width"}} +class CvTOnnxConfig(ViTOnnxConfig): + DEFAULT_ONNX_OPSET = 13 + ATOL_FOR_VALIDATION = 1e-2 + + class LevitOnnxConfig(ViTOnnxConfig): pass diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index 1378d8917c..14194314a0 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -402,6 +402,9 @@ class TasksManager: "image-classification", onnx="ConvNextOnnxConfig", ), + "cvt": supported_tasks_mapping( + "feature-extraction", "image-classification", "masked-im", onnx="CvTOnnxConfig" + ), "data2vec-text": supported_tasks_mapping( "feature-extraction", "fill-mask", diff --git a/optimum/utils/normalized_config.py b/optimum/utils/normalized_config.py index 2e17a68fb4..3016dfa736 100644 --- a/optimum/utils/normalized_config.py +++ b/optimum/utils/normalized_config.py @@ -205,6 +205,7 @@ class NormalizedConfigManager: "bloom": NormalizedTextConfig.with_args(num_layers="n_layer"), "camembert": NormalizedTextConfig, "codegen": GPT2LikeNormalizedTextConfig, + "cvt": NormalizedVisionConfig, "deberta": NormalizedTextConfig, "deberta-v2": NormalizedTextConfig, "deit": NormalizedVisionConfig, diff --git a/tests/exporters/exporters_utils.py b/tests/exporters/exporters_utils.py index aa261bc195..c28613c793 100644 --- a/tests/exporters/exporters_utils.py +++ b/tests/exporters/exporters_utils.py @@ -43,6 +43,7 @@ "clip": "hf-internal-testing/tiny-random-CLIPModel", "convbert": "hf-internal-testing/tiny-random-ConvBertModel", "codegen": "hf-internal-testing/tiny-random-CodeGenModel", + "cvt": "hf-internal-testing/tiny-random-CvTModel", "data2vec-text": "hf-internal-testing/tiny-random-Data2VecTextModel", "data2vec-vision": "hf-internal-testing/tiny-random-Data2VecVisionModel", "data2vec-audio": "hf-internal-testing/tiny-random-Data2VecAudioModel", From 78dcf5f044c86da84d3489484d353d891ae0c4a9 Mon Sep 17 00:00:00 2001 From: rishab26201 Date: Fri, 23 Jun 2023 14:37:46 -0700 Subject: [PATCH 2/3] Tests Passed --- optimum/exporters/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index 14194314a0..05c9fa8660 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -403,7 +403,7 @@ class TasksManager: onnx="ConvNextOnnxConfig", ), "cvt": supported_tasks_mapping( - "feature-extraction", "image-classification", "masked-im", onnx="CvTOnnxConfig" + "feature-extraction", "image-classification", onnx="CvTOnnxConfig" ), "data2vec-text": supported_tasks_mapping( "feature-extraction", From 1a6af8d7dc531f4a80d0f1c22126b75cf04b6ea4 Mon Sep 17 00:00:00 2001 From: rishab26201 Date: Mon, 26 Jun 2023 07:31:55 -0700 Subject: [PATCH 3/3] style --- optimum/bettertransformer/models/encoder_models.py | 2 +- optimum/exporters/tasks.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/optimum/bettertransformer/models/encoder_models.py b/optimum/bettertransformer/models/encoder_models.py index fcfc882bf8..3913830640 100644 --- a/optimum/bettertransformer/models/encoder_models.py +++ b/optimum/bettertransformer/models/encoder_models.py @@ -639,7 +639,7 @@ def forward(self, x, attn_mask, head_mask=None, output_attentions=None, *_): attn_mask = torch.reshape(attn_mask, (attn_mask.shape[0], attn_mask.shape[-1])) seqlen = attn_mask.shape[1] lengths = torch.sum(~attn_mask, 1) - if not all([l == seqlen for l in lengths]): + if not all(l == seqlen for l in lengths): x = torch._nested_tensor_from_mask(x, attn_mask) attn_mask = None diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index 05c9fa8660..e841a6e047 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -402,9 +402,7 @@ class TasksManager: "image-classification", onnx="ConvNextOnnxConfig", ), - "cvt": supported_tasks_mapping( - "feature-extraction", "image-classification", onnx="CvTOnnxConfig" - ), + "cvt": supported_tasks_mapping("feature-extraction", "image-classification", onnx="CvTOnnxConfig"), "data2vec-text": supported_tasks_mapping( "feature-extraction", "fill-mask",