TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

feat: Implement symbolic shape propagation, sym_size converter

Open peri044 opened this issue 2 years ago • 0 comments

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 : https://github.com/pytorch/TensorRT/discussions/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

peri044 avatar Nov 16 '23 08:11 peri044