Skip to content

TF-TRT Dynamic Shapes Feature Tracker #45481

Closed

Description

@tfeher

Introduction

The dynamic shape mode in TF-TRT utilizes TensorRT’s dynamic shape feature to improve the conversion rate of networks and handle networks with unknown input shapes efficiently. This issue tracks the ongoing development to enable TRT's dynamic shape mode trough TF-TRT.

Who will benefit with this feature?
The conversion rate and therefore the performance will improve for the following inference problems:

  • Network with unknown input shapes (e.g. fully convolutional object detection networks)
  • Networks where the first (batch) dimension of a tensor changes within the graph (e.g. BERT)
  • Networks that have subgraphs where the tensors have non identical first dimension

Additionally the memory usage will improve: to handle input tensors with different shapes (eg image size, sequence length) currently requires separate TRT engine creation for each input. With dynamic shape mode a single engine can handle various input shapes.

Will this change the current api? How?

Some change in the conversion parameters will be necessary to enable/disable dynamic shape mode and provide a way to select optimization profiles.

Phase 1

The first phase of this work is the basic scaffolding to enable the TF-TRT converter to use TRT's dynami shape API.

  1. Add implicit batch experimental Add implicit batch experimental #34293
  2. Enable explicit batch mode Enable TF-TRT explicit batch mode #36379
  3. Improve binding index query Improve TensorRT binding index query #36434
  4. Add binding size specification Add TensorRT binding size dimension specification #36435
  5. Define networks with dynamic shapes Define TensorRT network with dynamic shapes #36439
  6. Add optimizaton profiles Add TensorRT optimization profiles #36660
  7. Execution context managment Execution context management for TensorRT profiles #36664
  8. TensorRT profile generation mode TensorRT profile generation mode #36729

Phase 2

Enable dynamic shape mode for ops used in MobileNet, ResNet, Bert. This includes improvement in the converters plus increasing their unit test coverage. Note that at this stage dynamic shape mode is still experimental.

Phase 3

This is a direct continuation of Phase 2. Ensure that all op converter support dynamic shape mode and test it. We have almost 20 converters to update and test. The bulk of this work is improving the test coverage.

Phase 3+

Some converters in phase 3 were updated only for explicit batch support with static shape. Enable dynamic shape mode for them:

Additionally:

Phase 4

Implement calibration in dynamic shape mode. Using TRT 7.1 one can run calibration in dynamic shape mode.

  • TRTEngineOp: allow profile collection before calibration
  • Refine APIs: build mode + calibration + lazy calibration

Phase 5

Test performance of dynamic shape mode

Phase 6

Define API to enable dynamic shape and specify optimization profiles.

Phase 7

  • C++ conversion API TF-TRT C++ conversion #52012
    Optional elements from Phase 6 are moved here.
  • Implement UserDefined profile
  • Change default conversion param from implicit batch mode to dynamic shape mode

Tagging @DEKHTIARJonathan and @bixia1

Activity

  1. added a commit that references this issue on Jan 14, 2021
  2. DrXuQian commented on Jul 8, 2021

    @DrXuQian

    Hi tfeher, About 'Networks where the first (batch) dimension of a tensor changes within the graph (e.g. BERT)'.
    Why would the first dimension change within the graph? I would assume that once the batch size is determined, the shape won't change throughout graph of BERT.

  3. tfeher commented on Jul 9, 2021

    @tfeher
    ContributorAuthor

    Why would the first dimension change within the graph?

    Some networks do reshape operations that change the first dim. It is done internally to express some operations more conveniently, the output is usually reshaped again to have the expected batch size. An example is BERT TF1 model.

    The dynamic shape feature of TF-TRT improves the TRT conversion of such networks.

  4. jiweibo commented on Jul 29, 2021

    @jiweibo

    Hi, @tfeher can tf-trt dynamic_batch support the situation of being divided into multiple trt subgraphs now?
    And how should we set the shape information of the min, max, and opt of the internal subgraph?

    image

  5. tfeher commented on Jul 29, 2021

    @tfeher
    ContributorAuthor

    can tf-trt dynamic_batch support the situation of being divided into multiple trt subgraphs now?

    Yes, dynamic shape mode supports graphs that have multiple TRT subgraphs. There is a known issue tensorflow/tensorrt#251, which occurs if the trt_engine_op is trying to output shape tensors. Otherwise it should work.

    And how should we set the shape information of the min, max, and opt of the internal subgraph?

    You only need to set the shape information for the inputs of the model. From these we calculate the size of any tensor in the graph, and set input shape information for the internal TRT subgraphs (trt_engine_ops).

  6. christopherbate commented on Aug 12, 2021

    @christopherbate
    Contributor

    PR for Conv2dBackpropInput #51468

  7. tilakrayal commented on Aug 20, 2024

    @tilakrayal
    Contributor

    Hi,

    Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base.

    Also the PR's which were raised got merged and the changes are reflected.
    #55166

    The Tensorflow team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TensorFlow version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate.

    Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow space.

  8. github-actions commented on Aug 28, 2024

    @github-actions

    This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

  9. added
    staleThis label marks the issue/pr stale - to be closed automatically if no activity
    on Aug 28, 2024
  10. github-actions commented on Sep 4, 2024

    @github-actions

    This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp:gpu:tensorrtIssues specific to TensorRTstaleThis label marks the issue/pr stale - to be closed automatically if no activitystat:awaiting responseStatus - Awaiting response from authortype:featureFeature requests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions