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: Implement symbolic shape propagation, sym_size converter #2473

Merged
merged 49 commits into from
Apr 11, 2024

Conversation

peri044
Copy link
Collaborator

@peri044 peri044 commented Nov 16, 2023

Description

This PR replaces our old shape propagation system which relied on dummy runs of inputs. If the inputs were dynamic, we used to run dummy inference on min, opt, max shapes to capture output shapes/dtypes.

For data-dependant shapes (with static input), our shape propagation system might not work and would give incorrect info about subgraph input shapes. This PR uses symbolic shape propagation from PyTorch.

Eg:

class DDS(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, mask):
        return x[mask]

model = DDS().eval().cuda()
x = torch.randn(1, 3, 4, 4).cuda()
y = torch.rand((1, 3, 4, 4), device="cuda") < 0.9

trt_model = torch_tensorrt.compile(model, inputs=[x, y], 
                                    ir="dynamo",
                                    min_block_size=1, 
                                    debug=True)

Example 2:

class Sample(torch.nn.Module):
    def __init__(self):
        super(Sample, self).__init__()

    def forward(self, x):
        input_shape = x.size()
        y = x.view(input_shape[0], -1)
        return y

RFC : #2409

Type of change

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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 Nov 16, 2023
@github-actions github-actions bot requested a review from apbose November 16, 2023 08:49
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

github-actions[bot]

This comment was marked as resolved.

@peri044 peri044 removed the request for review from apbose November 16, 2023 16:33
Signed-off-by: Dheeraj Peri <[email protected]>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

github-actions[bot]

This comment was marked as resolved.

Signed-off-by: Dheeraj Peri <[email protected]>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Signed-off-by: Dheeraj Peri <[email protected]>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@peri044 peri044 changed the base branch from main to save March 15, 2024 23:33
@peri044 peri044 force-pushed the save branch 4 times, most recently from 8980b7a to 982dbd2 Compare March 26, 2024 01:57
@github-actions github-actions bot added documentation Improvements or additions to documentation component: core Issues re: The core compiler component: runtime labels Apr 2, 2024
@peri044 peri044 changed the base branch from save to release/2.3 April 2, 2024 12:23
@github-actions github-actions bot removed documentation Improvements or additions to documentation component: core Issues re: The core compiler component: runtime labels Apr 2, 2024
@peri044 peri044 merged commit c5d6e16 into release/2.3 Apr 11, 2024
20 of 21 checks passed
peri044 added a commit that referenced this pull request Apr 16, 2024
zewenli98 pushed a commit that referenced this pull request Apr 26, 2024
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: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests component: torch_compile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants