Skip to content

[GG] Fix MRV2 CUDA graph and sparse DCP memory profiling - #131

Merged
voipmonitor merged 4 commits into
dev/gilded-gnosisfrom
fix/gg-mrv2-memory-profile-20260719
Jul 20, 2026
Merged

[GG] Fix MRV2 CUDA graph and sparse DCP memory profiling#131
voipmonitor merged 4 commits into
dev/gilded-gnosisfrom
fix/gg-mrv2-memory-profile-20260719

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • replace the MRV2 CUDA-graph memory profiler stub with a real throwaway capture of target and speculator graphs
  • checkpoint B12X channels before either target or draft capture, then roll back every transient profiling channel after graph destruction
  • destroy every disposable graph while its managers and wrappers still reference the private profiling pool
  • release profiling KV/cache state before production KV allocation and avoid double-counting retained graph-pool pages
  • account for eager B12X sparse-DCP transient memory when VLLM_MEMORY_PROFILE_INCLUDE_ATTN=1
  • add regression coverage for cleanup ordering, channel rollback, and sparse DCP workspace gates

Root causes

MRV2 previously returned 0 from profile_cudagraph_memory(). On large TP6/DCP6 configurations this filled remaining VRAM with KV cache without reserving the production graph footprint. Sparse MLA also skips attention during the dummy profile, so its eager AG/RS transient was omitted.

The first real profiling implementation exposed a separate lifetime bug. It originally checkpointed only immediately before draft capture, leaving target-created B12X graph channels outside rollback. It also restored the production graph pool before destroying disposable graphs. Cleanup must instead cover both target and draft captures and happen while every owner still points at the private pool.

The fixed order is:

  1. checkpoint target/draft B12X channel ownership
  2. capture target and speculator graphs in a private pool
  3. synchronize and destroy those graphs while every owner still points at that pool
  4. use B12X's coordinated cross-rank rollback for transient channels
  5. restore production pool references

PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True is not a fix. Validation uses backend:native; expandable segments can change address layout enough to hide a lifetime failure and are incompatible with native KV-offload address registration.

Validation

  • focused vLLM cleanup-order regression test passed
  • paired B12X lifecycle suite: 40 passed
  • Ruff and git diff --check passed
  • GLM-5.2 NVFP4 A4 + online MXFP8, TP8/DCP2/MTP3, graph 4, 8k chunks, native allocator, B12X PCIe DCP A2A
  • disposable target/draft profiling capture, production capture, short request, then 300k-token chunked prefill and first decode all passed without Xid or CUDA error
  • TP6/DCP6 memory repro retained 1,748,694 KV tokens and completed a 64,515-token prefill without OOM

This PR is based directly on dev/gilded-gnosis; it contains no Docker-only source overlay. Pair it with local-inference-lab/sparkinfer#47 for coordinated IPC teardown.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@voipmonitor, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6712f7c1-64d1-403f-b3fa-6a206772b6f2

📥 Commits

Reviewing files that changed from the base of the PR and between eed6a28 and 454b853.

📒 Files selected for processing (1)
  • vllm/distributed/device_communicators/custom_all_reduce.py
📝 Walkthrough

Walkthrough

The changes add B12X sparse MLA transient-memory profiling and implement CUDA graph memory profiling with minimal KV-cache setup, capture cleanup, memory measurement, and restoration of PCIe and DCP A2A channel state.

Changes

Sparse MLA memory profiling

Layer / File(s) Summary
Sparse profile estimation and configuration
vllm/envs.py, vllm/model_executor/layers/attention/mla_attention.py
Adds the attention profiling environment flag and estimates transient B12X DCP sparse attention memory.
Profiling allocation and validation
vllm/model_executor/layers/attention/mla_attention.py, tests/v1/attention/*
Includes estimated sparse workspace in profiling allocations and tests workspace, projection, batch, and pure-A2A paths.

CUDA graph memory profiling

Layer / File(s) Summary
CUDA graph cleanup contract
vllm/v1/worker/gpu/cudagraph_utils.py, vllm/v1/worker/gpu/spec_decode/*, tests/v1/cudagraph/*
Adds graph-manager cleanup methods and speculator access to active CUDA graph managers.
B12X channel checkpoint and rollback
vllm/distributed/device_communicators/custom_all_reduce.py, vllm/distributed/parallel_state.py, vllm/v1/attention/ops/dcp_alltoall.py, tests/distributed/*
Adds checkpoint and reverse-order rollback for PCIe and DCP A2A channel state.
CUDA graph profiling orchestration
vllm/v1/worker/gpu/model_runner.py
Initializes minimal KV caches, captures graphs, measures memory deltas, and releases profiling state.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GPUModelRunner
  participant CudaGraphManager
  participant Speculator
  participant parallel_state
  participant CUDA
  GPUModelRunner->>GPUModelRunner: Initialize minimal KV cache
  GPUModelRunner->>parallel_state: Checkpoint B12X channels
  GPUModelRunner->>CudaGraphManager: Capture CUDA graphs
  GPUModelRunner->>Speculator: Get and capture speculator managers
  GPUModelRunner->>CUDA: Measure memory deltas
  GPUModelRunner->>CudaGraphManager: Clear captured graphs
  GPUModelRunner->>Speculator: Clear cudagraphs
  GPUModelRunner->>parallel_state: Roll back B12X channels
  CUDA-->>GPUModelRunner: Return estimated graph memory
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main changes: MRV2 CUDA graph cleanup and sparse DCP memory profiling fixes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/gg-mrv2-memory-profile-20260719

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
vllm/distributed/device_communicators/custom_all_reduce.py (1)

653-668: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding Google-style Args: / Returns: / Raises: sections.

As per coding guidelines, Python code must use Google-style docstrings with Args:/Returns:/Raises: sections instead of reStructuredText/Sphinx fields. While these single-line docstrings don't use Sphinx fields, expanding them to include explicit Args:, Returns:, and Raises: sections would fully align with the guideline. Consider applying this to the newly added docstrings across the PR.

📝 Proposed docstring updates
     def checkpoint_pcie_channels(self) -> Any | None:
-        """Snapshot B12X channels before a throwaway graph capture."""
+        """Snapshot B12X channels before a throwaway graph capture.
+        
+        Returns:
+            The checkpoint object, or None if the runtime does not support it.
+        """
         runtime = self._pcie_runtime
         checkpoint = getattr(runtime, "checkpoint_channels", None)
         if checkpoint is None:
             return None
         return checkpoint()

     def rollback_pcie_channels(self, checkpoint: Any) -> None:
-        """Release B12X channels created after ``checkpoint``."""
+        """Release B12X channels created after ``checkpoint``.
+        
+        Args:
+            checkpoint: The checkpoint object returned by checkpoint_pcie_channels.
+            
+        Raises:
+            RuntimeError: If the B12X PCIe all-reduce runtime is unavailable.
+        """
         runtime = self._pcie_runtime
         rollback = getattr(runtime, "rollback_channels", None)
         if rollback is None:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@vllm/distributed/device_communicators/custom_all_reduce.py` around lines 653
- 668, Expand the docstrings for checkpoint_pcie_channels and
rollback_pcie_channels with Google-style sections: document the checkpoint
returned by checkpoint_pcie_channels, the checkpoint argument accepted by
rollback_pcie_channels, and the optional return value and RuntimeError raised
when the PCIe runtime is unavailable. Preserve the existing behavior and
descriptions.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@vllm/distributed/device_communicators/custom_all_reduce.py`:
- Around line 653-668: Expand the docstrings for checkpoint_pcie_channels and
rollback_pcie_channels with Google-style sections: document the checkpoint
returned by checkpoint_pcie_channels, the checkpoint argument accepted by
rollback_pcie_channels, and the optional return value and RuntimeError raised
when the PCIe runtime is unavailable. Preserve the existing behavior and
descriptions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e1d6c703-50dc-4c73-b37f-5474cb0abdce

📥 Commits

Reviewing files that changed from the base of the PR and between d8c0f0d and c574093.

📒 Files selected for processing (7)
  • tests/distributed/test_b12x_fused_all_reduce.py
  • tests/distributed/test_dcp_a2a.py
  • tests/v1/cudagraph/test_breakable_cudagraph.py
  • vllm/distributed/device_communicators/custom_all_reduce.py
  • vllm/distributed/parallel_state.py
  • vllm/v1/attention/ops/dcp_alltoall.py
  • vllm/v1/worker/gpu/model_runner.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/v1/cudagraph/test_breakable_cudagraph.py
  • vllm/v1/worker/gpu/model_runner.py

@voipmonitor

Copy link
Copy Markdown
Author

Addressed the lifecycle API docstring review note in 454b853. Full focused MRV2/DCP/CUDA-graph validation in the release environment: 94 tests passed.

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.

1 participant