From 8969e6c5cdc89d14d2cbabc865cf22f46e946012 Mon Sep 17 00:00:00 2001 From: Yann HALLOUARD Date: Sun, 6 Oct 2024 13:25:30 +0200 Subject: [PATCH 1/5] Add RTDetr Onnx Config --- optimum/exporters/onnx/model_configs.py | 15 ++++++++++++++- optimum/exporters/tasks.py | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index 36963a986d0..ad2a8146254 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -1793,7 +1793,8 @@ class SpeechT5OnnxConfig(OnnxSeq2SeqConfigWithPast): # so we won't support for now. NORMALIZED_CONFIG_CLASS = NormalizedSeq2SeqConfig.with_args( hidden_size="hidden_size", - num_attention_heads="encoder_attention_heads", # TODO: bugged in case encoder and decoder have different number of heads + num_attention_heads="encoder_attention_heads", + # TODO: bugged in case encoder and decoder have different number of heads encoder_num_layers="encoder_layers", decoder_num_layers="decoder_layers", allow_new=True, @@ -2310,3 +2311,15 @@ def overwrite_shape_and_generate_input( class EncoderDecoderOnnxConfig(EncoderDecoderBaseOnnxConfig): NORMALIZED_CONFIG_CLASS = NormalizedEncoderDecoderConfig + + +class RTDetrOnnxConfig(ViTOnnxConfig): + DEFAULT_ONNX_OPSET = 16 + ATOL_FOR_VALIDATION = 1e-5 + + @property + def inputs(self) -> Dict[str, Dict[int, str]]: + return { + "pixel_values": {0: "batch_size", 1: "num_channels", 2: "height", 3: "width"}, + "pixel_mask": {0: "batch_size"}, + } diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index a489f34fb06..9ed1cf2deda 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -994,6 +994,10 @@ class TasksManager: onnx="RoFormerOnnxConfig", tflite="RoFormerTFLiteConfig", ), + "rt-detr": supported_tasks_mapping( + "object-detection", + onnx="RTDetrOnnxConfig", + ), "sam": supported_tasks_mapping( "feature-extraction", onnx="SamOnnxConfig", From 58d9548f9931b6d893b545ad146f3fbef0855af7 Mon Sep 17 00:00:00 2001 From: Yann HALLOUARD Date: Sun, 27 Oct 2024 15:37:54 +0100 Subject: [PATCH 2/5] add test and comment --- optimum/exporters/onnx/model_configs.py | 2 ++ tests/exporters/exporters_utils.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index ad2a8146254..49d3c5af4c0 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -2314,6 +2314,8 @@ class EncoderDecoderOnnxConfig(EncoderDecoderBaseOnnxConfig): class RTDetrOnnxConfig(ViTOnnxConfig): + # Export the operator 'aten::grid_sampler' to ONNX fails under opset 16. + # Support for this operator was added in version 16. DEFAULT_ONNX_OPSET = 16 ATOL_FOR_VALIDATION = 1e-5 diff --git a/tests/exporters/exporters_utils.py b/tests/exporters/exporters_utils.py index c8a33b0be35..f75a2a578c1 100644 --- a/tests/exporters/exporters_utils.py +++ b/tests/exporters/exporters_utils.py @@ -142,6 +142,7 @@ "resnet": "hf-internal-testing/tiny-random-resnet", "roberta": "hf-internal-testing/tiny-random-RobertaModel", "roformer": "hf-internal-testing/tiny-random-RoFormerModel", + "rtdetr": "PekingU/rtdetr_r18vd", "sam": "fxmarty/sam-vit-tiny-random", "segformer": "hf-internal-testing/tiny-random-SegformerModel", "splinter": "hf-internal-testing/tiny-random-SplinterModel", @@ -261,6 +262,7 @@ "resnet": "microsoft/resnet-50", "roberta": "roberta-base", "roformer": "junnyu/roformer_chinese_base", + "rtdetr": "PekingU/rtdetr_r18vd", "sam": "facebook/sam-vit-base", "segformer": "nvidia/segformer-b0-finetuned-ade-512-512", "splinter": "hf-internal-testing/tiny-random-SplinterModel", From 29d380c07ccf2f67f45b83ed15091b0ab6c6649b Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Tue, 17 Dec 2024 15:04:38 +0100 Subject: [PATCH 3/5] fix style --- optimum/exporters/onnx/model_configs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index 03e1d85912f..63b98152dd8 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -1941,8 +1941,7 @@ class SpeechT5OnnxConfig(OnnxSeq2SeqConfigWithPast): # so we won't support for now. NORMALIZED_CONFIG_CLASS = NormalizedSeq2SeqConfig.with_args( hidden_size="hidden_size", - num_attention_heads="encoder_attention_heads", - # TODO: bugged in case encoder and decoder have different number of heads + num_attention_heads="encoder_attention_heads", # TODO: bugged in case encoder and decoder have different number of heads encoder_num_layers="encoder_layers", decoder_num_layers="decoder_layers", allow_new=True, @@ -2487,4 +2486,4 @@ def inputs(self) -> Dict[str, Dict[int, str]]: return { "pixel_values": {0: "batch_size", 1: "num_channels", 2: "height", 3: "width"}, "pixel_mask": {0: "batch_size"}, - } \ No newline at end of file + } From 1f71fae6eece83c8962c7c1e22906b9882ad46b3 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Tue, 17 Dec 2024 15:06:28 +0100 Subject: [PATCH 4/5] Update tests large model --- tests/exporters/exporters_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/exporters/exporters_utils.py b/tests/exporters/exporters_utils.py index 222821850bd..bdbc73912c4 100644 --- a/tests/exporters/exporters_utils.py +++ b/tests/exporters/exporters_utils.py @@ -265,7 +265,7 @@ "resnet": "microsoft/resnet-50", "roberta": "roberta-base", "roformer": "junnyu/roformer_chinese_base", - "rtdetr": "PekingU/rtdetr_r18vd", + "rtdetr": "PekingU/rtdetr_r101vd", "sam": "facebook/sam-vit-base", "segformer": "nvidia/segformer-b0-finetuned-ade-512-512", "splinter": "hf-internal-testing/tiny-random-SplinterModel", From f25f2273e55cb1eb3d89a1a78d8c458fd3021800 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Tue, 17 Dec 2024 15:38:20 +0100 Subject: [PATCH 5/5] fix expected configs model type --- tests/exporters/exporters_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/exporters/exporters_utils.py b/tests/exporters/exporters_utils.py index bdbc73912c4..680ae7e91b8 100644 --- a/tests/exporters/exporters_utils.py +++ b/tests/exporters/exporters_utils.py @@ -145,7 +145,7 @@ "resnet": "hf-internal-testing/tiny-random-resnet", "roberta": "hf-internal-testing/tiny-random-RobertaModel", "roformer": "hf-internal-testing/tiny-random-RoFormerModel", - "rtdetr": "PekingU/rtdetr_r18vd", + "rt-detr": "PekingU/rtdetr_r18vd", "sam": "fxmarty/sam-vit-tiny-random", "segformer": "hf-internal-testing/tiny-random-SegformerModel", "splinter": "hf-internal-testing/tiny-random-SplinterModel", @@ -265,7 +265,7 @@ "resnet": "microsoft/resnet-50", "roberta": "roberta-base", "roformer": "junnyu/roformer_chinese_base", - "rtdetr": "PekingU/rtdetr_r101vd", + "rt-detr": "PekingU/rtdetr_r101vd", "sam": "facebook/sam-vit-base", "segformer": "nvidia/segformer-b0-finetuned-ade-512-512", "splinter": "hf-internal-testing/tiny-random-SplinterModel",