Skip to content

qwen35: use GDN state rows for safe single-sequence plain decode - #407

Merged
bri-prism merged 2 commits into
prismfrom
metal/gdn-rows-plain-20261025
Nov 2, 2026
Merged

bri-prism merged 2 commits into
prismfrom
metal/gdn-rows-plain-20261025

Conversation

@bri-prism

Copy link
Copy Markdown
Collaborator

Depends on #406 (the Metal empty-upload fix); this branch contains that commit too.

Plain Qwen3.5 decode currently gathers and copies the full recurrent state for every GDN layer and token, because rows mode is gated on n_rs_seq > 0 (speculative decoding only). This enables the existing CPU/Metal rows reads and fused writeback for single-token plain decode when exactly one sequence is active and there are no extra recurrent rows, so build_rs_cache_view cannot relocate state. Multi-sequence decode and prefill keep the gathered path. CUDA dispatch is unchanged.

Correctness: greedy token IDs identical to the gathered path on three Qwen3.5-architecture model sizes (1,280/1,280 per model), including parallel, interleaved and shared-prefix multi-sequence cases, CPU weights, rollback snapshots and a two-slot llama-server run; Metal and CPU GATED_DELTA_NET/SET_ROWS test-backend-ops all pass.

Performance (M5 Pro, tg, indicative; candidate bracketed by gathered controls on a shared host, a quiet-window repeat is still pending): decode +3.3%, +11.7% and +8.0% on the small, medium and large model; prefill unchanged.

Empty recurrent-state views can reach async uploads after #393. Metal cannot allocate a zero-length staging buffer.

Assisted-by: Codex
Use rows reads and K=1 scatter for fused single-token decode. Require one active sequence and no extra recurrent rows to avoid relocation ordering hazards.

Assisted-by: Codex
@bri-prism
bri-prism merged commit 62c418c into prism Nov 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant