Skip to content

Adds support for serialization and deseralization for compiled TorchScript modules #74

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 17 commits into from
May 31, 2020

Conversation

narendasan
Copy link
Collaborator

@narendasan narendasan commented May 31, 2020

Description

Adds support for embedded TensorRT engines into TorchScript modules, allowing serialization and deserialization of compiled TorchScript modules. Also introduces trtorchc, a CLI for the compiler which can compile then serialize modules to load into Python or C++ via standard PyTorch APIs. Various code tweaks and fixing two operators which broke on dynamic input.

Closes #40

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
  • 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 and have regenerated the documentation (make html in docsrc)
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes

narendasan added 10 commits May 30, 2020 18:52
making generated TorchScript programs portable

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
will serve as a replacement to trtorchexec and act like a GCC style
compiler for TorchScript

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
deserializing modules in python

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
dynamic inputs

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
tensorrt internal custom classes

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
dynamic, to use in converters for handling it seperately

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
converter implementations

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
@narendasan narendasan marked this pull request as draft May 31, 2020 02:29
@narendasan narendasan added the component: execution Issues re: Execution of engines label May 31, 2020
@narendasan narendasan added this to the v0.1.0 milestone May 31, 2020
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
@narendasan narendasan marked this pull request as ready for review May 31, 2020 04:59
serialized TRTorch programs

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
about what is going on

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
@narendasan narendasan merged commit db20098 into master May 31, 2020
@narendasan narendasan deleted the seralization branch May 31, 2020 05:33
frank-wei pushed a commit that referenced this pull request Jun 4, 2022
…roperly (#74)

Summary:
Pull Request resolved: https://github.com/pytorch/fx2trt/pull/74

## Root cause
We have code like:

```
x = ...                             # result shape is [batch_size, N]
y = mean(y, dim=1, keepdim=False)   # result shape is [batch_size]
z = y + 0.5                         # result shape is [batch_size]
```

For TRT with implicit batch dimension it should look like:
```
x = ...                             # result shape is [N]
y = mean(y, dim=1, keepdim=False)   # result shape is []
z = y + 0.5                         # result shape is []
```
However, because we convert scalar to `TRTTensor` and don't do dimensions squeeze for it, the resulting tensor `z` would have shape `[1]`, and this is gonna break the rest of the net.

## Solution
Convert the scalar value to `torch.Tensor`, because we have dimensions squeeze logic implemented for them.

## P.S.:
Also added support for `sqrt` tracing.

Reviewed By: yinghai, houseroad

Differential Revision: D36336816

fbshipit-source-id: 412e44e99f25ab3549df540a87bd005e6b3fe08a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: execution Issues re: Execution of engines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create some sort of serialization / deserialization functionality
1 participant