8000 feat: dynamic shape support for pow/mod/eq operator by keehyuna · Pull Request #2982 · pytorch/TensorRT · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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 3 commits into from
Jul 9, 2024

Conversation

keehyuna
Copy link
Collaborator
@keehyuna keehyuna commented Jul 3, 2024

Description

dynamic shape support for pow/mod/eq operator
Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@keehyuna keehyuna self-assigned this Jul 3, 2024
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jul 3, 2024
@keehyuna keehyuna requested a review from chohk88 July 3, 2024 07:46
@github-actions github-actions bot requested a review from gs-olive July 3, 2024 07:46
@keehyuna keehyuna requested review from peri044 and zewenli98 July 3, 2024 07:46
@@ -2278,6 +2279,7 @@ def aten_ops_bitwise_not(

@dynamo_tensorrt_converter(torch.ops.aten.eq.Tensor)
@dynamo_tensorrt_converter(torch.ops.aten.eq.Scalar)
@dynamo_tensorrt_converter(operator.eq, supports_dynamic_shapes=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -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)
Copy link
Collaborator

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 uses operator.mul when using torch.nn.Linear layers. This might be why operator.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, and operator.mod with the converter?

Copy link
Collaborator

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 needed

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator

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!

Copy link
Collaborator
@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Added a question

@@ -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)
Copy link
Collaborator

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.

@keehyuna keehyuna force-pushed the operator_dynamic_shape branch from 5ee1e50 to bf65839 Compare July 9, 2024 01:26
@peri044 peri044 merged commit 077e46d into pytorch:main Jul 9, 2024
55 of 61 checks passed
cehongwang added a commit that referenced this pull request Jul 12, 2024
cehongwang added a commit that referenced this pull request Jul 12, 2024
@keehyuna keehyuna deleted the operator_dynamic_shape branch August 19, 2024 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0