-
Notifications
You must be signed in to change notification settings - Fork 350
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
Conversation
This PR introduces type propagation infrastructure through pytorch inference. Inferred output types are used to set the TensorRT engines output types.
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
There was a problem hiding this 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++])); |
There was a problem hiding this comment.
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)
There was a problem hiding this 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)
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.
Checklist: