Repository navigation
perf(cuda): a q8_0 recurrent-state cache takes the fused snapshot write - #13
Merged
Merged
Conversation
With -cts q8_0 every Gated DeltaNet layer wrote its new state as f32 into the gdn output and a separate cpy then quantized it into the cache: 48 cpy_f32_q8_0 launches per step, ~13.9 us each on an RTX 5070 Ti (the kernel gives one thread a 32-value block, so it reads 3 MB of state uncoalesced). The f32 cache already skipped that cpy (the kernel writes the snapshots into the cache view); a q8_0 cache now does too. gdn_store_state quantizes as it stores: one q8_0 block is one warp-wide slice of a state column (QK8_0 == warp_size, and every column starts on a block since S_v % 32 == 0), so the block scale is a warp max, and the formula is cpy's quantize_f32_q8_0_block: the cache holds the bytes the unfused gdn -> cpy pair would write. ggml_cuda_try_gdn_cache_fusion takes a q8_0 destination only where that holds: a 32-lane warp, S_v a multiple of 32, the scalar gate (not KDA), and the recurrent kernel; the chunked prefill pipeline writes f32 and keeps its cpy. GGML_CUDA_GDN_Q8_CACHE_LEGACY=1 keeps a q8_0 cache on the cpy. RTX 5070 Ti, Ternary Bonsai 2 27B, -cts q8_0: - GPU time per step (nsys, legacy / fused / legacy): decode (ubatch 1) 14.195 / 13.403 / 14.108 ms, an MTP verify's width (ubatch 3) 17.006 / 16.570 / 16.873 ms. Per layer the cpy took ~14 us and the kernel's in-register quantize adds 1.4 us (ubatch 1) and 2.2 us (ubatch 3) - served with the MTP draft head (K = 3 snapshots per verify: three cpys per layer before this), one conversation, six greedy prompts, legacy / fused A-B-A-B: 104.8 / 118.1 / 110.1 / 120.2 tok/s (+9-10 %), the generated text byte-identical in every leg and the draft acceptance counts equal - logits identical: KL against the cpy path at ubatch 1 and 3, Mean KLD 0.000000, 99 % KLD at the protocol's noise floor, same top p 100 % - test-backend-ops GATED_DELTA_NET_CACHE_FUSION: 13 new q8_0 cases (the served layer, 16 k-heads, 48 v-heads, raw gates, K = 3, at 1-3 tokens over 1/2/4 sequences; K = 1; activated gates; head widths 32/64/128) pass against the CPU cpy, and all 13 fail with the block scale mutated to amax/126; two q8_0 shapes the fusion refuses (a 16-wide head, the 512-token chunked ubatch) keep the cpy and pass, with and without the off switch Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UjmSA3sZea1AekeAiJ4zer
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UjmSA3sZea1AekeAiJ4zer
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.
With
-cts q8_0, every Gated DeltaNet layer used to write its new state as f32 into the GDN output. A separatecpy_f32_q8_0then quantized it into the cache: 48 launches per step at ~14 µs each. The kernel now quantizes as it stores:quantize_f32_q8_0_block, so the cache holds the same bytes the unfused pair wrote.S_v % 32 == 0, the scalar gate (not KDA) and the recurrent kernel.Measured (RTX 5070 Ti, Ternary Bonsai 2 27B PQ2_0,
-cts q8_0)GATED_DELTA_NET_CACHE_FUSION21/21,GATED_DELTA_NET63/63, CONCAT 216/216, SCALE 6/6 and SSM_CONV 45/45, with and without the off switch.Off switch
GGML_CUDA_GDN_Q8_CACHE_LEGACY=1keeps a q8_0 cache on the cpy.TORAD.md gains the row after
b4c2d66.