Skip to content

TF-TRT Improve reshape op converter - #40545

Merged
copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
tfeher:trt_reshape_dynamic
Mar 10, 2021
Merged

copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
tfeher:trt_reshape_dynamic

Conversation

@tfeher

@tfeher tfeher commented Jun 17, 2020 •

Copy link
Copy Markdown
Contributor

This PR improves the Reshape op converter to handle explicit batch and dynamic shape input data.

Since TRT6, IShuffleLayer has an option to accept the shape parameter as an input tensor. If the shape input tensor corresponds to an input tensor of the TRTEngineOp, then we need to specify the input shape values for the engine. Additionally we need to specify optimization profile parameters for the shape values. The necessary changes were implemented in TrtShapeOptimizationProfile, TRTEngineOp, trt_engine_utils.

The unit tests have only a single op, and therefore handling shape input values are required to test
reshape with tensor input shape. In normal network it is less likely to have shape input tensors.

Additionally the handling of scalar input/output shapes are improved.

C++ test for serialization / deserialization of input shapes and shape values added.

Note: TensorRT has a function INetworkDefinition::markOutputForShapes which could enable the output tensor's value to be computed by IExecutionContext::getShapeBinding. This is not used in this PR, but it might be useful for shape inference.

@google-ml-butler google-ml-butler Bot added the size:XL CL Change Size:Extra Large label Jun 17, 2020
@google-ml-butler
google-ml-butler Bot requested a review from joker-eph June 17, 2020 12:59
@tfeher
tfeher marked this pull request as draft June 17, 2020 12:59
@gbaned gbaned self-assigned this Jun 17, 2020
@gbaned gbaned added the comp:gpu:tensorrt Issues specific to TensorRT label Jun 17, 2020
@tfeher
tfeher force-pushed the trt_reshape_dynamic branch from 318b5c4 to 8f64eab Compare June 19, 2020 16:34
@gbaned

gbaned commented Jul 14, 2020

Copy link
Copy Markdown
Contributor

@tfeher This PR is in draft, any update on this? Please. Thanks!

@tfeher

tfeher commented Jul 20, 2020

Copy link
Copy Markdown
Contributor Author

I am working on an update that would enable the missing python test for this feature. It shall be ready by next week.

@gbaned

gbaned commented Aug 13, 2020

Copy link
Copy Markdown
Contributor

@tfeher This PR is in draft, any update on this? Please. Thanks!

@tfeher
tfeher force-pushed the trt_reshape_dynamic branch 2 times, most recently from 35f68f2 to f6f0f81 Compare August 26, 2020 11:40
@tfeher
tfeher marked this pull request as ready for review August 26, 2020 11:42
@tfeher

tfeher commented Aug 26, 2020

Copy link
Copy Markdown
Contributor Author

I have updated the PR, it is ready for review.

@gbaned
gbaned requested review from bixia1 and removed request for bixia1 September 1, 2020 17:11
@gbaned gbaned added the awaiting review Pull request awaiting review label Sep 1, 2020
@gbaned gbaned added stat:awaiting response Status - Awaiting response from author and removed awaiting review Pull request awaiting review labels Sep 11, 2020
@gbaned

gbaned commented Sep 15, 2020

Copy link
Copy Markdown
Contributor

@tfeher Can you please check @bixia1's comments and keep us posted ? Thanks!

@gbaned

gbaned commented Sep 23, 2020

Copy link
Copy Markdown
Contributor

@tfeher Any update on this PR? Please. Thanks!

@tfeher

tfeher commented Sep 23, 2020

Copy link
Copy Markdown
Contributor Author

There is an issue with the converter using TRT 7.1.3. I am working on a fix.

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Sep 25, 2020
@gbaned gbaned added the stat:awaiting response Status - Awaiting response from author label Sep 25, 2020
@gbaned

gbaned commented Oct 9, 2020

Copy link
Copy Markdown
Contributor

@tfeher Any update on this PR? and please resolve conflicts Thanks!

@tfeher

tfeher commented Oct 15, 2020

Copy link
Copy Markdown
Contributor Author

The unit test of the converter fails in explicit batch mode with TRT 7.1.3 due to a bug in TRT. Waiting for feedback from the TRT team.

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Oct 17, 2020
@google-ml-butler google-ml-butler Bot added the ready to pull PR ready for merge process label Mar 8, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 8, 2021
@bixia1

bixia1 commented Mar 8, 2021

Copy link
Copy Markdown
Contributor

I got three tests failed:
(1) tensorflow/python/compiler/tensorrt:gpu_combined_nms_test. message is like
File "/build/work/fe0e3a7166e31378da05c1404a4fcd4fedb1/google3/runfiles/google3/third_party/tensorflow/python/compiler/tensorrt/test/tf_trt_integration_test_base.py", line 1107, in _Test
self.RunTest(run_params)
File "/build/work/fe0e3a7166e31378da05c1404a4fcd4fedb1/google3/runfiles/google3/third_party/tensorflow/python/compiler/tensorrt/test/tf_trt_integration_test_base.py", line 1030, in RunTest
GraphState.INFERENCE)
File "/build/work/fe0e3a7166e31378da05c1404a4fcd4fedb1/google3/runfiles/google3/third_party/tensorflow/python/compiler/tensorrt/test/tf_trt_integration_test_base.py", line 907, in _VerifyGraphDef
graph_state)
File "/build/work/fe0e3a7166e31378da05c1404a4fcd4fedb1/google3/runfiles/google3/third_party/tensorflow/python/compiler/tensorrt/test/tf_trt_integration_test_base.py", line 893, in _VerifyGraphDefV2
[name for name in unexpected_names if name in all_op_names])
AssertionError: ['score_threshold', 'max_output_size_per_class', 'iou_threshold', 'max_total_size'] has length of 4.
(2) tensorflow/python/compiler/tensorrt:gpu_neighboring_engine_test
and tensorflow/python/compiler/tensorrt:gpu_multi_connection_neighbor_engine_test
they both failed because of native segment execution happened,
(0) Aborted: User disallowed engine native segment execution
[[{{node TRTEngineOp_0_1}}]]

@bixia1

bixia1 commented Mar 8, 2021

Copy link
Copy Markdown
Contributor

tensorflow/compiler/tf2tensorrt:convert_nodes_test_gpu also failed
test.log

@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Mar 8, 2021

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @bixia1 for the review. I have corrected the smaller issues. I am looking into the python test problems.

The C++ test seem to have a problem with ConvertConv3D. I could not reproduce that wint TRT 7.2.1, but I will have a look with other versions.

There seem to be an additional issue with shape value handling in TRT6. I will investigate, and disable conversion in the affected versions.

@tfeher

tfeher commented Mar 8, 2021

Copy link
Copy Markdown
Contributor Author
  • I have disabled ConvertDynamicReshape before TRT 7.1.3, this way the reshape unit test works in all TRT versions that I have tested (5.1.5, 6.0.1, 7.1.3 and 7.2.1).
  • I could not reproduce the Conv3D test with TRT 7.1.3.4.
  • I confirm the problems with the two neighbor engine tests. I will continue to investigate those.

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per offline conversation, approving this for testing inside google while Tamas is still working on the python tests.

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 9, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 9, 2021
@bixia1

bixia1 commented Mar 9, 2021

Copy link
Copy Markdown
Contributor

I found the reason for the Conv3D failure. This line of code is accessing garbage value when c_index == 4, and for implicit batch mode.
In case you need a test to verify it, here is one.
The problem is actually not introduced by this PR, but this one.

@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Mar 9, 2021
@tfeher

tfeher commented Mar 9, 2021

Copy link
Copy Markdown
Contributor Author

Thanks @bixia1 for looking into the Conv3D failure, I will add a fix in this PR.

The last commit seems to solve the problem with the with the two neighbor engine tests. There is still an issue with the combined_nms_test.py, I am looking into that.

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving this so that I can get it to google and test it while Tamas is still working on one failing test.

Comment thread tensorflow/compiler/tf2tensorrt/BUILD Resolved
@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 9, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 9, 2021
- Add profile management for shape input tensors

- Allow scalars for TRT6 or above

- Improve engine serialization test. Additionally improve shape value
  handling. Adapt to Shape IO API change in TRT 7.1.3.

- Disable ConvertDynamicReshape befor TRT 7.1.3

- Fix Conv3D channel index in implicit batch mode

- Update CombinedNMS scalar value check
@tfeher
tfeher force-pushed the trt_reshape_dynamic branch from 23dd7c8 to 47ef8f0 Compare March 9, 2021 22:29
@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Mar 9, 2021

@tfeher tfeher left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The NMS Python test error was caused by a change in how scalars are represented in this PR. I have updated the converter, the test passes now.

I have also fixed the two smaller issues.

Comment thread tensorflow/compiler/tf2tensorrt/BUILD Resolved
@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 9, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 9, 2021
@copybara-service
copybara-service Bot merged commit ce9f460 into tensorflow:master Mar 10, 2021
@tfeher
tfeher deleted the trt_reshape_dynamic branch May 16, 2022 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes comp:gpu:tensorrt Issues specific to TensorRT ready to pull PR ready for merge process size:XL CL Change Size:Extra Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants