Skip to content

[PyTorch] Isolate GroupedTensor GEMM workspaces by invocation - #4004

Open
Vtmpas wants to merge 3 commits into
NVIDIA:mainfrom
Vtmpas:fix/grouped-tensor-workspace
Open

Vtmpas wants to merge 3 commits into
NVIDIA:mainfrom
Vtmpas:fix/grouped-tensor-workspace

Conversation

@Vtmpas

@Vtmpas Vtmpas commented Dec 3, 2026

Copy link
Copy Markdown

Two overlapping PyTorch GroupedTensor GEMMs can write the same setup arrays and use the same cuBLASLt scratch. The caches are keyed by device and group count or layout, so they also alias across independent CUDA graph captures. Fixes #3963.

Allocate both mutable buffers for each invocation on the caller's CUDA stream. PyTorch orders eager reuse on that stream and keeps captured storage in the graph pool. For cuBLASLt versions before 13.8, clear the 32 MiB scratch before every launch to guard against the stale descriptors seen on mixed-layout replay in #3171.

  • Compare concurrent TN, NN, NT and NN→NT calls to serial execution. Capture two independent graphs on the same stream and replay them on separate streams. Check both workspace addresses and the numerical outputs.
  • Replay the existing FP8 block-scaling training graph twice. Drop leaf gradient references between replays so the test cannot overwrite graph-owned gradients.

Pre-commit passed. On H200 with cuBLASLt 13.5.1, the allocation changes passed all four workspace cases and two FP8 block-scaling replays against an existing TE native build. This used the exact allocation code and test definitions from this branch in that runtime. Full upstream CI and performance measurements are pending. The legacy scratch clear adds a device operation per call.

Allocate the mutable pointer arrays and cuBLAS scratch on the invoking stream. Clear scratch on older cuBLASLt before dispatch to avoid carrying stale descriptors across layouts. Cover independent graph generations and repeated FP8 block-scaling replay.

Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
@Vtmpas

Vtmpas commented Dec 3, 2026

Copy link
Copy Markdown
Author

@rohitna thanks again for reporting this. The GroupedTensor fix for #3963 is in this draft at f59f5cde. On H200 with cuBLASLt 13.5.1, the workspace changes passed the two-stream and independent graph tests, including mixed NN→NT replay, and two FP8 block-scaling training replays. If you have the delayed-wgrad reproducer from your integration, please link it here so I can check that case too.

FYI @ksivaman @timmoon10 @denera, this is the GroupedTensor follow-up to #3625 and the legacy replay case discussed in #3171. Pre-commit and DCO passed. The H200 run used the existing TE native build, and the full CI and scratch-clear timing are still pending. I'll keep it in draft while I review the patch.

@Vtmpas
Vtmpas marked this pull request as ready for review December 3, 2026 10:38
@Vtmpas
Vtmpas requested a review from ksivaman as a code owner December 3, 2026 10:38
@Vtmpas

Vtmpas commented Dec 3, 2026

Copy link
Copy Markdown
Author

@ksivaman @timmoon10 @zhongbozhu #4004 is now ready for review at f59f5cde. Could one of you run PyTorch L0/L1 on this commit? The targeted H200 tests passed, including concurrent GroupedTensor calls and a second FP8 block-scaling graph replay. CI coverage on Blackwell would be helpful. Thanks!

@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Gives each GroupedTensor GEMM its own setup and cuBLASLt scratch buffers.

  • Each GroupedTensor GEMM call gets its own workspaces.

No actionable issues found. Review was source-based; GPU tests were not run.

Reviews (1) · Last reviewed commit: "Remove obsolete gradient-reset call from..." · Reviewed by Greptile

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GroupedTensor GEMMs on independent CUDA streams share mutable setup and cuBLAS workspaces

1 participant