[Memory] Measure complete CUDA graph capture footprint for KV budgeting - #51590
Open
xiaohuguo2023 wants to merge 1 commit into
Open
[Memory] Measure complete CUDA graph capture footprint for KV budgeting#51590xiaohuguo2023 wants to merge 1 commit into
xiaohuguo2023 wants to merge 1 commit into
Conversation
Profile every capture descriptor in one end-to-end span instead of extrapolating from two samples per mode. Include profiling setup and retained scratch in the estimate, skip profiling when the flag disables it, and guard the unaccounted-memory warning to runs that capture graphs. Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
13 tasks
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.
Purpose
Fix CUDA graph memory undercounting in
profile_cudagraph_memory().The old path profiled only two descriptors per graph mode and extrapolated the rest. It also summed per-mode deltas even though FULL and PIECEWISE share one runtime pool, and it did not budget memory allocated during profiling setup or retained after profiling cleanup. The shortfall was assigned to the KV cache, so
--gpu-memory-utilizationcould be exceeded during capture or serving while the KV pool was still mostly empty.This PR:
cudagraph_profiling_retained_memoryin the estimate (scratch the real capture reuses).VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS=0(previously ran and discarded the result).--enforce-eager/cudagraph_mode=NONEno longer trigger it).On Kimi-K3 (8× MI355X, TP8), the estimate rose from ~1.3 GiB/GPU to ~4.7–16.9 GiB/GPU depending on config — matching what capture actually needs. This is accounting only; no kernel or graph-capture logic changes.
Fixes agentic OOMs where
HSA_STATUS_ERROR_OUT_OF_RESOURCESoccurred at 3–16% KV usage because graph/setup memory was budgeted to the KV cache.Test Plan
Unit tests (CPU-only; fake device allocator, no GPU required):
pytest tests/v1/cudagraph/test_cudagraph_memory_profiling.py \ tests/v1/cudagraph/test_cudagraph_memory_worker.py -qCoverage:
test_cudagraph_memory_profiling.py— all descriptors and modes; shared-pool span accounting; negative deltas and zero clamping; encoder graphs; profiling-KV setup; retained memory; cleanup on capture failure.test_cudagraph_memory_worker.py— estimate profiled and subtracted from KV budget;VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS=0skips profiling; no warning whencudagraph_mode=NONE.Serving smoke (ROCm, optional for reviewers):
FULL_AND_PIECEWISE,gpu-memory-utilization=0.95Estimated CUDA graph memory: … GiB totalreflects full capture footprint and serve completes without HSA OOM at previously failing batch/seq limits.Test Result
Unit tests (this branch):
Negative control: 8 behavior-changing tests fail on pristine
upstream/main.Serving (Kimi-K3, MI355X TP8):
Startup: profiling every descriptor adds ~8s on Kimi-K3 TP8 (21s → 29s for profiling + capture). Warmup reuse across profiling and real capture is intentionally deferred to a follow-up PR.