Repository navigation
Conversation
The workspace cache currently ignores the calling CUDA stream. Overlapping GEMMs can therefore overwrite the same scratch buffer and return incorrect results. Include the stream in the cache key, keep reuse on each stream, and add ownership and FP32/BF16 numerical regression tests. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
[High impact] The PR appears safe to merge; no new blocking issues were found. SummaryMoves ordinary and list/grouped GEMM scratch from a Python cache to invocation-local allocations owned by PyTorch’s CUDA allocator.
DiagramsequenceDiagram
participant P as Python caller
participant B as Native binding
participant A as CUDA allocator
participant G as GEMM streams
P->>B: "GEMM with workspace=None"
B->>A: Allocate invocation-local scratch
A-->>B: Owned memory
B->>G: Submit GEMMs with separate slices
G-->>B: Join caller stream, including on launch error
B->>A: Release owner
B-->>P: Return outputs or rethrow error
Reviews (35) · Last reviewed commit: "Merge branch 'main' into fix/cublas-work..." · Reviewed by Greptile |
Keep scratch local to each invocation so graph captures use their own private pools and temporary streams do not retain tensors in Python. Remove Linear's preallocation workaround for the global workspace cache. Cover concurrent graph replays, graph generations, scratch reclamation, grouped GEMM stream joins, and compiled Linear forward and backward. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
Cover NN router dgrad with FP32 and BF16 operands in concurrent eager execution and independent CUDA graphs. Preserve NT wgrad coverage and exact references while retaining only one pair of large eager outputs. All 22 workspace cases pass on native SM90 H200 with CUDA 13 and PyTorch 2.13, including all four new NN cases. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
@Oleg-Goncharov , @ksivaman , hello! can i have your assistance here? |
|
@ksivaman kindly |
|
/te-ci pytorch L0 |
This comment has been minimized.
This comment has been minimized.
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Replace the cold-start test's cache_info assertions with checks for capture-time allocation and release of workspace tensors. Keep output and gradient comparisons across CUDA, CPU and meta initialization. Remove BasicLinear's obsolete cache preallocation and use the existing opaque-object capability guard for compiled execution. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
Fixed in f01b35e, on top of the latest main merge. The cold-start test now checks capture-time workspace allocation and release of Python tensor references instead of On H200 with CUDA 13 and PyTorch 2.13, the original |
|
@ksivaman could you rerun PyTorch L0 on |
Preserve a launch exception until all forked helper streams have rejoined the caller. This keeps earlier GEMMs ordered before caller-owned scratch is released, including when a later operation is rejected. Add a regression that catches a later native bias-type error during CUDA graph capture, checks the completed prefix and untouched rejected output, and verifies eager recovery. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
/te-ci pytorch L0 L1 |
zhongbozhu
left a comment
There was a problem hiding this comment.
I have found similar issues where upper frameworks enable some overlap features and might run into issues like this.
Beside cublas backend, TE also has cudnn cutedsl grouped gemms which also needs its own workspace buffer, can we apply similar technique for those (without introducing too much cpu overhead)?
I can do it. It you want me to. imo, it's important here. |
|
Kr |
Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
@zhongbozhu @ksivaman @timmoon10 I merged current main ( The cuBLAS implementation and evidence are already in the PR:
I also traced the cuDNN/CuTeDSL paths. In our frontend 1.26 runtime, the compiled operators retain mutable workspace, and the wgrad launch closures capture it. The wgrad API does not expose caller workspace, so changing an operator attribute after compilation would not redirect those launches. TE's newer descriptor-workspace path caches by FC role/configuration/device, which doesn't isolate overlapping calls or independent graph generations. The follow-up should reuse compiled kernels but separate workspace ownership for overlapping calls and graph lifetimes, then measure eager enqueue cost and graph replay separately. I haven't added an unverified cuDNN patch here: we only have H200/H100, while these kernels require SM100+. Could you confirm the frontend version/API to target and provide Blackwell CI coverage for concurrent calls, capture generations and delayed wgrad? |
|
/te-ci pytorch |
|
Up |
|
@zhongbozhu are any updates or concerns here? |
|
/te-ci pytorch L1 |
Preserve main's separate C and D arguments in the grouped GEMM launch. Keep the helper stream joins before rethrowing a launch error. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
@zhongbozhu @ksivaman @timmoon10 I resolved the merge conflict in 985b7a23. The merge keeps main's separate C/D handling and the PR's helper-stream joins on exceptions. Local pre-commit, cpplint and the license check passed. The Nov 18 L1 request stopped at the mergeability check, so no tests ran. PyTorch L0 passed on the earlier Nov 6 run. Could one of you run |
|
/te-ci pytorch L0 L1 |
Bring in the pack_forward_args lint fix from NVIDIA#3941. Signed-off-by: Matvey Saprykin <mtvey.s@gmail.com>
|
@zhongbozhu thanks for running L0/L1. All 12 GPU checks on I merged current main in 746692fe, bringing in the upstream fix from #3941. I reproduced the warning with pylint 4.1.3 on the old head and verified that it clears after the merge. The workspace patch is unchanged relative to main. @ksivaman @timmoon10 could one of you rerun PyTorch L0/L1 on |
|
Thanks for this change. One thing I noticed while reading it: the description says the grouped-tensor backend is unchanged, and I think that path has the same sharing problem, with one extra buffer involved. It may be worth covering here or in a follow-up. In
Neither cache key includes the CUDA stream. So two grouped GEMMs with the same number of groups, running on two streams of one device, share the setup buffer, and if they also have the same layout they share the scratch. The second call's setup kernel can overwrite the pointer arrays while the first call's GEMM is still reading them. Where we saw it: MoE training with the fused grouped MLP, with the expert weight gradients delayed onto a side stream while the main stream ran the next grouped GEMM for the same number of experts. The symptom was a crash or a hang inside the grouped GEMM, and it went away when both buffers were keyed by To be clear about how solid this is: we hit it on an older TE revision in our own integration branch, and I have not reproduced it on current Two questions:
|
Description
Concurrent GEMMs on independent CUDA streams receive the same cuBLAS workspace from the device/mode cache and can overwrite each other's partial sums. On one H200, two FP32
NTGEMMs with a reduction dimension of 16384 produced incorrect results in 35 of 48 calls; separate scratch produced zero mismatches against serial execution.Replace the Python workspace cache with invocation-local memory owned by PyTorch's CUDA allocator. Ordinary GEMMs allocate a native
DataPtrin the PyTorch binding, avoiding per-call Python Tensor creation. The list/multistream grouped path uses one allocation with disjoint, 256-byte-aligned workspace slices. Its helper streams join the caller before the owner is released. Eager reuse remains stream-ordered; captured allocations belong to their graph's private pool. No persistent per-stream cache or new device synchronization is added.Custom recipes and communication overlap retain explicit Tensor workspaces. Existing explicit-workspace callers remain supported; the private bindings additionally accept
Nonewith size zero to request native allocation. Usable workspace sizes, GEMM dtypes and algorithm selection are unchanged. The grouped-tensor backend is unchanged.Type of change
Changes
weight[128,4096],grad_output[8192,128], output[8192,4096], and reduction 128 against exact analytic references in FP32 and BF16. Preserve NT coverage.Validation
Exception-path follow-up (
efa5063, October 26): the common grouped launch now rejoins helper streams before rethrowing a recoverable GEMM error. On H200, the old core reproducescudaErrorStreamCaptureUnjoined; the rebuilt core and PyTorch binding pass all 23 workspace tests, including the new partial-group failure/capture/recovery regression. Formatting, cpplint and the license check pass. No host/device-wide synchronization or additional successful-path CUDA calls were added. The earlier performance measurements below were not rerun for this exception-path change.The following records the earlier native-allocation qualification:
H200, PyTorch 2.13.0+cu130, CUDA toolkit 13.0, cuBLASLt 13.5.1, native PyTorch CUDA allocator. The candidate binding was rebuilt with the same flags as main
9ea05cf2e8dc, using the unchanged common library.tests/pytorch/test_gemm_workspace.pypass, including the compiled opaque-GEMM capture-generation case, with no skips.48a48c91896a: update both Linear compile-test observers to the native binding. Both edited observers pass H200 capture checks through the compiled-GEMM fixture; the full Linear tests remain capability-skipped (11 cases) on the available PyTorch 2.13 build, pending the compatible opaque-object CI environment.Checklist