Repository navigation
Conversation
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.
Motivation
Sparse-prefill scratch replacement allocates its new tensor while the backend still owns the old one. A larger workspace (or a different dtype) can therefore fail even when the replacement alone fits the available allocator budget.
This is a follow-up to #43921, which left workspace retention unchanged. The release-before-replacement change was originally proposed by @divyvasal in #43726. Refs #41076; this addresses the transient replacement peak, not the independently unbounded size of a batch of long histories.
Modifications
Release the workspace owner's old tensor reference before allocating a replacement. Scratch contents are overwritten by the existing caller. Requests that fit the current capacity still reuse the buffer, and views retained by a caller continue owning their original storage.
Add a single-GPU regression with fresh subprocesses so the allocator cap cannot affect other tests or a resident server.
Accuracy Tests
On an H200 with Torch 2.14.1+cu130, starting from upstream
a3abea35609eeeff7e165486dd614963af211161:Both replacement cases pass the below-100-MiB peak-allocation assertion after the fix. These are controlled allocator regressions using the actual workspace class, not a replay of the reported production OOM. No model weights or full serving workload are used.
Existing DSV4 compressed sparse-prefill attention (C4/C128) and workspace reuse tests also pass on H200. The initial numerical-test attempt failed to link
libcudartwith the pip CUDA path; using the complete/usr/local/cuda-13.0toolkit passed without source changes.Speed Tests and Profiling
No kernel, gather layout or attention math changes. No throughput claim; the measured improvement is successful scratch replacement under the same allocator cap.
Checklist
CI States
Latest PR Test (Base): ❌ Run #39123421376
Latest PR Test (Extra): ❌ Run #39123421591
Latest PR Test (AMD ROCm 10): ❌ Run #39123421440