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 an attribute to disable custom kernels in deformable detr in order to make the model ONNX exportable #22918

Merged
merged 10 commits into from
Apr 24, 2023

Conversation

fxmarty
Copy link
Contributor

@fxmarty fxmarty commented Apr 21, 2023

As per title and reported in #22330 and huggingface/optimum#931

This option will allow us to patch the model on the fly during the export to avoid going into the try/catch logic that is not supported by PyTorch ONNX export.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 21, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! This should be a config attribute instead of a model attribute. This way your comments in the code about ONNX become a docstring there.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for adding this update!

@@ -520,6 +520,10 @@ def __init__(self, embed_dim: int, num_heads: int, n_levels: int, n_points: int)
self.value_proj = nn.Linear(embed_dim, embed_dim)
self.output_proj = nn.Linear(embed_dim, embed_dim)

# This option is necessary for the ONNX export, as the try/catch in the forward
# is not supported by PyTorch ONNX export
self.disable_custom_kernels = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd remove the # Copied from statement for this method, as the comment and additional parameter don't make sense here

@amyeroberts
Copy link
Collaborator

@fxmarty Following up on this, I agree with @sgugger's suggestion and think that a config argument would be a better alternative.

@fxmarty
Copy link
Contributor Author

fxmarty commented Apr 21, 2023

Thank you will update!

@fxmarty
Copy link
Contributor Author

fxmarty commented Apr 21, 2023

@amyeroberts Let me know if this is better!

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for iterating!

src/transformers/models/deta/modeling_deta.py Outdated Show resolved Hide resolved
src/transformers/models/deta/modeling_deta.py Outdated Show resolved Hide resolved
src/transformers/models/deta/modeling_deta.py Outdated Show resolved Hide resolved
fxmarty and others added 3 commits April 21, 2023 16:46
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for iterating! One last comment and we should be good to go.

Comment on lines 592 to 594
def __init__(
self, embed_dim: int, num_heads: int, n_levels: int, n_points: int, disable_custom_kernels: bool = False
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's pass the config here (I think you can also remove n_points from the args, which seems to always be config.num_feature_levels) and the read the flag from the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully addressed in 4f3f041!

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the additional cleanup!

@sgugger sgugger merged commit edb6d95 into huggingface:main Apr 24, 2023
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
…r to make the model ONNX exportable (huggingface#22918)

* add disable kernel option

* add comment

* fix copies

* add disable_custom_kernels to config

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* style

* fix

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
…r to make the model ONNX exportable (huggingface#22918)

* add disable kernel option

* add comment

* fix copies

* add disable_custom_kernels to config

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* style

* fix

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants