Repository navigation
Add MTP speculative decoding to the agent - #215
Merged
Merged
Conversation
- gemv_multirow.cuh: int8 multi-row GEMV for 2-8 rows (all 12 GGUF types), used by GGUFMatrix#gemv_into. 4-token pass 283 -> 68 ms on the 27B. - Gated DeltaNet verify mode: no state writes during verify, rows stashed per block, commit_verify!(n) folds in the kept rows. - MTPHead: Qwen3.5/3.8 NextN head (llama.cpp graph_mtp), loaded from the model or an mtp-*.gguf sidecar; KV kept in lockstep with the trunk. - Network: verify / commit_verify! / mtp_draft, all-row logits, MTP in clear/save/restore/snapshot. - Loader reserves VRAM for the head and drops it rather than push trunk layers to the CPU. - Agent: speculative sampling loop (k=3, SHAINET_SPEC_K), sidecar discovery under ~/models.
The tiled prefill kernel parallelizes over 64-query tiles and heads only, so a 4-token pass at 32K context ran 24 blocks and took 70 ms of attention against 7 ms for one decode token. Up to 8 tokens now take the grouped split-KV decode kernel, extended to one query token per blockIdx.z: 22.5 ms, verify pass 120 -> 82 ms at 32K.
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.
Problem
Decode on Qwen3.8-27B is bound by weight reads per token. Speculative decoding needs a verify pass over a few tokens that costs about one decode step, and a way to roll the Gated DeltaNet state back after rejected drafts. Before this, a 2-8 token pass took the prefill GEMM path and cost 5.5x a single token (283 ms vs 50 ms for 4 tokens).
Changes
gemv_multirow.cuh: int8 multi-row GEMV for 2-8 rows, all 12 GGUF types in use. Each weight block is read once for all rows (llama.cpp mmvq scheme).GGUFMatrix#gemv_intouses it for 2-8 rows (SHAINET_GEMV_MR=0disables it). 4-token pass: 283 -> 68 ms.commit_verify!(n)folds in the kept rows (gated_delta_rule_nowrite,short_conv_silu3_nostate,short_conv_state3).MTPHead: Qwen3.5/3.8 NextN head following llama.cppgraph_mtp, loaded from the model or anmtp-*.ggufsidecar (HFLoader.load_gguf_mtp). Its KV cache stays in lockstep with the trunk, and it is included in clear, save/restore and snapshot.Network#verify,#commit_verify!,#mtp_draft, and all-row logits.SHAINET_SPEC_K; 0 = off), sidecar discovery under~/models.Results (27B GSQ IQ3_S, RTX 4090 Laptop)
Tests
spec/gemv_multirow_spec.cr: multi-row vs single-row GEMV for every type.spec/gdn_verify_commit_spec.cr: verify + commit(n) leaves the same state as n plain rows, with a control for a wrong n.batched_kquant_matmul_spec:91,llama_attn_workspace_spec:152) also fail on master.