Repository navigation
gemma4 cuda: opt-in greedy argmax inside the target graph, no unread download - #4616
Merged
Merged
Conversation
…download TF_GEMMA4_ARGMAX_GRAPH=1 (default off): a verify round whose windows are all greedy and unmasked captures tf_round_bf16_argmax over the round's rows in the target forward's graph (a second graph set by row count; eager forwards launch it right after), instead of one launch a window after the graph. Each row has its own block, so every pick is the one the per-window launch made. Entries that are all picks no longer download tok, which no greedy entry reads, and each forward's ids, positions and slots are staged in pinned memory, reused only after an event shows the last copy done.
ashhart
force-pushed
the
lead/gemma4-argmax-graph
branch
from
November 23, 2026 06:29
52fcaca to
479ba3d
Compare
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.
What this changes
TF_GEMMA4_ARGMAX_GRAPH=1(opt-in, default off) trims Gemma 4's CUDA verify round after the target graph:tf_round_bf16_argmaxlaunch over the round's rows is captured at the end of the forward's graph (a second graph set per row count), instead of being launched eagerly after it. The kernel gives each row its own block over the same logits and vocabulary, so each row's pick is the one today's per-window launches make. Sampled, grammar-masked and plain-decode rounds keep today's path.picks; thetokdownload that greedy entries never read is skipped. Any drawn entry downloadstokas before.Same kernel, same inputs, same order: tokens cannot change. No pinned file changes.
Checks
cuda_argmax_graph_test.zig(which rounds fold, which downloads are skipped, staging reuse), the Gemma 4 CUDA host step, compile-cuda-tests for Linux; fmt, ast-check, the 600-line cap. No GPU was available.Still to run
On a GB10, Gemma 4 31B at one stream, plain and with its DFlash drafter, switch off/on/on/off with the same prompts at temperature 0: tokens identical, and decode speed.