[PyTorch] Reduce CPU overheads#2377
Merged
Merged
Conversation
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Contributor
Greptile Summary
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Linear/GroupedLinear
participant AutogradFunction
participant general_gemm
participant CUDAGuard
participant cuBLAS/cuDNN
User->>Linear/GroupedLinear: forward(input)
Linear/GroupedLinear->>Linear/GroupedLinear: Cache torch.is_grad_enabled()
Linear/GroupedLinear->>Linear/GroupedLinear: Consolidate args into non_tensor_args tuple
Linear/GroupedLinear->>AutogradFunction: forward(tensors, non_tensor_args)
AutogradFunction->>general_gemm: gemm(A, B, quantization_params)
general_gemm->>general_gemm: get_cublas_workspace(device, ub, grouped)
general_gemm->>CUDAGuard: Set correct device context
CUDAGuard->>cuBLAS/cuDNN: Execute GEMM with correct device
cuBLAS/cuDNN-->>general_gemm: output
general_gemm-->>AutogradFunction: result
AutogradFunction-->>Linear/GroupedLinear: output
Linear/GroupedLinear-->>User: result
|
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Collaborator
|
Reviewed with Kirthi Offline. Looks good to me. LGTM. |
vthumbe1503
approved these changes
Nov 14, 2025
vthumbe1503
reviewed
Nov 15, 2025
| if ub: | ||
| return torch.empty( | ||
| get_cublas_workspace_size_bytes(), dtype=torch.uint8, device=device | ||
| ).repeat(_NUM_MAX_UB_STREAMS) |
Collaborator
There was a problem hiding this comment.
Just a minor further optimization, can be done in later PR as well. Instead of calling empty and then calling a repeat again which means there are 2 torch operations.Directly you can call
torch.empty(
get_cublas_workspace_size_bytes() * _NUM_MAX_UB_STREAMS, dtype=torch.uint8,device=device)
Member
Author
|
/te-ci |
Contributor
There was a problem hiding this comment.
27 files reviewed, no comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
This was referenced Nov 19, 2025
KshitijLakhani
pushed a commit
that referenced
this pull request
Nov 20, 2025
Initial changes to remove pytorch overheads Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
timmoon10
referenced
this pull request
in NVIDIA-NeMo/RL
May 4, 2026
Signed-off-by: Anna Shors <ashors@nvidia.com>
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.
Description
Based on single GPU profiling of the
GroupedLinearmodule, implement some optimizations in order to reduce CPU overhead due to PyTorch.Type of change
Changes
unwrap_dead_wrappers.torch.cuda.devicecontext manager to C++.torch.is_grad_enabledand misc other torch calls.copyimplementations in order to avoidcopy.copy().Checklist: