mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1372] [CLOSED] DeltaNet recurrence: STRATA_GDN_CHUNKED=1 - the prompt's recurrence in 32-token chunks (opt-in, 1.8x faster, other bits) #3412
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3412
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1372
Author: @sergqwer
Created: 10/7/2026
Status: ❌ Closed
Base:
main← Head:pr/gdn-chunked📝 Commits (1)
7d32cf5DeltaNet recurrence: STRATA_GDN_CHUNKED=1 - the prompt's recurrence in 32-token chunks (opt-in, 1.8x faster, other bits)📊 Changes
2 files changed (+849 additions, -3 deletions)
View changed files
📝
src/prefill/gdn_rec_parity.cu(+497 -2)📝
src/prefill/kernels.cu(+352 -1)📄 Description
The prompt path's DeltaNet recurrence (
gdn_rec_kh_kernel) walks a chunk one token at a time. On an RTX 5090 it costs ~0.41 µs per token and layer: 520-530 ms of a 32K prompt (9%). This PR adds an opt-in (STRATA_GDN_CHUNKED=1) that computes the recurrence in chunks of 32 tokens, in the WY form flash-linear-attention uses, all in FP32. The kernel is 1.81x faster per launch, and it takes ~210 ms (3.7%) off a 32K prompt. It sums in another order than the sequential kernel, so its bits differ; that is why it is opt-in. Unset (the default), nothing changes.What it does
The math, per value head, with γ_t the gate's running sum inside the chunk and S0 the state before it:
The two kernels:
gdn_chunk_prep_kernel, one block per (chunk, key head), for every chunk of a 2048-token super-block at once. It forms k·k and q·k and solves for T (one lane per token). It writes T, P = e^(γ_t − γ_i) q_t·k_i and γ for the key head's three value heads.gdn_chunk_scan_kernel, one block per (key head, 16 value columns): 128 blocks. Each block walks the super-block's chunks with its state slice in registers. The products are register-tiled from shared memory, and the next chunk's k, q, v, γ and β load (cp.async) while the current one computes.Scratch. The prep's output for a super-block takes 25.6 MB. It is allocated once per device, on the first call, and kept; the two kernels' shared-memory attributes are also set once. A stream-ordered allocation and free per call cost more host time than the kernels saved: a 2K prompt's recurrence took 78 ms against 34 ms.
Where it runs. Only on prompt chunks of ≥ 128 tokens (
kGdnChunkedMin; see below), on a CUDA card with:STRATA_EMULATE_CCis honoured. Anywhere else the existing kernels run: smaller cards (RTX 3090, 4080, 5080), a failed scratch allocation, and HIP/SYCL, where none of this code is compiled.Builds and tests.
kernels.cucompiles for 75/80/86/89/120.gdn_rec_paritynow:gdn_rec_kh_kernel(fails above 1e-4 relative) at T = 1..4099, 8192 and 32768, from a non-zero state;--bench).Measured
RTX 5090 (170 SMs), Ryzen 9 9950X3D, IQ2_XS (ISTA GSQ-RCO),
--kv int8,--expert-cache 12000.Kernel accuracy (
gdn_rec_parity, max |diff| / max |value|, output / state after the chunk, 0 failures):gdn_rec_kh_kernelgdn_rec_kh_kernelEnd to end, first-token KL to the default. The noise arm is
STRATA_PROMPT_ATTN_V1=1: upstream's first prompt-attention kernel, which has the same accuracy but sums in another FP32 order. The last column says whether the 32 greedy tokens match the default's.The switch moves the output by 1.15-1.83x what the noise arm does. The top token is the same everywhere. The greedy tokens match the default's on 3 of 4 prompts with the switch, and on 1 of 4 with the noise arm.
Speed per launch (
gdn_rec_parity --bench, one layer, 48 value heads, medians of alternating runs):gdn_rec_kh_kernelBelow ~100 tokens the two launches cost more than they save, so the threshold is 128 tokens. Since the switch is opt-in, it then applies to nearly every prompt chunk.
In the engine, the recurrence phase (
STRATA_PREFILL_TIMING=1, 3 to 6 runs each):Prompt time, 3 interleaved pairs in each order:
Identity. With the switch unset, the first-token logits and the 32 greedy tokens equal v0.1.40.2 on IQ2_XS after 2K, 8K and 32K (identical bytes; 2K repeated on the final build).
Our NVFP4 fork has shipped these kernels since 0.1.40-nvfp4.3. This PR adds the per-device scratch, which removes the per-call cost that had kept the fork's threshold at 16K tokens.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.