-
Notifications
You must be signed in to change notification settings - Fork 364
feat: dynamic shape support for pow/mod/eq operator #2982
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2002,6 +2002,7 @@ def aten_ops_div( | |
@dynamo_tensorrt_converter( | ||
torch.ops.aten.pow.Tensor_Scalar, supports_dynamic_shapes=True | ||
) | ||
@dynamo_tensorrt_converter(operator.pow, supports_dynamic_shapes=True) | ||
def aten_ops_pow( | ||
ctx: ConversionContext, | ||
target: Target, | ||
|
@@ -2278,6 +2279,7 @@ def aten_ops_bitwise_not( | |
|
||
@dynamo_tensorrt_converter(torch.ops.aten.eq.Tensor, supports_dynamic_shapes=True) | ||
@dynamo_tensorrt_converter(torch.ops.aten.eq.Scalar, supports_dynamic_shapes=True) | ||
@dynamo_tensorrt_converter(operator.eq, supports_dynamic_shapes=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
@enforce_tensor_types( | ||
{ | ||
0: (TRTTensor,), | ||
|
@@ -3149,8 +3151,13 @@ def aten_ops_copy( | |
) | ||
|
||
|
||
@dynamo_tensorrt_converter(torch.ops.aten.remainder.Scalar) | ||
@dynamo_tensorrt_converter(torch.ops.aten.remainder.Tensor) | ||
@dynamo_tensorrt_converter( | ||
torch.ops.aten.remainder.Scalar, supports_dynamic_shapes=True | ||
) | ||
@dynamo_tensorrt_converter( | ||
torch.ops.aten.remainder.Tensor, supports_dynamic_shapes=True | ||
) | ||
@dynamo_tensorrt_converter(operator.mod, supports_dynamic_shapes=True) | ||
@enforce_tensor_types( | ||
{ | ||
0: (TRTTensor,), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
From the PR (#2918), it looks like dynamic testing and registration for
operator.mul
were added because PyTorch internally usesoperator.mul
when usingtorch.nn.Linear
layers. This might be whyoperator.mul
was registered with the converter.If I'm misunderstanding, could you please explain? (cc. @peri044 )
Then, in this PR, why do we need to register
operator.pow
,operator.eq
, andoperator.mod
with the converter?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.
It seems
operator.*
overrides original Python ops, which results in running any Python op will create a TRT Layer to handle it. However, they are not listed in the schema. I'm also curious if these ops' converters are neededThere 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 @chohk88 / @zewenli98
If operator.pow is missing and ** is used in module, there is exception from TRTInterpreter.
E torch_tensorrt.dynamo.conversion._TRTInterpreter.UnsupportedOperatorException: Conversion of function _operator.pow not currently supported!
I saw such usage of operator in openchat model. I think we need to register these operators to support such usage.
https://github.com/imoneoi/openchat/blob/master/ochat/models/unpadded_llama.py#L105
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 the example. If then, it seems to be necessary I think.
cc: @narendasan @dheerajperi
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.
Yes, openchat model uses operator.pow and there's one other model too I think. We need them to be registered as converters similar to other operator.* variants we have.
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 the example. LGTM!