qwen35 : in-place recurrent state rows for plain decode (GGML_GDN_ROWS_PLAIN=1) - #276
Open
jasontitus wants to merge 2 commits into
Open
jasontitus wants to merge 2 commits into
jasontitus wants to merge 2 commits into
Conversation
…S_PLAIN=1) The rows path of the gated delta net (the fused op reads and writes the per-sequence state rows of the cache) is used today only when n_rs_seq > 0 (speculative contexts with snapshots). Plain decode instead gathers each layer's state, runs the recurrence, and copies it back: 10-14% of a decode token on the Bonsai models (M5 Max per-op profile). GGML_GDN_ROWS_PLAIN=1 takes the rows path for plain decode too, with one snapshot slot (K = 1); the output is bitwise identical. - only when no extra cells are relocated (n_rs == n_seqs): the relocation in build_rs_cache_view runs before the GDN read and, after a cell reorder, could overwrite a row another sequence reads (the gathered path reads first); graph reuse compares the s_copy_extra size, so such a batch rebuilds and takes the gathered path - GGML_GDN_ROWS_PLAIN_MAX_TOKENS caps it by tokens per sequence (on an A19 the in-place recurrence is ~18% slower at 512-token prefill); contexts with n_rs_seq > 0 keep rows mode at every width - off by default; read per context Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHqq1nTe46u7euASncLsee
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHqq1nTe46u7euASncLsee
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.
Overview
The fused gated delta net has a rows mode that reads and writes each sequence's state rows in the recurrent cache in place. Today it is used only when
n_rs_seq > 0(speculative contexts with snapshots). Plain decode gathers every layer's state, runs the recurrence, and copies the state back; on the Bonsai 2 models that is 10-14% of a decode token on an M5 Max.With
GGML_GDN_ROWS_PLAIN=1, plain decode takes the rows path too, with one snapshot slot (K = 1). Output is bitwise identical. Off by default.n_rs == n_seqs): the relocation inbuild_rs_cache_viewruns before the GDN read and, after a cell reorder, could overwrite a row another sequence reads (the gathered path reads first). Graph reuse compares thes_copy_extrasize, so such a batch rebuilds and takes the gathered path.GGML_GDN_ROWS_PLAIN_MAX_TOKENS=Nlimits it to at most N tokens per sequence: on an A19 the in-place recurrence op is ~18% slower at 512-token prefill while decode gains. Contexts withn_rs_seq > 0keep rows mode at every width, as today.delta-net-base.cppaccepts rows mode without snapshots (the assert that requiredn_rs_seq > 0becomes thekeepcondition).Related: #207 does an in-place GDN update for the CPU backend with a new op. This PR only reuses the existing rows path (Metal) for plain decode; the two touch the same lines in
qwen35.cppanddelta-net-base.cpp.Additional information
M5 Max, Ternary Bonsai 2 27B PTQ1_0, this branch, switch off vs on, three A-B-B-A quartets with 8 s cooldowns (tok/s; llama-server rates are aggregate over the requests, 128 greedy tokens):
Generated tokens identical in every pair. Every logit bitwise equal off vs on for 96 single-token decodes plus 12 batches of 4 on PTQ1_0, Q1_0 and PQ2_0 Bonsai models.
Requirements