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

feat: support 1D, 2D, and 3D avg and max pooling dynamo converters #2317

Merged
merged 4 commits into from
Sep 29, 2023

Conversation

zewenli98
Copy link
Collaborator

Description

Support 1D, 2D, and 3D avg and max pooling dynamo converters.

Fixes #2200

Type of change

  • 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

@github-actions github-actions bot added component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests labels Sep 12, 2023
@zewenli98 zewenli98 self-assigned this Sep 19, 2023
Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

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

Left a few code comments, otherwise looks good to me

Comment on lines 41 to 43
if stride is None:
stride = kernel_size
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

By the function documentation and the schema, it should not be allowed for stride to be None, so this can be removed

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 for pointing it out! According to the schema, the stride could be [] by default, so I made changes accordingly.

@@ -0,0 +1,106 @@
from typing import Optional, Sequence, Union

# @manual=//deeplearning/trt/python:py_tensorrt
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed

from torch.fx.node import Target
from torch_tensorrt.dynamo.conversion.converter_utils import extend_attr_to_tuple
from torch_tensorrt.fx.converters.converter_utils import (
SourceIR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Switch to using the torch_tensorrt.dynamo version of SourceIR

Comment on lines 88 to 90
if stride is None:
stride = kernel_size
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above comment (can remove)



# Note: MaxPool1d uses max_pool2d as it converts to 2D first.
@dynamo_tensorrt_converter(torch.ops.aten.max_pool2d.default, capability_validator=max_pool_param_validator) # type: ignore[misc]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could max_pool1d support be added here as well? Schema

Copy link
Collaborator Author

@zewenli98 zewenli98 Sep 28, 2023

Choose a reason for hiding this comment

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

I can add torch.ops.aten.max_pool1d.default but it won't be used. Even for torch.nn.AvgPool1d, it still calls torch.ops.aten.avg_pool2d.default, as you can see in the test file: https://github.com/pytorch/TensorRT/pull/2317/files#diff-9fce39bc42c66d2866c41665779cab7da0a4d3fe54576925e2b66c17a1cf1ebfR20-R43
But anyways, the 1d schema looks same as others, so I added here.

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 that - I plan to add a lowering pass which will lead us to that converter, so it will still be helpful.

Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

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

Looks good to me, pending CI!

@gs-olive gs-olive merged commit 891c2ef into pytorch:main Sep 29, 2023
17 of 19 checks passed
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: converters Issues re: Specific op converters 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.

Exposing IPoolingLayer in dynamo.conversion.impl
4 participants