Repository navigation
Define TensorRT network with dynamic shapes - #36439
Merged
tensorflow-copybara merged 23 commits intoFeb 11, 2020
Merged
tensorflow-copybara merged 23 commits into
tensorflow-copybara merged 23 commits into
Conversation
bixia1
reviewed
Feb 7, 2020
tfeher
commented
Feb 10, 2020
bixia1
reviewed
Feb 10, 2020
tfeher
commented
Feb 11, 2020
bixia1
approved these changes
Feb 11, 2020
|
|
||
| #if IS_TRT_VERSION_GE(6, 0, 0, 0) | ||
| // For dynamic input shapes, we need to use TRT ops to build the new shape. | ||
| // If the remaining dimensions of squeeze operation have dynamic sizes, we |
Contributor
There was a problem hiding this comment.
Add "a" between "of" and "squeeze operation"
|
|
||
| // Array of all input shapes, collected from the input_shapes attribute when | ||
| // constructing the TRTEngineOp. The input_shapes attribute is set during | ||
| // graph conversion time. This data is used to retrive which input dimensions |
| return errors::InvalidArgument( | ||
| "Input tensor with shape ", shape.DebugString(), | ||
| " has an unknown non-batch dimension at dim ", d); | ||
| // Following checks are only used during TRT engine creation time. In implicit |
Contributor
There was a problem hiding this comment.
Following checks are only used during TRT engine creation time.
Do you mean this routine itself is called to validate tensors during TRT engine creation time? Can you move this sentence and make it a document for the routine?
tensorflow-copybara
pushed a commit
that referenced
this pull request
Feb 11, 2020
PiperOrigin-RevId: 294525798 Change-Id: Ied3dd9c188bef8f22dff1a6864615a5d59991d7a
tensorflow-copybara
pushed a commit
that referenced
this pull request
Feb 12, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds enables TRT network creation using dynamic shapes.
Dynamic shapes can be only used in the explicit batch mode (experimental). This PR only implements TensorRT network definition using dynamic shapes. To actually build the engine and run inference, one needs to specify optimization profiles. That is implemented in the next PR. Therefore TRT Engine creation is expected to fail if explicit batch mode is selected and the input tensors have unknown dimensions. This is tested in trt_engine_op_test.
This PR is not supposed to change any existing behavior: inference in implicit batch mode, or in explicit mode with known (static) shapes should still work as before.
Note
With the introduction of dynamic shapes, TF-TRT will have two different strategies to handle input with different shapes. (Confusingly the doc sometimes refers both as dynamic shapes). From the user point of view they are similar: the aim is to use TensorRT inference for inputs whose shape is unknown at the time when we call trt.convert().
The existing strategy is dynamic engine creation. It means that TensorRT engines can be created during runtime to handle different input shapes.
tensorflow/tensorflow/python/compiler/tensorrt/trt_convert.py
Lines 1210 to 1221 in 97b4c2c
tensorflow/tensorflow/python/compiler/tensorrt/trt_convert.py
Lines 136 to 142 in 97b4c2c
Dynamic engine creation is the only supported ongine creation in TF v2. See the relevant doc:
tensorflow/tensorflow/python/compiler/tensorrt/trt_convert.py
Lines 858 to 859 in 97b4c2c
This PR introduces dynamic input shapes (supported since TensorRT version 6), which is another way to deal with input data that has a shape not known at conversion time: we can define the TensorRT network with unknown input shapes. This way a single engine can handle input with different sizes. We still need to know the expected range of each input dimension (shape optimization profiles) at engine creation time.