Skip to content

[Bugfix] Make Gemma4 MTP suppress_tokens masking CUDA-graph-safe - #53884

Merged
LucasWilkinson merged 1 commit into
vllm-project:mainfrom
lucianommartins:main
Aug 26, 2026
Merged

LucasWilkinson merged 1 commit into
vllm-project:mainfrom
lucianommartins:main

Conversation

@lucianommartins

Copy link
Copy Markdown
Collaborator

Purpose

Gemma4MTP.compute_logits masks suppressed tokens by indexing logits with a
Python list taken from the draft's generation_config (suppress_tokens).
List indexing issues an unpinned host->device copy, which is illegal during
CUDA graph capture.

Since the V2 model runner became the default for non-MoE architectures, the
speculator captures the drafter prefill routine — including compute_logits —
into FULL CUDA graphs. Engine init then fails deterministically with:

RuntimeError: Cannot copy between CPU and CUDA tensors during CUDA graph
capture unless the CPU tensor is pinned.

Trigger: any MTP draft whose generation_config has non-empty
suppress_tokens — currently google/gemma-4-12B-it-assistant
([258883, 258882]). Other Gemma4 assistants ship no suppress_tokens and
are unaffected.

Fix:

  • Materialize the suppress-index tensor once at the end of load_weights
    (post-load, so the device is real and never meta; pre-capture, so no H2D
    transfer ever occurs inside a graph).
  • Mask via logits.index_fill_, mirroring the capture-safe pattern already
    used in Gemma4ForConditionalGeneration.compute_logits (gemma4_mm.py).
  • Lazy per-call materialization is deliberately avoided: the drafter's first
    call happens under capture, and even a pinned copy there would bake a read
    of a transient staging buffer into the graph.

No behavior change for drafts without suppress_tokens (_suppress_idx
stays None; the branch is a no-op). On the V1 runner the masking result is
identical, just via index_fill_.

Test Plan

Repro/verify (H100, gemma-4-12B-it + its MTP assistant, V2 runner default):

python <a-python-test-file> \
  --model-path google/gemma-4-12B-it \
  --assistant-model google/gemma-4-12B-it-assistant \
  --spec-tokens 4

Regression (assistants without suppress_tokens, dense + MoE):

same command with gemma-4-E4B-it / gemma-4-26B-A4B-it and their assistants

Lint: ruff check / ruff format --check clean; mypy introduces no new
findings (4 pre-existing Tensor | Module findings on untouched lines).

Test Result

  • Before: engine init crashes during Capturing prefill CUDA graphs (FULL)
    with the pinned-memory RuntimeError (traceback ends at
    gemma4_mtp.py compute_logits).
  • After: init completes all graph captures; full unit suite passes
    (29/29, text + function-calling + image + multi-image) with MTP active.
  • Regression runs on dense (E4B) and MoE (26B-A4B) assistants: no change.

Duplicate-work check: no open PR/issue found touching Gemma4 MTP
suppress-token masking or this capture crash.

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added nvidia bug Something isn't working labels Aug 26, 2026
- Gemma4MTP.compute_logits masked suppressed tokens via Python-list
  indexing (logits[:, ids] = -inf), which issues an unpinned H2D copy.
- Since the V2 model runner became the default for non-MoE archs, the
  drafter prefill path (incl. compute_logits) is captured into FULL CUDA
  graphs, where unpinned H2D copies are illegal -> engine init fails with
  "Cannot copy between CPU and CUDA tensors during CUDA graph capture".
- Trigger: any MTP draft whose generation_config has non-empty
  suppress_tokens; currently google/gemma-4-12B-it-assistant
  ([258883, 258882]). Other Gemma4 assistants are unaffected (empty).
- Fix: materialize the index tensor once at the end of load_weights
  (post-load, so the device is real and never meta; pre-capture, so no
  H2D ever occurs inside a graph) and mask via logits.index_fill_.
- Lazy per-call materialization is deliberately avoided: the first
  drafter call happens under capture, and even a pinned copy there would
  bake a read of a transient staging buffer into the graph.
- Mirrors the capture-safe suppress-token pattern already used by
  Gemma4ForConditionalGeneration.compute_logits (gemma4_mm.py).
- Verified: gemma-4-12B-it + 12B assistant, spec-tokens=4 crashed at
  "Capturing prefill CUDA graphs (FULL)" before; passes 29/29 unit tests
  after. No behavior change for drafts without suppress_tokens.

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>

@LucasWilkinson LucasWilkinson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM; thanks for fixing!

@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Aug 26, 2026
@LucasWilkinson

Copy link
Copy Markdown
Contributor

/ci run

@LucasWilkinson
LucasWilkinson enabled auto-merge (squash) August 26, 2026 13:48
@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 26, 2026
@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85657 for commit c13244e6ac61.

@LucasWilkinson
LucasWilkinson merged commit 2ab1874 into vllm-project:main Aug 26, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Aug 26, 2026
am-cohere pushed a commit to am-cohere/vllm that referenced this pull request Sep 1, 2026
…m-project#53884)

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
mikeshawcode pushed a commit to mikeshawcode/vllm that referenced this pull request Sep 1, 2026
…m-project#53884)

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Signed-off-by: mikeshawcode <michaelwshaw2@gmail.com>
mylibrar pushed a commit to tanyuqian/vllm that referenced this pull request Sep 3, 2026
…m-project#53884)

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
kelnei added a commit to kelnei/vllm-gemma4 that referenced this pull request Sep 10, 2026
Two follow-ups from the v0.29.0 upgrade, both measured 2026-09-10:

- Model Runner V2 is the default since v0.29.0, so the
  VLLM_USE_V2_MODEL_RUNNER=1 override in the README MTP recipe and in
  run_cluster.sh is redundant. Dropped it; 26B-A4B + MTP without the
  variable decodes at 285.0 / 1,476 tok/s on the RTX PRO 6000, matching
  the published 283.1 / 1,462. The V2 runner also honors
  thinking_token_budget now, so that caveat is gone too.

- vllm-project/vllm#53884 (Gemma 4 MTP under CUDA graphs) fixes the 12b
  assistant. 193.8 / 1,339 tok/s on the RTX (baseline 114 / 843, DFlash
  203.1 / 1,203) and 39.3 / 270 on a DGX Spark (DFlash 40.8 / 242).
  DFlash stays the 12b recommendation; the table row and run_cluster.sh
  now carry the 12b assistant instead of marking it broken.
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…m-project#53884)

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nvidia ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants