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

[RT-Detr] - Add RT-Detr Onnx Config #2040

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,5 +2472,18 @@ def overwrite_shape_and_generate_input(

class EncoderDecoderOnnxConfig(EncoderDecoderBaseOnnxConfig):
NORMALIZED_CONFIG_CLASS = NormalizedEncoderDecoderConfig

DEFAULT_ONNX_OPSET = 14 # uses SDPA in Transformers, hence opset>=14.


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
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
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"},
Copy link
Collaborator

@echarlaix echarlaix Dec 18, 2024

Choose a reason for hiding this comment

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

why is it needed ? (not needed for ViT models but might be needed for RT-DETR)

Copy link
Collaborator

@echarlaix echarlaix Dec 18, 2024

Choose a reason for hiding this comment

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

also if needed shouldn't the height / width dimension set to dynamic as well?

}
4 changes: 4 additions & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,10 @@ class TasksManager:
onnx="RoFormerOnnxConfig",
tflite="RoFormerTFLiteConfig",
),
"rt-detr": supported_tasks_mapping(
"object-detection",
onnx="RTDetrOnnxConfig",
),
"sam": supported_tasks_mapping(
"feature-extraction",
onnx="SamOnnxConfig",
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -145,6 +145,7 @@
"resnet": "hf-internal-testing/tiny-random-resnet",
"roberta": "hf-internal-testing/tiny-random-RobertaModel",
"roformer": "hf-internal-testing/tiny-random-RoFormerModel",
"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",
Expand Down Expand Up @@ -264,6 +265,7 @@
"resnet": "microsoft/resnet-50",
"roberta": "roberta-base",
"roformer": "junnyu/roformer_chinese_base",
"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",
Expand Down
Loading