Repository navigation
[Bugfix] Make Gemma4 MTP suppress_tokens masking CUDA-graph-safe - #53884
Merged
Merged
Conversation
- 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
approved these changes
Aug 26, 2026
LucasWilkinson
left a comment
Contributor
There was a problem hiding this comment.
LGTM; thanks for fixing!
Contributor
|
/ci run |
LucasWilkinson
enabled auto-merge (squash)
August 26, 2026 13:48
|
✅ Triggered Buildkite CI #85657 for commit |
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>
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
Gemma4MTP.compute_logitsmasks suppressed tokens by indexing logits with aPython 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:
Trigger: any MTP draft whose
generation_confighas non-emptysuppress_tokens— currentlygoogle/gemma-4-12B-it-assistant(
[258883, 258882]). Other Gemma4 assistants ship nosuppress_tokensandare unaffected.
Fix:
load_weights(post-load, so the device is real and never meta; pre-capture, so no H2D
transfer ever occurs inside a graph).
logits.index_fill_, mirroring the capture-safe pattern alreadyused in
Gemma4ForConditionalGeneration.compute_logits(gemma4_mm.py).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_idxstays
None; the branch is a no-op). On the V1 runner the masking result isidentical, just via
index_fill_.Test Plan
Repro/verify (H100, gemma-4-12B-it + its MTP assistant, V2 runner default):
Regression (assistants without suppress_tokens, dense + MoE):
Lint:
ruff check/ruff format --checkclean; mypy introduces no newfindings (4 pre-existing
Tensor | Modulefindings on untouched lines).Test Result
Capturing prefill CUDA graphs (FULL)with the pinned-memory RuntimeError (traceback ends at
gemma4_mtp.pycompute_logits).(29/29, text + function-calling + image + multi-image) with MTP active.
Duplicate-work check: no open PR/issue found touching Gemma4 MTP
suppress-token masking or this capture crash.