Skip to content
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: Cudagraphs integration for Torch-TRT + Non-default Stream Utilization #2881

Merged
merged 9 commits into from
Jul 9, 2024

Conversation

gs-olive
Copy link
Collaborator

@gs-olive gs-olive commented Jun 3, 2024

Description

  • Add option to enable Cudagraphs in the runtime for additional acceleration of TRT engines
  • Add C++ and Python toggles and well as full integration for C++ and Python runtimes
  • Add support for dynamic shape cases via shape keys with cache invalidation
  • Add test cases for cudagraphs support
  • Add support for non-default CUDA Stream usage by default

Addresses #2736

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • [ x ] My code follows the style guidelines of this project (You can use the linters)
  • [ x ] I have performed a self-review of my own code
  • [ x ] I have commented my code, particularly in hard-to-understand areas and hacks
  • [ x ] I have made corresponding changes to the documentation
  • [ x ] I have added tests to verify my fix or my feature
  • [ x ] New and existing unit tests pass locally with my changes
  • [ x ] I have added the relevant labels to my PR in so that relevant reviewers are notified

@gs-olive gs-olive requested a review from narendasan June 3, 2024 16:40
@gs-olive gs-olive self-assigned this Jun 3, 2024
@github-actions github-actions bot added documentation Improvements or additions to documentation component: tests Issues re: Tests component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: runtime component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jun 3, 2024
@github-actions github-actions bot requested a review from peri044 June 3, 2024 16:41
@@ -168,27 +210,66 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> inputs, c10::intr
auto dims = core::util::toVec(out_shape);
auto type = util::TRTDataTypeToScalarType(compiled_engine->exec_ctx->getEngine().getTensorDataType(name.c_str()));
outputs[pyt_idx] = std::move(at::empty(dims, {at::kCUDA}).to(type).contiguous());

// In cudagraphs mode, the allocated output buffers are stored for reuse
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a downside to always using the buffers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also what is the required lifetime of these buffers, can they be deallocated at any point or do they need to be reserved as long as the cuda graph is active?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If not in cudagraphs mode, the main downside is the requirement that buffers need to change size/be reallocated in Dynamic shape usecases.

My understanding is that these I/O buffers need to be reserved for the duration of the cudagraph being active

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM

@gs-olive gs-olive changed the title feat: Cudagraphs integration for Torch-TRT feat: Cudagraphs integration for Torch-TRT + Non-default Stream Utilization Jun 28, 2024
@github-actions github-actions bot added the component: build system Issues re: Build system label Jun 28, 2024
Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM, pending rebase

Copy link
Collaborator

@zewenli98 zewenli98 left a comment

Choose a reason for hiding this comment

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

LGTM

- Add option to enable Cudagraphs in the runtime for additional
acceleration of TRT engines
- Add C++ and Python toggles and well as full integration for C++ and
Python runtimes
- Add support for dynamic shape cases via shape keys with cache
invalidation
- Add test cases for cudagraphs support
- Add support for non-default streams
@narendasan narendasan merged commit 3f8fff7 into pytorch:main Jul 9, 2024
53 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: build system Issues re: Build system component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: runtime component: tests Issues re: Tests documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants