Repository navigation
Execution context management for TensorRT profiles - #36664
Merged
tensorflow-copybara merged 12 commits intoFeb 21, 2020
Merged
tensorflow-copybara merged 12 commits into
tensorflow-copybara merged 12 commits into
Conversation
Contributor
|
@tfeher Can you please resolve conflicts? Thanks! |
Contributor
|
@tfeher Still, conflicts are appearing. Can you please resolve? Thanks! |
bixia1
reviewed
Feb 20, 2020
tfeher
commented
Feb 21, 2020
bixia1
requested changes
Feb 21, 2020
bixia1
left a comment
Contributor
There was a problem hiding this comment.
Please resolve conflicts.
bixia1
approved these changes
Feb 21, 2020
bixia1
left a comment
Contributor
There was a problem hiding this comment.
Approved it for further testing.
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 adds a mechanism to handle multiple execution context for a TensorRT engine, which is a step towards enabling dynamic shape mode with multiple profiles.
This PR is not expected to change any existing behavior: inference in implicit batch mode, in explicit batch and in dynamic shapes mode remains the same.
What changes is the engine lookup. Until now the EngineContext object contained a reference to a singe ICudaEngine and a corresponding IExecutionContext. We plan to have one execution context for each profile, therefore we introduce a vector of IExecutionContexts in EngineContext.
Correspondingly the GetEngine function changes: it does not only return the pointer to the EngineContext but also gives the indexd of the IExecutionContext that can be used for inference.
An alternative method for handling multiple profiles would be to keep a single IExecutionContext, and switch profile before we enqueue the new inference task. This could lead to problems with asynchronous inference, because we would need to ensure there are "no enqueued operations pending in the context prior to switching profiles".
Dynamic shape mode is an experimental feature. The advantage of dynamic shapes is that we can use a single engine with multiple profiles to handle input data with different shapes. This saves memory: all input profiles for an engine can share the same weights. Input dimensions that do not influence the number of model parameters can be dynamic (batch size, sequence length, even image dimensions for fully convolutional networks). A single profile can handle a range of input parameters, or we could have multiple profiles each optimized for a certain input shape (e.g. one profile for each expected batch size).
Although this PR implements the mechanism to handle multiple profiles and the corresponding execution contexts, one still needs a method to define these profiles. Such profile generation feature is implemented in PR #36729.