Skip to content

feat(gpu,arch,spec,quant): DFlash Q4_0, FlashCascade, SenseNova-Loop mHC, external draft models, q4/q2 KV, RDNA3.5 WMMA & AVX-512 - #50

Closed
ybenyedder wants to merge 863 commits into
RustingStudio:mainfrom
ybenyedder:upstream/kv-q4-thinking-budget-tq1
Closed

ybenyedder wants to merge 863 commits into
RustingStudio:mainfrom
ybenyedder:upstream/kv-q4-thinking-budget-tq1

Conversation

@ybenyedder

@ybenyedder ybenyedder commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Native DFlash block-diffusion speculative decoding (src/config.rs, src/gguf.rs, src/gpu_model.rs, src/gpu_model/prefill.rs, src/main.rs, src/model.rs, src/ops.rs): auto-converts HF DFlash safetensors + config.json into native Q4_0 (223.1 MiB, default) or Q8_0 (391.1 MiB) GGUF, extracts concatenated post-layer target hidden states across prefill_chunk / forward, caches persistent DFlash KV across turns, supports lossless greedy (gemv_rows_n 143K shortlist) & Leviathan residual rejection sampling (draft_dist/accept_dist), includes Adaptive Block Controller {8, 12, 16}, and integrates FlashCascade (--spec-type suffix,ngram-simple,ngram-cache with DFlash).
  • Register-only moe_gemv_q, unrolled gemv_f, & strided DeltaNet rollback (src/vulkan/shaders/{moe_gemv_q.comp,gemv_f.comp,deltanet.comp}, src/backend.rs, src/vulkan/{mod.rs,preflight.rs}, src/gpu_model.rs): specializes MAX_NM {1,4,8,17} + dedicated nm <= 4 fast path eliminating register/scratch spills (Scratch size 0), adds gemv_rows_n / upload_raw, and strides DeltaNet state snapshots (SNAP_STRIDE = 4 + exact 0..3 token GPU replay on rollback, saving -738 MB VRAM & -51% DeltaNet kernel time).
  • RDNA 3.5 16x16x16 INT8 coopmat (gemmi_16/gemmi_s_16), 2 GiB expert pools, --kv q4/--kv q2, & Zen 5 AVX-512 VNNI+VBMI: unlocks 100% fast-path GPU expert residency (10240/10240 on 27 GiB unified APU), 256K–1M KV context, --thinking-budget, --short, DeltaNet GEMV dedup, exact MTP shortlist, and AVX-512 Q8_0/Q4_*/Q5_*/IQ4_*/TQ1_0/IQ1_S/IQ2_XXS/IQ3_S kernels.

Verification (AMD Ryzen AI 9 HX 470 + Radeon 890M gfx1150)

  • ./tools/gen_spirv.sh && cargo test --release --lib --bins --tests: all 20 release test suites pass (0 failures, 0 warnings), verified both on fork/main and the squashed PR branch on origin/main (b29ab99).
  • STRATA_VK_STATS=1: Spilled SGPRs 0, Spilled VGPRs 0, Scratch size 0 on all moe_gemv_q, gemv_f, and deltanet pipelines.
  • Greedy --temp 0 parity vs --mtp 0: 100% SHA-256 bit-identical outputs verified across Rust SPSC (-n 256: 13.83 -> 24.49 tok/s), Math --thinking-budget 512 (14.23 -> 30.89 tok/s), accented French prose (14.12 -> 26.86 tok/s), and FlashCascade contextual refactoring (14.18 -> 43.36 tok/s, 72.3% acceptance).
  • bench --gpu --backend vulkan --kv q4 --chunk 512 --tg 256: 14.2 tok/s (--mtp 0) -> 58.5–65.5 tok/s (DFlash Q4_0, 90.4%) -> 66.3–78.6 tok/s (+ FlashCascade).

Wave 4 — Community Architectures & Speculative Decoding (sensenova_loop, External Draft Models & Looped DFlash)

  • Native sensenova_loop (SenseNova-Loop-9B) Architecture:
    • Supports shared-weight looped middle layers (phys_layer mapping virtual layers 28..52 to physical blk.4..27.*) with zero duplicate VRAM allocation via Arc-backed GpuTensor cloning while maintaining independent KV and DeltaNet states across all 56 virtual layers.
    • Implements Manifold-Constrained Hyper-Connections (mHC) with 20-step log-space Sinkhorn-Knopp doubly-stochastic stream mixing (mhc.streams = 2 | 4, mhc.layer_kinds enter/carry/leave phases) across CPU (src/model.rs), Vulkan (hc_mix.comp, hc_write.comp), and CUDA (kernels.cu).
  • Standalone External Draft Model Speculative Decoding (--draft-model <standalone-model.gguf>):
    • Allows any standalone causal LM GGUF sharing the target vocabulary (e.g. nvidia/Qwen3.5-4B-Qwen3.8-27B-Draft, Qwen3.5-0.8B, Qwen3-0.6B) to act as an external speculative drafter (ext_draft in GpuModel) sharing the same GPU device (Backend::share), with cross-turn KV/DeltaNet state reuse (ext_draft_sync_prompt), FlashCascade (hybrid_spec_step) integration, and lossless greedy (--temp 0) / Leviathan rejection sampling (--temp > 0).
  • Looped Multi-Step DFlash Block-Diffusion Refinement (STRATA_DFLASH_STEPS=2..4):
    • Re-anchors prefix positions of the diffusion block with Pass-1 predicted token embeddings and re-runs the shared 6-layer DFlash drafter in-place.

Wave 5 — Register-Zero Vulkan Decode Attention, Reduced-Spill HD=256 Prefill & Chunked mHC Prefill

  • Split-Stage attn_decode (src/vulkan/shaders/attn_decode.comp + attn_decode.spv):
    • Splits K-dot and V-accumulate stages so kr/vr register live ranges do not overlap, achieving Spilled VGPRs 0, Scratch size 0 (Subgroups per SIMD 16) under STRATA_VK_STATS=1 across all tested spec widths ([0,2,..], [0,4,..], [0,8,..]).
  • 2-Register Packed Indexing & Streaming HD>128 attn_prefill (src/vulkan/shaders/attn_prefill.glsl + attn_prefill_{64,128,256}.spv):
    • Packs ri/ci into 2-register r_pack/c_pack bitfields, streams K/V for HD > 128, and adds subgroupMemoryBarrierShared() every 2 tiles, cutting attn_prefill_256 spills from 127 (Scratch size 16384, Latency 340146) to 81 (Scratch size 10496, Latency 197502).
  • Chunked FP16 WMMA Prefill & CLI Inspection for sensenova_loop (src/gpu_model.rs, src/gpu_model/prefill.rs, src/model.rs, src/main.rs):
    • Enables prefill_chunk for mhc_streams > 0 models using non-aliasing stream scratch (hg/mix/mo past total), dense WMMA projections (gemm_dense when cols % 64 == 0), and mhc_load batch sizing (chunk.min(ctx).max(TMAX)).
    • Adds sensenova_loop summary reporting to check subcommand and validates 4-token chunked prefill (chunk=64, short=2), GPU decode, and CPU parity (max_err <= 0.0080, < 1e-2 tolerance).
    • Full cargo test --release --lib --bins --tests: 20 test binaries run (261 passed; 0 failed; 6 ignored bench/external-model tests), 0 compiler warnings.

Wave 6 — Speculative rollback / kernel cleanups (measured neutral)

  • Vk::dtod skips the per-copy barrier inside batch; deltanet supports o == 0 (state-only replay); moe_down_combine hoists xq/xd/sx for nsb == 2 (0 spills, 16 subgroups/SIMD); DeltaNet rollback runs as a graph; dflash_commit_forward batches its 6 layers; FlashCascade can splice an n-gram prefix (order >= 6) into DFlash drafts.
  • A/B on identical prompts, GPU DPM high, --temp 0 -n 256 (Wave 3 27ed6db vs this branch, 2 runs each): decode speed is the same within noise (rust 18.9 vs 18.9-19.0, math 41.3-42.4 vs 41.5-42.1, french 17.0-17.2 vs 17.1-17.2, ctx 50.2-50.3 vs 50.3-50.5 tok/s) and the draft acceptance is identical (174/701, 240/408, 163/791, 241/351). Outputs are byte-identical to a no-draft run (SHA-256 equal on all 4 prompts, baseline 14.1-14.2 tok/s). So Wave 6 is lossless but gives no measurable speedup; an earlier +14.7% figure compared different prompts and is retracted.

Vasyl-Trefilov and others added 30 commits November 6, 2026 11:57
The low 4 bits of a Q3_K sub-block scale come from byte is & 7, shifted
by 4 when is >= 8. It was a select between two byte loads; now it is
one load and a shift. Integer only, so the output is the same bit for
bit (perplexity logprobs of Qwen3-30B-A3B UD-Q2_K_XL at 4096 tokens).

RTX 3060, Qwen3-30B-A3B UD-Q2_K_XL decode at 512 tokens of context,
--mtp 0: 105.6 -> 108.0 tok/s. Prefill is unchanged. The same change in
the Vulkan shader made no difference, so it is not ported.
The two half-float scales at the end of a Q2_K block (rows are 4-aligned)
come from one 4-byte load instead of two 2-byte loads, as Q4_K already
does. The values are the same, so the output is unchanged bit for bit
(perplexity logprobs of Qwen3-30B-A3B UD-Q2_K_XL at 4096 tokens).

RTX 3060, Qwen3-30B-A3B UD-Q2_K_XL decode at 512 tokens of context:
moe_gemv_q2_k median 36.1 -> 35.3 us, decode 107.9 -> 108.5 tok/s.
The rotation angle is a double, and the 3060 runs double math at 1/64
rate. sincos shares the argument reduction of sin and cos and gives the
same values, so the output is unchanged bit for bit (perplexity logprobs
of Qwen3-4B Q4_K_M and Qwen3-30B-A3B UD-Q2_K_XL at 4096 tokens).

rms_norm_rope median on Qwen3-30B-A3B decode: 8.0 -> 7.5 us per layer.
Most of what is left is the double pow of the frequency, which a float
version shows to be about 5 us per layer; a table of the frequencies
made on the GPU before the decode graph is captured would remove it.
rms_norm_rope computed base^(-2i / n_rot) with an f64 pow per element, which consumer
cards run at 1/64 rate. A rope_freq kernel now writes the same values once per (base,
n_rot) and the kernel reads them. A graph captured before the table exists computes them
itself, and the next call captures again with the table. Output is the same bit for bit.

RTX 3060, 512 tokens of context: Qwen3-30B-A3B UD-Q2_K_XL 109.0 to 111.3 tok/s,
Qwen3-4B Q4_K_M 93.2 to 94.3 tok/s.
Signed-off-by: bettercallcaleb <121191527+bettercallcaleb@users.noreply.github.com>
Signed-off-by: bettercallcaleb <121191527+bettercallcaleb@users.noreply.github.com>
…gguf-shards-model-list

fix(serve): hide incomplete GGUF shard sets from model list
# Conflicts:
#	tests/serve.rs
…memory

gemmi_dp asks for 49168 bytes of Workgroup storage with SHARED_TABLES
(the xq/wq double buffers plus the three spec-constant-sized IQ table
arrays), 16 over maxComputeSharedMemorySize (49152) on sm_70. The
NVIDIA driver does not drop the unused table arrays there, so the first
chunked prefill dies with Xid 13 (SKEDCHECK18_L1_CONFIG_TOO_SMALL) and
a lost logical device. Read the tables from the buffer in the
non-cooperative-matrix path instead; load_tables() becomes a no-op when
SHARED_TABLES is not defined.

Verified on a Tesla V100-SXM2-32GB: Qwen3.6-35B-A3B UD-Q2_K_XL on
Vulkan, 4K prefill 1424 tok/s, decode 109 tok/s.
Plan for the fork: keep Vulkan as the working backend on Volta, then port
the CUDA kernels (ldmatrix, mma.m16n8k16, cp.async, warp reduce, int8
tensor cores) behind __CUDA_ARCH__ guards. Results file records the
baseline measured on the V100-SXM2-32GB.
AGENTS.md is the contract: fork rules, branch model, build/test commands,
environment (V100 sm_70, driver 580, CUDA 12.x, Vulkan without cooperative
matrix) and the non-negotiable constraints.

docs/agents/WORKFLOW.md defines the three-step protocol: the analyst opens
the issue with the task contract, the developer implements it on a task
branch and opens a PR, the reviewer verifies against the issue and merges
or sends it back. Labels step:* drive the state.

.opencode/agents/ adds the coordinator (no code, orchestration only) and the
three subagents with their permissions. .github adds the issue and PR
templates.
The fork has its own issue tracker; gh without --repo can resolve to the
upstream remote. Document the explicit --repo target and the fact that
gh repo set-default is already configured.
New sessions in the fork start as the coordinator, which cannot edit files:
the analysis/development/review work is done by the three subagents.
All agent-facing documents, prompts and artifacts are English-only from now
on. Add the planner subagent (Step 0): it decomposes the request into
milestones and tasks and writes the living docs/ROADMAP.md, which the
coordinator keeps updated. AGENTS.md and the workflow document the new step,
the roadmap artifact and the English-only rule.
Produced by the planner from the fork request: goals/non-goals, hard
constraints, status legend, milestone exit criteria, task tables with IDs,
scope, files, size, dependencies, acceptance criteria and empty issue/PR
columns for traceability, plus critical path and risks.

The coordinator owns this document: it updates statuses and issue/PR links
after every verified merge. It supersedes the earlier Italian plan, which is
removed, and the informal issue #1.
Project 'RustingStrata V100' (5) is linked to the repository with a
Roadmap table and a Board view. Fields: Milestone group (M0-M4), Task ID,
Size, Depends on and an extended Status. 36 draft items mirror the tasks;
repository milestones M0-M4 are created for the real issues. The sync
protocol when an issue is opened is documented.
Upstreaming is deferred and not part of the plan for now. Drop the three
upstream tasks (sync job, audit, open PRs), renumber the remaining M4 tasks
(documentation -> M4-T4, release -> M4-T5), and update M4 title, exit
criteria, dependencies, critical path and the non-goals. The GitHub project
and repository milestone #5 are updated to match.
The analyst and developer hit their per-run step limits during the first
M0-T4 round (analysis and implementation). Raise the budgets to 80 and 160.
Record issue #2 / PR #3 and the in-review status for M0-T4 in the roadmap.
* feat(vulkan): account Workgroup shared memory and refuse oversized pipelines

Walk the committed SPIR-V, keep the Workgroup OpVariables and evaluate their
OpTypeArray lengths with the pipeline's specialization map (constants 0..n-1
plus 15 = kv_q8), failing with the opcode on anything unsupported. Vk::new
queries maxComputeSharedMemorySize and logs it on the device line; Vk::pipeline
compares every new pipeline with it and refuses with the kernel, spec, bytes
needed and limit before creating anything (the driver used to accept it and
fault at dispatch, Xid 13 on Volta). STRATA_VK_SMEM_LIMIT overrides the reported
limit so the refusal can be tested without a doctored shader.

* feat(vulkan): preflight the model's pipelines before weights are uploaded

gpu_weight_types derives the weight types a GPU load leaves for the kernels:
upload_type applies Backend::upload's F16 -> F32 and Q4_0/Q5_0 -> Q8_0 rewrites
(experts are copied raw), and the load_part gate (cpu_only, f32_up) is shared
rather than duplicated. Vk::preflight walks the (kernel, spec) pairs each type
reaches, mirroring gemm_raw's COOP split, NT and wpb, and checks them through
the same accounting Vk::pipeline uses: SPIR-V and spec arithmetic only, no
pipeline, model buffer or dispatch. Engine::runner runs it after the backend is
opened and before GpuModel::load_split, so a refusal precedes every weight
upload. The Backend trait gets a no-op default for backends without Workgroup
shared memory.

* feat(cli): add strata check for the Vulkan shared-memory preflight

strata check --model --backend vulkan --device runs the preflight without
loading the model: it lists every checked (kernel, specialization) pair, the
shared-memory limit and the wall-clock cost, and exits non-zero on overflow.
The GPU-free tests assert the measured sizes of the committed SPIR-V
(gemmi_dp: 49152 bytes with Q2_K, 40960 with IQ3_S; the COOP gemmi: 49168) and
the refusal text (kernel, spec, bytes, limit), which Vk::pipeline raises before
it creates anything. The reference-model preflight test skips cleanly without
the model or a Vulkan device.
M0-T4 is merged (cf30f29, issue #2 / PR #3): append the V100 window results
(maxComputeSharedMemorySize, checked pairs, forced-overflow refusal, bench
numbers and the no-regression comparison) and mark the task done.
* test: select test backends with STRATA_TEST_BACKENDS

A comma-separated allow-list lets the Vulkan suites run on this box while
the CUDA backend still panics on NVRTC sm_70. Filtered backends are
reported as SKIP: <name> (filtered) and never opened.

* test(kernels): synthesize finite blocks for every GgmlType

random_tensor now writes d / dmin / m and the IQ1_M packed scale at the
offsets each dequantizer reads, for all 23 types, and asserts every
produced f32 is finite. Adds a GPU-free generator test.

* test(vulkan): add the per-type GGUF matrix

Exercise dequant, GEMV/GEMV-N/GEMV-Q, MoE GEMV, dense and tiled GEMM for
all 23 GgmlType variants with synthetic raw blocks, and print one MATRIX
line per type. Vk::max_shared_bytes exposes the per-type shared-memory
footprint checked by the existing preflight accounting.

* fix(test): match the Vulkan f16 conversion in GEMM references

On the NVIDIA Volta driver the shader's OpFConvert (packFloat2x16)
truncates toward zero, while CUDA's __float2half rounds to nearest even.
References for the f16 GEMM path now use the conversion the running
backend performs; otherwise a 1-ulp input difference reads as a kernel
error. No shader or numerics change.

* docs: record the M0-T5 Vulkan GGUF type matrix

Append the 23-row per-type matrix, both strata check results, both
end-to-end generations, the informational bench and the no-Xid statement
for the V100 Vulkan window.
Saul5662 and others added 8 commits November 17, 2026 18:03
int_dot had no IQ4_NL entry, so routed experts stored as IQ4_NL (the
ffn_down_exps of OrcaRouter Qwen3.8-Flash-Next-Uncensored IQ3_XXS) fell
back to f32 row dequantization in the CPU expert worker.

Add dot_iq4nl against the Q8_K activations like dot_iq4xs: 18-byte
blocks, eight per Q8_K block. The AVX2 version looks up KVALUES_IQ4NL
with pshufb and handles two blocks per step plus an odd tail.
int_dots_match_dequant covers it at 672 values (21 blocks, odd tail).

RTX 3060 + Ryzen 7 5800XT, 8K prompt: CPU worker 75.6 -> 15.9 ms/token,
decode 10.9 -> 31.6 tok/s.
…duct, MTP for Flash-Next and layer splits

- chat page: MCP tools from an mcp.json file (serve --mcp), per-tool switches, confirm step before each call (RustingStudio#18)
- cpu_moe: integer IQ4_NL dot product, scalar and AVX2 (RustingStudio#47)
- experts: a long prompt no longer freezes the placement for the reply (RustingStudio#44)
- mtp: draft head for Qwen3.8-Flash-Next on the GPU (--mtp-model), drafts with a multi-GPU layer split (RustingStudio#38)
- vision: faster CPU encoder, image prompts prefill on the GPU with M-RoPE
- startup warning when the binary has no AVX2 but the CPU does (RustingStudio#44)
- cuda: size_t pointer offsets in moe_combine, STRATA_NVRTC_OPTS (RustingStudio#34)
- docs: LORA.md rewritten for users (RustingStudio#15)
@ybenyedder ybenyedder changed the title feat: 4-bit KV cache (--kv q4), --thinking-budget, --short flag, DeltaNet nsnap, and AVX2 TQ1_0 feat: --kv q4/q2 GPU KV cache, RDNA3/3.5 16x16x16 INT8 coopmat, 2 GiB expert pools, AVX-512 VNNI+VBMI CPU kernels, --thinking-budget & --short Nov 17, 2026
@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch from a7819cd to 4bb0d52 Compare November 17, 2026 22:59
@ybenyedder ybenyedder changed the title feat: --kv q4/q2 GPU KV cache, RDNA3/3.5 16x16x16 INT8 coopmat, 2 GiB expert pools, AVX-512 VNNI+VBMI CPU kernels, --thinking-budget & --short feat: --kv q4/q2, RDNA3.5 16x16x16 INT8 coopmat, 2 GiB pools, AVX-512 VNNI+VBMI (incl. IQ1_S/IQ2_XXS/IQ3_S), DeltaNet GEMV dedup & exact MTP shortlist Nov 18, 2026
@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch 2 times, most recently from 358773f to b32e064 Compare November 18, 2026 09:43
@ybenyedder ybenyedder changed the title feat: --kv q4/q2, RDNA3.5 16x16x16 INT8 coopmat, 2 GiB pools, AVX-512 VNNI+VBMI (incl. IQ1_S/IQ2_XXS/IQ3_S), DeltaNet GEMV dedup & exact MTP shortlist feat: native DFlash block-diffusion, FlashCascade, strided DeltaNet rollback, RDNA3.5 16x16x16 coopmat, --kv q4/q2 & AVX-512 Nov 18, 2026
@Vasyl-Trefilov

Copy link
Copy Markdown
Member

Hi Hi, tysm for contribute, I am reviewing this PR and will merge if everything is fine

@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch from b32e064 to f339543 Compare November 18, 2026 11:31
@ybenyedder ybenyedder changed the title feat: native DFlash block-diffusion, FlashCascade, strided DeltaNet rollback, RDNA3.5 16x16x16 coopmat, --kv q4/q2 & AVX-512 feat(gpu,arch,spec,quant): DFlash Q4_0, FlashCascade, SenseNova-Loop mHC, external draft models, q4/q2 KV, RDNA3.5 WMMA & AVX-512 Nov 18, 2026
@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch 2 times, most recently from 2b33e38 to f133c75 Compare November 18, 2026 12:55
@Vasyl-Trefilov

Vasyl-Trefilov commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

@ybenyedder I see you still working, can you just request review when you finish

@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch from f133c75 to 803c93d Compare November 18, 2026 13:31
…va-Loop mHC, external draft models, q4/q2 KV, RDNA3.5 WMMA & AVX-512
@ybenyedder
ybenyedder force-pushed the upstream/kv-q4-thinking-budget-tq1 branch from 803c93d to 3f3446d Compare November 18, 2026 16:55
Vasyl-Trefilov added a commit that referenced this pull request Nov 18, 2026
Co-authored-by: Andrew Pavlov <100561417+andrew-pavlov-ua@users.noreply.github.com>
@Vasyl-Trefilov

Copy link
Copy Markdown
Member

oh hell, I am so sorry, I did it by accident, I will reopen it, I am so sorry.

@Vasyl-Trefilov

Copy link
Copy Markdown
Member

@ybenyedder GitHub won't let me reopen this: I rewrote main's history, so your branch and main no longer share any commits. Your PR is one commit on top of the old 1.2.5 commit b29ab99. Could you rebase it onto the new main (git rebase --onto /main b29ab99) and open a new PR that links back here? There is one conflict, in src/vulkan/mod.rs. Sorry for the trouble, I am really sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants