-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Add an attribute to disable custom kernels in deformable detr in order to make the model ONNX exportable #22918
Conversation
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this 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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
Thank you will update! |
@amyeroberts Let me know if this is better! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for iterating!
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>
There was a problem hiding this 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.
def __init__( | ||
self, embed_dim: int, num_heads: int, n_levels: int, n_points: int, disable_custom_kernels: bool = False | ||
): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully addressed in 4f3f041!
…com/fxmarty/transformers into fix-deformable-detr-for-onnx-export
There was a problem hiding this 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!
…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>
…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>
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.