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

Add CvTONNX Config #1131

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion optimum/bettertransformer/models/encoder_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

This seems pretty high tbh, do you have any idea which op makes it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you talking about the tolerance or the opset version? Im not sure why lower tolerance doesn't work, but einsum causes an error for lower opset versions

Copy link
Member

Choose a reason for hiding this comment

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

I am talking about the tolerance, we might have a hidden bug if we need 1e-2, or we might not, but just wanted to raise the potential issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any way this can be checked?



class LevitOnnxConfig(ViTOnnxConfig):
pass

Expand Down
1 change: 1 addition & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ class TasksManager:
"image-classification",
onnx="ConvNextOnnxConfig",
),
"cvt": supported_tasks_mapping("feature-extraction", "image-classification", onnx="CvTOnnxConfig"),
"data2vec-text": supported_tasks_mapping(
"feature-extraction",
"fill-mask",
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 @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down