fix(gemma4-mtp): resolve PARALLEL=2 multi-slot crash in Gemma 4 MTP speculative decoding#26
Merged
Ooooze merged 1 commit intoJun 9, 2026
Conversation
This was referenced Jun 6, 2026
|
Great fix! |
0dbf74d
into
AtomicBot-ai:feature/turboquant-kv-cache
1 check passed
Author
|
my first merge, whoo hoo |
|
Congrats on your first merge, genuinely well earned. This is exactly the kind of practical runtime fix that makes the benchmark work useful beyond just posting numbers: it turns a Gemma 4 MTP caveat into something that can be retested cleanly with multi-slot serving. Thanks for digging into the actual graph/context issue and upstreaming it. |
fukuro-kun
pushed a commit
to fukuro-kun/fukuro-llama-cpp-turboquant
that referenced
this pull request
Jul 5, 2026
…tomicBot-ai#26 Massive reduction in constant memory and compute: - 256KB of dense matrices → 512 bytes of sign arrays - O(d²) = 16,384 ops → O(d log d) = 896 ops per rotation - Metal shader file: 1.5MB → 432KB Speed: still 2.4 tok/s. WHT reduced per-rotation cost but the bottleneck is redundant calls (8-32× per block from flash attention). The dequantize function is called per 4/16-element chunk, each time doing the full 128-element WHT. Need to modify the flash attention kernel to dequantize once per block. Quality: WHT+signs gives BETTER quality than dense QR on real KV tensors (cosine 0.94 vs 0.79 at 2-bit). Sub-Gaussian distribution (kurtosis 1.53) means fewer outliers hitting extreme centroids. Reviewed by Codex: WHT butterfly correct, inverse order verified, QJL correction matches reference C implementation. Co-Authored-By: tturney@psyguard.ai Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fukuro-kun
pushed a commit
to fukuro-kun/fukuro-llama-cpp-turboquant
that referenced
this pull request
Jul 5, 2026
…kv-cache fix(gemma4-mtp): resolve PARALLEL=2 multi-slot crash in Gemma 4 MTP speculative decoding
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 fixes
Running
llama-serverwith--n-parallel 2and a Gemma 4 MTP assistant head crashed immediately when the second slot began its first speculative draft step:Reproducible in 18 tokens on any two-slot request.
Root cause (3 related issues)
1.
gemma4-assistant.cpp— wrong token dimension in Qcur reshapeThe MTP draft step always processes a single token column. The reshape was using
n_tokens(the main batch size, which is2under--n-parallel 2) as the third dimension:n_tokensis correct for the main model forward pass. For the MTP head it is always1— the draft head speculates one token position at a time regardless of how many slots the server is running.2.
llama-graph.cpp/h— stream partition size for MTP modelsn_streamwas not being set to1for MTP graphs, causing batch dimension splitting in self-attention/MHA that produced mismatched shapes under multi-slot scheduling.3.
llama-context.cpp— reservation graph shape mismatchScheduling reservations were using
init_fullinstead ofinit_mtp, causing the reservation graph shape to differ from the execution graph shape under--n-parallel 2.Testing
Tested on AMD Ryzen AI Max+ 395 (Strix Halo APU), Vulkan/RADV, with:
--n-parallel 2,--mtp-draft-n 3,--draft-p-min 0.75Server survived two-slot speculative decoding without crashing. Acceptance rates and decode throughput unchanged from single-slot baseline.
Note: PR #25 addresses a different crash path (null
embddereference inllm_graph_input_embd::set_input). These two fixes are independent.