Skip to content

[GG] perf(nf3): integrate Grid188 hybrid decode - #113

Closed
voipmonitor wants to merge 2 commits into
local-inference-lab:dev/gilded-gnosis-old-basefrom
voipmonitor:codex/gg-nf3-grid188-decode-20260717
Closed

[GG] perf(nf3): integrate Grid188 hybrid decode#113
voipmonitor wants to merge 2 commits into
local-inference-lab:dev/gilded-gnosis-old-basefrom
voipmonitor:codex/gg-nf3-grid188-decode-20260717

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Jul 17, 2026

Copy link
Copy Markdown

Summary

  • Integrate the exact TP4 GLM-5.2 E64-NVFP4/E192-NF3 mapped Grid188 decode path on dev/gilded-gnosis.
  • Validate the complete expert remap, prepared layouts, TP4/M=4/top-k=8 geometry, SM count, launch resources, tensor contracts, and custom-op availability before arming it.
  • Borrow the existing serial-path scratch buffers without aliasing; all non-exact cases keep the existing serial fallback.
  • Allow dense/shared-expert MXFP8 online overlays for nvfp4_nf3_hybrid checkpoints.
  • Remove two MTP draft-loop host synchronization sources: reuse a conservative CPU sequence-length bound and keep DCP rank localization as a Python scalar.

Requires local-inference-lab/b12x#36.

Grid188 is enabled by default for its exact geometry and can be disabled with VLLM_NF3_GRID188_DECODE=0 for A/B comparison.

Validation

  • 26 focused vLLM tests passed; 17 CUDA-only cases skipped in the unit-test container.
  • 7 focused b12x tests passed.
  • Ruff check and format check passed.
  • Real TP4/DCP4/MTP3 CUDA graph capture and inference passed with InstantTensor BUFFERED loading; no garbled/CJK output.

Benchmark

Checkpoint: madeby561/GLM-5.2-MXFP8-NVFP4-NF3-Hybrid with the exact 546-module MXFP8 selector, A16, FP8 KV for the matched old-v18 overlay test, CC1, three 60-second runs, no concurrent model loading.

Configuration Median aggregate tok/s Mean aggregate tok/s Mean acceptance
Existing serial fallback 93.98 94.04 0.6165
Grid188 104.22 104.10 0.6794
Grid188 + host-sync fixes 105.43 106.44 0.6944

The Grid188 median gain over the serial fallback is +10.9%. The additional host-sync median gain is +1.16%; its throughput effect is smaller and partially coupled to probabilistic MTP acceptance variance, so it is kept as a separate commit.

Provenance

The Grid188 design and the two host-sync observations were published in davidsyoung/vllm-glm52#2. This PR ports the required symbols onto GG rather than replacing GG files with release overlays.

Summary by CodeRabbit

  • New Features

    • Added support for the nvfp4_nf3_hybrid ModelOpt online quantization configuration.
    • Added an optimized Grid188 decode path for eligible hybrid NVFP4/MXFP4 and NF3 MoE workloads.
    • Added the VLLM_NF3_GRID188_DECODE environment option to control the specialized decode path.
  • Performance

    • Reduced device-side overhead during distributed attention sequence-length calculations.
    • Improved speculative decoding metadata handling with more conservative sequence-length bounds.
  • Bug Fixes

    • Improved fallback behavior when Grid188 geometry or layout requirements are not met.

voipmonitor and others added 2 commits July 17, 2026 23:02
Co-authored-by: David Young <david@davidsyoung.com>
Co-authored-by: David Young <david@davidsyoung.com>
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds an exact Grid188 fused decode path for hybrid NVFP4/MXFP4 and NF3 layers, recognizes the hybrid online overlay, and adds tests for descriptor encoding. It also changes DCP rank localization and speculative decoding attention metadata bounds.

Changes

Grid188 hybrid decode

Layer / File(s) Summary
Overlay and descriptor contracts
tests/quantization/test_nvfp4_nf3_hybrid.py, vllm/config/quantization.py
Online overlay resolution accepts nvfp4_nf3_hybrid; tests validate MXFP8 resolution, descriptor encoding, and incomplete remap rejection.
Grid188 runtime preparation
vllm/envs.py, vllm/model_executor/layers/quantization/nvfp4_nf3_hybrid.py
Adds the Grid188 environment flag, descriptor and eligibility helpers, runtime state, prepared tensors, scratch handling, and fused launch preparation.
Grid188 apply dispatch
vllm/model_executor/layers/quantization/nvfp4_nf3_hybrid.py
Initializes Grid188 state and uses the fused kernel for eligible four-token batches, otherwise retaining existing tier-based execution.

DCP attention localization

Layer / File(s) Summary
DCP rank localization
vllm/v1/attention/backends/utils.py, tests/v1/attention/test_indexer_dcp_localize.py
Keeps dcp_rank as a host scalar and tests localized sequence lengths without scalar tensor allocation.

Speculative decode metadata

Layer / File(s) Summary
Draft metadata upper bound
vllm/v1/worker/gpu/spec_decode/autoregressive/speculator.py
Computes a conservative draft sequence-length upper bound and supplies it during draft attention metadata rebuilding.

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

Sequence Diagram(s)

sequenceDiagram
  participant HybridLayer
  participant HybridRuntime
  participant Grid188Kernel
  HybridLayer->>HybridRuntime: initialize runtime
  HybridRuntime->>HybridRuntime: prepare eligible Grid188 state
  HybridLayer->>HybridRuntime: apply four-token batch
  HybridRuntime->>Grid188Kernel: launch fused hybrid decode
  Grid188Kernel-->>HybridLayer: return output
Loading

Possibly related PRs

Suggested reviewers: lukealonso

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 clearly and concisely summarizes the main change: integrating the Grid188 hybrid decode path.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
vllm/model_executor/layers/quantization/nvfp4_nf3_hybrid.py (1)

1029-1029: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Use vLLM’s cached current_stream() helper in this decode hot path.

torch.cuda.current_stream() constructs a stream wrapper on every eligible MoE layer and token, adding avoidable host overhead to the new fast path.

🤖 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/model_executor/layers/quantization/nvfp4_nf3_hybrid.py` at line 1029,
Update the decode hot path around the current_stream argument to use vLLM’s
cached current_stream() helper instead of torch.cuda.current_stream(). Preserve
the existing device selection and integer CUDA stream handle passed to the
downstream operation.
🤖 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.

Inline comments:
In `@tests/v1/attention/test_indexer_dcp_localize.py`:
- Around line 309-319: Add a CUDA-gated variant of
test_get_dcp_local_seq_lens_rank_does_not_allocate_cuda_scalar that creates
seq_lens on CUDA and verifies the same localized result, preserving the
torch.tensor allocation guard; alternatively, rename the existing test to
explicitly describe its CPU-only guarantee.

---

Nitpick comments:
In `@vllm/model_executor/layers/quantization/nvfp4_nf3_hybrid.py`:
- Line 1029: Update the decode hot path around the current_stream argument to
use vLLM’s cached current_stream() helper instead of
torch.cuda.current_stream(). Preserve the existing device selection and integer
CUDA stream handle passed to the downstream operation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 593ec3e4-04c4-48d2-ac97-8c669dcb87af

📥 Commits

Reviewing files that changed from the base of the PR and between 5b116d1 and 95cefd7.

📒 Files selected for processing (7)
  • tests/quantization/test_nvfp4_nf3_hybrid.py
  • tests/v1/attention/test_indexer_dcp_localize.py
  • vllm/config/quantization.py
  • vllm/envs.py
  • vllm/model_executor/layers/quantization/nvfp4_nf3_hybrid.py
  • vllm/v1/attention/backends/utils.py
  • vllm/v1/worker/gpu/spec_decode/autoregressive/speculator.py

Comment on lines +309 to +319
def test_get_dcp_local_seq_lens_rank_does_not_allocate_cuda_scalar(monkeypatch):
seq_lens = torch.tensor([17, 33, 65], dtype=torch.int32)

def fail_tensor_allocation(*args, **kwargs):
raise AssertionError("rank localization must not allocate a scalar tensor")

monkeypatch.setattr(torch, "tensor", fail_tensor_allocation)

actual = get_dcp_local_seq_lens(seq_lens, dcp_size=4, dcp_rank=2)

assert actual.tolist() == [4, 8, 16]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Exercise the CUDA behavior this regression test claims to cover.

Because seq_lens is CPU-backed, the test only proves that torch.tensor is not called; it cannot detect a CUDA-only scalar conversion or synchronization regression. Add a CUDA-gated case with seq_lens on CUDA, or rename the test to state its narrower guarantee.

🤖 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 `@tests/v1/attention/test_indexer_dcp_localize.py` around lines 309 - 319, Add
a CUDA-gated variant of
test_get_dcp_local_seq_lens_rank_does_not_allocate_cuda_scalar that creates
seq_lens on CUDA and verifies the same localized result, preserving the
torch.tensor allocation guard; alternatively, rename the existing test to
explicitly describe its CPU-only guarantee.

@voipmonitor

Copy link
Copy Markdown
Author

Final baked-image validation on madeby561/GLM-5.2-MXFP8-NVFP4-NF3-Hybrid, TP4/DCP4, A16, NVFP4 MLA KV:

  • MTP0: 45.37 tok/s decode CC1, 2,347 tok/s 64k prefill, 778,240 KV tokens.
  • MTP3: 105.69 tok/s decode CC1, 2,288 tok/s 64k prefill, 529,920 KV tokens, mean accepted length 2.89, draft acceptance 63.1%.
  • Logs assert both armed exact TP4 Grid188 one-grid decode and executing TP4 Grid188 one-grid decode, plus kv_cache_dtype=nvfp4_ds_mla.

This matches the clean v17 MTP0 result within run variance and retains the measured Grid188 MTP3 decode gain.

@voipmonitor voipmonitor changed the title perf(nf3): integrate Grid188 hybrid decode on GG [GG] perf(nf3): integrate Grid188 hybrid decode Jul 18, 2026
@voipmonitor

Copy link
Copy Markdown
Author

Superseded by the canonical dev/gilded-gnosis consolidation. The corresponding implementation is present in commit(s): 45837b4,1dc20c2b7f. Closing the old-base PR so future work targets the canonical GG branch.

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