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: introduce type propagation infrastructure #2469

Closed
wants to merge 2 commits into from

Conversation

bowang007
Copy link
Collaborator

@bowang007 bowang007 commented Nov 15, 2023

Description

This PR introduces type propagation infrastructure through pytorch inference.
Inferred output types are used to set the TensorRT engines output types.

Related PR: #1853

Previous solution has several limitations.

  • Bug fix
  • New feature

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

This PR introduces type propagation infrastructure through pytorch inference.
Inferred output types are used to set the TensorRT engines output types.
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

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

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

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

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

@@ -340,6 +340,19 @@ void getSegmentsOutputByRunning(

seg_block.register_inshapes(input_shapes, shape_mode);
seg_block.register_intypes(input_types);

// get output type for each segmented block so this can be used in conversion process
std::vector<at::ScalarType> output_types;
Copy link
Contributor

@mfeliz-cruise mfeliz-cruise Nov 15, 2023

Choose a reason for hiding this comment

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

One thing to check: Because we're running this at the end of shape propagation does this work for fully convertible modules?

From memory I think that shape prop is only called from BuildHybridGraph->partition() which I don't think is called if all ops are convertible.

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

@@ -265,6 +269,7 @@ void MarkOutputs(ConversionCtx* ctx, at::ArrayRef<const torch::jit::Value*> outp
}

if (!setOutput) {
out_tensor->setType(util::ScalarTypeToTRTDataType(out_types[out_idx++]));
Copy link
Contributor

Choose a reason for hiding this comment

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

The out_idx needs to be incremented even if one of the outputs is an input (see where setOutput may be set above)

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.

Overall, looks good, just needs a few small fixes. Needs a test case for verification. Additionally, it seems some of the Torchscript test cases are failing due to this change:

ERROR conda.cli.main_run:execute(41): `conda run python -m pytest --junitxml=/tmp/test_results/ts_api_test_results.xml api/` failed. (See above for error)
Fatal Python error: Segmentation fault

Current thread 0x00007f4711145740 (most recent call first):
  File "/opt/python/cp38-cp38/lib/python3.8/site-packages/torch_tensorrt/ts/_compiler.py", line 266 in convert_method_to_trt_engine
  File "/__w/TensorRT/TensorRT/pytorch/tensorrt/tests/py/ts/api/test_classes.py", line 300 in test_detect_invalid_input_binding

This may be due to the reason in the comment above #2469 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: partitioning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants