Skip to content

DS4.1: MXFP8 dense weights, exact IQ2_XXS/IQ3_XXS HIP decode, mixed-type streamed cache, batch-invariant DSpark verify - #800

Closed
geometric[bot] wants to merge 10 commits into
Luce-Org:feat/ds41-enginefrom
GeometricAGI:deano/ds41-engine-mxfp8-upstream
Closed

geometric[bot] wants to merge 10 commits into
Luce-Org:feat/ds41-enginefrom
GeometricAGI:deano/ds41-engine-mxfp8-upstream

Conversation

@geometric

@geometric geometric Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Engine support for serving DeepSeek-V4.1-Flash GGUFs whose dense weights keep the checkpoint's native
FP8 and whose routed experts mix stock ggml IQ2_XXS / IQ3_XXS / IQ2_XS per layer, on the Lucebox
(R9700 + Strix Halo). Ten commits on top of feat/ds41-engine (dbb179d); the
ds41-lucebox profile, router bias, protected experts, DSpark and direct_all streaming are used
unchanged. The research tooling these were developed with stays in the GeometricAGI fork.

The main pieces: a new GGML_TYPE_MXFP8 (117) that repacks the model's 32x32 FP8 blocks losslessly
at 8.25 bpw with an exact decode (so attention and shared experts stay native at about Q8_0's size);
a fix to the streamed expert cache for stacks of mixed quant types (slot strides were not whole
blocks of every sharing type, so mixed-type GGUFs decoded to empty text on the cached path);
faster bit-identical IQ2_XXS and IQ3_XXS decode matvecs on HIP (gfx1201 / gfx1151); and
batch-invariant MUL_MAT_ID and whole six-route graphs in the fused verifier, so DSpark verify batches
reproduce single-token decode bit for bit (layered and fused graphs); and a one-line fix to the V4.1
index-selection store, which reserved the candidate-block rows only when its own width exceeded the
candidate window (a condition on the step, not the context), so the hybrid tier's runtime store had
none and the first graph past position 16,384 aborted in ds4_publish_index_selection (the candidate
source runs at compress ratio 1, so its rows are tokens).

With these, a geo-quant allocation of DS4.1-Flash at antirez's public Q2 byte budget scores
164 vs 141 of 177 reasoning items against that Q2 (paired exact McNemar p = 6.6e-5) and decodes
faster on the Lucebox. Model card and files: Geometric-AI/DeepSeek-V4.1-Flash-Lucebox-GGUF.

Impact

Scenario before after gain
Lucebox6 IQ2_XXS routed-expert matvec (rocprofv3, per decode token) 29.4 ms 15.2 ms 1.93x, bit-identical
Lucebox6 IQ3_XXS routed-expert matvec (per decode token) 5.33 ms 3.36 ms 1.59x, bit-identical
Lucebox6, mixed-type GGUF on the 12 GiB streamed expert cache empty text (4.3-5.2 tok/s uncached) correct, 9.6-12.0 tok/s cached path usable
Lucebox6, geo-quant DS4.1 final vs public Q2, same engine, exact decoding 12.2 tok/s 13.4 tok/s +9.6%
Lucebox6, same GGUF, --profile ds41-lucebox + DSpark drafter 13.9 tok/s (bias off) 20.2 tok/s +45% (profile settings change outputs; see Notes)

Implementation

  • GGML_TYPE_MXFP8 (117): 256 E4M3 codes + 8 E8M0 scales per 264-byte block; CPU reference quantize/dequantize/validate; CUDA/HIP register-decode GEMV with F32 activations for up to 8 columns (batch invariant) and an exact BF16 dequant + GEMM for wider batches; gguf-py knows the type.
  • Streamed expert cache: each role's slot stride is rounded up to the lcm of the block sizes sharing it (moe_expert_slot_stride), so layers of different quant types index experts correctly through their views.
  • IQ2_XXS / IQ3_XXS HIP decode matvecs: v_perm sign decode, grid staged in LDS, fixed-K multi-row launch for the DS4.1 shapes (K = 5120 / 2304); integer dot products regrouped only, accumulation order unchanged.
  • bench_ds41_iq_mmid: MUL_MAT_ID timing and output hash at decode width without the model, for kernel work on boxes without the GGUF.
  • Fused verifier route order: tokenwise verify lanes keep all six routed experts in one owner graph (the former LUCE_DS4_TP_NATIVE_ROUTE_WIDTH=1), because the legacy 4 + 2 decomposition sums the routes in another order than the q=1 graph; LUCE_DS4_TP_HEAD4_TAIL2=1 restores it for bisection.
  • Batch-invariant MUL_MAT_ID: under ggml_backend_cuda_set_mmvq_batch_invariant each token of a routed-expert batch runs the single-token path and small batches stay on MMVQ; test_ds41_mmid_width_invariance checks T-token batches against single tokens per format and surface.

Runtime Flags / Configuration

Default-on paths:

  • MXFP8 tensors load and decode wherever the GGUF carries them; no flag.
  • The streamed-cache stride fix and the HIP IQ2_XXS / IQ3_XXS matvecs apply automatically on the shapes they cover.
    Disable path:
  • LUCE_CUDA_MMVQ_MOE_KERNEL=0: previous multi-token MoE kernel outside batch-invariant mode (unchanged behaviour).
  • LUCE_DS4_TP_HEAD4_TAIL2=1: the previous 4 + 2 route decomposition of the fused q>1 verifier (not bit-identical to q=1 decode).
    Debug/profiling-only flags:
  • bench_ds41_iq_mmid and test_ds41_mmid_width_invariance are standalone binaries; no server flags.
    One default changes on every backend: the fused q>1 verifier keeps its six routes in one owner graph
    (the previous LUCE_DS4_TP_NATIVE_ROUTE_WIDTH=1 behaviour). Validated bit-for-bit against q=1 decode on
    CUDA (H200 pair); the ROCm Lucebox run of the same check is listed under Validation when done.

Validation

Check Result
test_ds41_mxfp8 cpu / gpu (exact decode of every code, GEMV <= 2e-7 relative vs double, batch invariance, validation, requantization) pass on CPU, H200, gfx1201, gfx1151
test_moe_expert_slot_stride, test_packed_experts, test_ds41_hc_f32, test_ds41_attention_cuda, test_ds41_fp8_io pass
test_ds41_mmid_width_invariance 3 64 (T-token batch vs single tokens, batch-invariant mode; routed MUL_MAT_ID and dense MUL_MAT) routed IQ2_XXS, IQ2_XS, IQ3_XXS, Q2_K, MXFP4 bit-identical on H200 and R9700 (routed Q8_0 still differs on CUDA); dense BF16/F16/F32/MXFP8/Q8_0 bit-identical on H200
bench_ds41_iq_mmid output hashes, R9700 and Strix identical to the base build for IQ2_XXS and IQ3_XXS
Lucebox6 golden items (canary + 4 reasoning items), new HIP matvecs vs previous engine byte-identical outputs
H200 quality panels, geo-quant final GGUF (exact decoding) vs antirez public Q2 93 vs 86 of 96; 164 vs 141 of 177 (p = 6.6e-5)
H200 panels, final GGUF with the profile's router bias + protected experts + DSpark drafter (exact prefill), before the route-order fix 158 of 177 (94/96, 27/32, 37/49) vs 164 exact (6 vs 12 discordant, p = 0.24; 10 of the 12 are 16K length caps) and vs 141 public Q2 (p = 0.006)
Review fixes (42f1722): wave64 targets compile the IQ multi-row kernel to an inert stub, batch-invariant MUL_MAT_ID only for types with an MMVQ case, MXFP8 cuBLAS gated on BF16 GEMM support, host launch mirrors the kernel guards, test exit status = batch-invariant contract formats only CUDA build (H200) and test_ds41_mmid_width_invariance 3 64: 16/16 contract cases identical, exit 0 (routed Q8_0 reported as a diagnostic); HIP configure + full ggml-hip build for gfx90a (wave64) on the Lucebox toolchain: exit 0; gfx1201/gfx1151 rebuild: exit 0
H200 pair, 8 reasoning items at 8K, greedy, exact prefill, bias off: DSpark drafter vs no-drafter decode of the same engine and graphs, byte for byte layered graphs (LUCE_DS4_FUSED_VERIFY=0 LUCE_DS4_FUSED_HYBRID_DECODE=0): 8/8 identical with the default rollback and with full snapshots; fused graphs (profile defaults): 0/8 before the route-order fix, 8/8 after, verify 26.4 vs 22.7 tok/s

Notes

Methodology: Lucebox6 = Radeon AI PRO R9700 (gfx1201) + Ryzen AI Max 395 Strix Halo (gfx1151), stock
power limits, geo-quant DS4.1-Flash final GGUF (366 GB) with the 12 GiB streamed expert cache; one
warm-up canary then four fixed reasoning prompts, greedy, 8,192-token cap, decode tok/s from the
server's own per-request timing, each arm a fresh server; kernel times from rocprofv3 over a 128-token
decode. H200 panels: 96 + 32 + 49 reasoning items, greedy, high reasoning effort, same engine build
and flags for every arm, paired exact McNemar on the per-item outcomes.

The store fix was found on a single B300 serving the all-native V4.1-Flash GGUF in the hybrid tier
(streamed cold experts): the lossless arm of a gate aborted on a hard-panel item after a 15.6k-token
generation, and a diagnostic build showed layer 20 publishing a [2560, 1] selection into a [512, 10240]
store. Resident loads never hit it because their store is sized for the whole context (18,432 columns).

One PR for the five pieces by maintainer request; each is its own conventional commit, so the
compact-commits bot can fold by type. Suggested order for review: MXFP8, cache stride, HIP matvecs

  • bench, batch-invariant MUL_MAT_ID (branch order). MXFP8 keeps type id 117 (the ids 108-116 are used by the fork's
    research types) so existing GGUFs load; happy to renumber if upstream prefers 108.

Known caveats: --profile ds41-lucebox changes outputs relative to exact decoding (router bias and
protected experts change expert selection; dense prefill is chunk-dependent; the fused whole-model graphs
round differently from the layered ones). The DSpark drafter does not: with the last two commits its output is
byte-identical to the same engine's plain greedy decode on 8/8 traced items, for the layered graphs and for
the fused graphs the profile uses (default rollback included). The two things that made it look otherwise:
the fused verifier summed a q>1 batch's six routed experts as 4 + 2 while the q=1 graph sums them whole, and
with LUCE_DS4_FUSED_HYBRID_DECODE=1 plain decode runs that fused q=1 graph, so a layered verify had no
matching baseline (LUCE_DS4_SPEC_REFERENCE_EXACT matched only because its n=1 forwards take the same fused
graph). The 158/177 panel above was measured before the fix, with the drafter rounding differently from the
no-drafter profile; it needs no gate of its own now. Gotcha kept: LUCE_DS4_FULL_SNAP=1 alone raises q to 6,
which verify refuses; pin LUCE_DS4_SPEC_Q. Lucebox speed with the route-order fix is not yet measured
(the box needs a reboot first: a server killed mid-load left ~65 GiB of host memory pinned).

Two follow-ups left out of this PR on purpose: the batch-invariant MUL_MAT_ID path launches the
single-token kernel once per token from the host rather than through the existing
LUCE_CUDA_MMVQ_MOE_TOKENWISE sample-dimension launch, because that launch bypasses the AMD fixed-K
IQ2_XXS/IQ3_XXS route decode takes (so it would not be bit-identical on the Lucebox); folding the
fixed-K kernels into the sample dimension would cut the launch count at q=5. And MXFP8 products past
8 columns dequantize the weight to BF16 per op, so dense prefill re-converts each MXFP8 tensor per chunk;
a per-tensor BF16 cache would remove that bandwidth. MXFP8 is not in upstream llama.cpp.

DeanoC added 7 commits October 1, 2026 10:03
…8.25 bpw

GGML_TYPE_MXFP8 (117): per row, 256 E4M3 codes with one E8M0 scale per 32
(264 B, 8.25 bpw). The checkpoint's 32x32 FP8 blocks convert losslessly by
repeating each block scale on its rows, so dense weights keep their native
values at about Q8_0's size instead of BF16's.

- Decode is exact everywhere: the E4M3 bits read as FP16 are the value * 2^-8,
  and the E8M0 scale absorbs the 2^8.
- CPU reference quantize/dequantize/validate (NaN codes and scales > 246 are
  rejected) and a vec_dot against F32 activations.
- CUDA/HIP: a register-decode GEMV with F32 activations and output for up to
  8 columns (batch invariant, 3-D channels for the grouped wo_a); wider
  batches dequantize to BF16 (exact) for a BF16 GEMM with F32 accumulation
  and output. No F16 conversion is registered, so no path can underflow small
  scales; no MMVQ/MMQ, and the grouped wo_b path is skipped for this type.
- gguf-py knows the type.
- test_ds41_mxfp8: exact decode of every code through both device paths,
  accuracy against a double reference (GEMV <= 2e-7 relative on H200),
  batch invariance, validation, requantization. Passes on CPU and H200.

(cherry picked from commit 496ddf26568fcb2c6242c048ea18f63b5211907e)
(cherry picked from commit 2a8285d)
… sharing type

Layers of different weight types share the streamed expert slots, each
through its own view whose expert stride is the slot stride; the matvec
kernels index experts in whole quant blocks (stride / type size). The
stride was the largest expert of the role, which is not a multiple of the
smaller types' block sizes (a 4,515,840 B IQ3_XXS gate slot is 68,421.8
IQ2_XXS blocks), so every layer with another type read wrong expert
offsets: a conditioned DS4.1 GGUF with per-layer types decoded to empty
text on the cached path while the uniform public Q2 was fine.

Round each role's stride up to the lcm of the block sizes sharing it
(moe_expert_slot_stride): +31 KB per gate/up slot, +0.9 MB per down slot
for the DS4.1 conditioned mix.

Lucebox 6, conditioned MXFP8-dense GGUF, 12 GiB cache on the Strix:
canary correct, coherent output (matches the uncached text for the first
480 characters), decode 9.6-12.0 tok/s against 4.3-5.2 uncached.

(cherry picked from commit 4f409550c16d2e67037380277498bda6fac387ff)
(cherry picked from commit 64ab306)
…ixed-K launch

Found by a geo-evo run on Lucebox 6 (target lucebox_ds41_iq2xxs_mmvq,
geo-evo e41f0ca, iteration 3). On HIP the resident IQ2_XXS expert matvec was
VALU bound on the per-byte sign expansion; every grid byte is 8, 25 or 43,
so the signed grid is selected with v_perm_b32 (selector from one carry-free
multiply plus the popcount parity), the grid table is staged in LDS, and the
DS4.1 shapes (K = 5120 / 2304) use a fixed-K launch with several one-wave
rows per workgroup. Integer dot products are bit-identical and each row's
float accumulation and wave-reduction order is unchanged; other targets keep
the existing code.

Lucebox 6 (gfx1201 + gfx1151, conditioned MXFP8-dense DS4.1, 12 GiB Strix
stream cache): IQ2_XXS matvec time 29.4 -> 15.2 ms/token (1.93x, rocprofv3);
canary and all four golden answers byte-identical to the previous engine;
decode 10.4-12.2 -> 12.1-13.9 tok/s. CUDA builds; test_ds41_mxfp8 passes on
H200, gfx1201 and gfx1151.

(cherry picked from commit 688ffe7134004d9dd59aa96da35f2b7ca2c695db)
(cherry picked from commit a7b02b7)
…t the model

MUL_MAT_ID at decode width (1 token, 6 of E experts) for IQ3_XXS and IQ2_XXS on DS4.1's gate/up
and down shapes, on every GPU: median/best time per op over chained nodes and an FNV hash of the
outputs for bit-exactness against a baseline build. Lets kernel work continue on a box without the
150 GB GGUF.

(cherry picked from commit 00871ce71030860c3e24ba83ff30a96dc5ce8f39)
(cherry picked from commit 3968f9e)
…aunch

The IQ3_XXS decode matvec reuses the IQ2_XXS path (one 8-byte index load, perm-based sign
expansion, 1 KiB grid in LDS, 8 waves x 2 rows per workgroup, packed K=2304 tail, DPP reduction);
integer dot products are regrouped only, so outputs are bit-identical.

Measured (geo-evo lucebox_ds41_iq3xxs_mmvq c2): lucebox6 full DS4.1 decode, IQ3_XXS kernel time
5334 -> 3358 us/token with the exact-token gate passing; lucebox5 bench_ds41_iq_mmid (6 of 64
experts, 1 token), identical output hashes to the base: R9700 down 113.0 -> 58.3 us (1.94x),
gate/up 91.3 -> 57.9 us (1.58x); Strix down 214.2 -> 124.3 us (1.72x), gate/up 159.7 -> 128.5 us
(1.24x); IQ2_XXS unchanged. The LDS sign-selector variant (c3) measured no faster.

(cherry picked from commit 307a6ea246f32e0cbf561bb7db718e4949b6847c)
(cherry picked from commit 4ee10b6)
…on routed experts

Verification sets ggml_backend_cuda_set_mmvq_batch_invariant and documents every
verified token as bit-identical to plain decode, but the width-invariant launch
excluded MUL_MAT_ID: a multi-token routed-expert product went to the dedicated MoE
kernel (or MMQ past the per-type MMVQ limit), which reduces in another order than
the single-token decode kernel (and on HIP bypasses the IQ2_XXS/IQ3_XXS fixed-K
decode kernels, which apply at one column only). In batch-invariant mode each token
of a MUL_MAT_ID now runs the single-token path, and small batches stay on MMVQ.

test_ds41_mmid_width_invariance compares a T-token batch with T single-token
products bit for bit per expert format and DS4.1 surface. H200 (sm_90), T = 2..5:
IQ2_XXS, IQ2_XS, IQ3_XXS, Q2_K and MXFP4 differ without the fix and match with it;
Q8_0 routed experts still differ (another dispatch; not used by DS4.1 plans).

(cherry picked from commit 91a6cb9)
BF16 output head, F16 indexer/compressor, F32 router, MXFP8 and Q8_0 MUL_MAT: under
ggml_backend_cuda_set_mmvq_batch_invariant all are bit-identical between a q-wide batch
and single columns on sm_90; without it the BF16/F16 products differ.

(cherry picked from commit 751c63e5)
@DeanoC
DeanoC force-pushed the deano/ds41-engine-mxfp8-upstream branch from 751c63e to f582053 Compare October 1, 2026 15:48
The fused verify graph represented the six routed experts of a q>1 batch as a
4 + 2 decomposition (head and tail owner graphs added afterwards), while the q=1
graph sums all six routes in one combine. The two orders round differently, so
a DSpark verify built with the decomposition was not bit-identical to the fused
q=1 decode it is documented to match: on an H200 pair with DS4.1-Flash the first
differing cache bytes appear at layer 1 of the first verify, and greedy traces
with the drafter diverge from plain decode on 8 of 8 items. With whole routes
(formerly opt-in through LUCE_DS4_TP_NATIVE_ROUTE_WIDTH) the q=3 verify and the
q=1 decode agree bit for bit at every compared cache field and argmax.

Tokenwise verify lanes (hc_staggered_pre models) now keep the routes whole by
default; LUCE_DS4_TP_HEAD4_TAIL2=1 restores the decomposition for bisection.
The layered verify path was unaffected: against a layered decode baseline
(LUCE_DS4_FUSED_VERIFY=0 LUCE_DS4_FUSED_HYBRID_DECODE=0) the drafter is
byte-identical on 8 of 8 items with the default rollback.
@davide221 davide221 changed the title DS4.1: MXFP8 dense weights, exact IQ2_XXS/IQ3_XXS HIP decode, mixed-type streamed cache, batch-invariant DSpark verify feat(ds41): MXFP8 dense weights, exact IQ2_XXS/IQ3_XXS HIP decode, mixed-type streamed cache, batch-invariant DSpark verify Oct 2, 2026
@davide221
davide221 marked this pull request as ready for review October 2, 2026 12:43
@geometric geometric Bot changed the title feat(ds41): MXFP8 dense weights, exact IQ2_XXS/IQ3_XXS HIP decode, mixed-type streamed cache, batch-invariant DSpark verify DS4.1: MXFP8 dense weights, exact IQ2_XXS/IQ3_XXS HIP decode, mixed-type streamed cache, batch-invariant DSpark verify Oct 5, 2026
- mmvq: the IQ2_XXS/IQ3_XXS multi-row block is a wave32 kernel; a wave64 target
  (gfx9) now compiles it to an inert stub instead of failing a static_assert, and
  the host launch requires wave32 plus the kernel's own one-wave/one-row table
  conditions so a mismatch is declined rather than launched.
- ggml-cuda: batch-invariant MUL_MAT_ID routes to MMVQ only for types that have an
  MMVQ case (the mix formats keep their own dispatch instead of aborting); the
  MXFP8 cuBLAS branch is gated on BF16 GEMM support and its comments say that
  wide batches round the activations to BF16 (the <=8-column GEMV keeps F32).
- test_ds41_mmid_width_invariance: only the batch-invariant mode of the contract
  formats decides the exit status; the non-invariant runs and routed Q8_0 (known
  to differ on CUDA) are diagnostics. H200: 16/16 contract cases identical, exit 0.
- fused verify: the whole-routes decision for tokenwise lanes is computed once
  per graph next to the lane count.
…never the model has a candidate source

The candidate source publishes [top_k + candidate_topk_blocks, n] once a query sees more
than candidate_topk_blocks * candidate_block_size rows: a condition on the context at
that layer's ratio (V4.1-Flash: ratio 1 at layer 20, so from position 16,384 inside an
18,432 context). Ds4IndexSelectionStore::ensure reserved those rows only when its column
count exceeded that product, a condition on the step width that happens to hold for the
load-time store (18,432 columns) and not for the hybrid step's runtime store (10,240).
The first hybrid-path graph past position 16,384 then aborted in
ds4_publish_index_selection (selection [2560, 1] into a [512, 10240] store; reproduced
on the B300 with a diagnostic build, 2026-10-05). Reserve the rows whenever the model has
a candidate source: 8 KiB per column.
@davide221

Copy link
Copy Markdown
Contributor

One crash with the final MXFP8 GGUF, with a one-line fix.

ggml_cuda_should_fuse_mul_mat_vec_q accepts any ggml_is_quantized type, and MXFP8 counts as quantized. So a single-column MXFP8 MUL_MAT followed by an ADD or GLU gets fused into MMVQ, which has no MXFP8 kernel, and it aborts at the default: of mul_mat_vec_q_switch_type (mmvq.cu). We hit it on the first one-token step after a 2K-token prefill, running this branch on top of #811. Multi-column verify steps skip that fusion, so short prompts were fine.

-    bool use_mul_mat_vec_q = ggml_is_quantized(src0->type) && !bad_padding_clear && src1->type == GGML_TYPE_F32 &&
+    // MXFP8 has its own matvec (ggml_cuda_mxfp8_mul_mat_vec); MMVQ has no kernel for it.
+    bool use_mul_mat_vec_q = ggml_is_quantized(src0->type) && src0->type != GGML_TYPE_MXFP8 && !bad_padding_clear &&
+                             src1->type == GGML_TYPE_F32 &&

With it, the final GGUF runs 2K, 15K and 30.7K prompts end to end on an R9700 + Ryzen AI Max box, with coherent outputs. Happy to push it to the branch if you turn on maintainer edits.

@davide221

Copy link
Copy Markdown
Contributor

Opened it as a follow-up stacked on this branch, with a regression test: #813.

@davide221

Copy link
Copy Markdown
Contributor

Rebased onto main in #813 so it can land there (this PR targets feat/ds41-engine, which is 102 commits ahead of and 22 behind main). Your ten commits keep their authorship; on top: the 107-character subject shortened, the new tests moved to main's server/test/unit layout, and the MXFP8 fused-MMVQ fix with its regression test.

@davide221 davide221 closed this Oct 6, 2026
davide221 added a commit that referenced this pull request Oct 6, 2026
 on main) (#813)

* feat(ggml): MXFP8 type keeps DS4.1 native FP8 dense weights exact at 8.25 bpw

GGML_TYPE_MXFP8 (117): per row, 256 E4M3 codes with one E8M0 scale per 32
(264 B, 8.25 bpw). The checkpoint's 32x32 FP8 blocks convert losslessly by
repeating each block scale on its rows, so dense weights keep their native
values at about Q8_0's size instead of BF16's.

- Decode is exact everywhere: the E4M3 bits read as FP16 are the value * 2^-8,
  and the E8M0 scale absorbs the 2^8.
- CPU reference quantize/dequantize/validate (NaN codes and scales > 246 are
  rejected) and a vec_dot against F32 activations.
- CUDA/HIP: a register-decode GEMV with F32 activations and output for up to
  8 columns (batch invariant, 3-D channels for the grouped wo_a); wider
  batches dequantize to BF16 (exact) for a BF16 GEMM with F32 accumulation
  and output. No F16 conversion is registered, so no path can underflow small
  scales; no MMVQ/MMQ, and the grouped wo_b path is skipped for this type.
- gguf-py knows the type.
- test_ds41_mxfp8: exact decode of every code through both device paths,
  accuracy against a double reference (GEMV <= 2e-7 relative on H200),
  batch invariance, validation, requantization. Passes on CPU and H200.

(cherry picked from commit 496ddf26568fcb2c6242c048ea18f63b5211907e)
(cherry picked from commit 2a8285d)

* fix(ds4): streamed expert cache slot strides in whole blocks of every sharing type

Layers of different weight types share the streamed expert slots, each
through its own view whose expert stride is the slot stride; the matvec
kernels index experts in whole quant blocks (stride / type size). The
stride was the largest expert of the role, which is not a multiple of the
smaller types' block sizes (a 4,515,840 B IQ3_XXS gate slot is 68,421.8
IQ2_XXS blocks), so every layer with another type read wrong expert
offsets: a conditioned DS4.1 GGUF with per-layer types decoded to empty
text on the cached path while the uniform public Q2 was fine.

Round each role's stride up to the lcm of the block sizes sharing it
(moe_expert_slot_stride): +31 KB per gate/up slot, +0.9 MB per down slot
for the DS4.1 conditioned mix.

Lucebox 6, conditioned MXFP8-dense GGUF, 12 GiB cache on the Strix:
canary correct, coherent output (matches the uncached text for the first
480 characters), decode 9.6-12.0 tok/s against 4.3-5.2 uncached.

(cherry picked from commit 4f409550c16d2e67037380277498bda6fac387ff)
(cherry picked from commit 64ab306)

* perf(hip): IQ2_XXS decode matvec with v_perm sign decode, LDS grid, fixed-K launch

Found by a geo-evo run on Lucebox 6 (target lucebox_ds41_iq2xxs_mmvq,
geo-evo e41f0ca, iteration 3). On HIP the resident IQ2_XXS expert matvec was
VALU bound on the per-byte sign expansion; every grid byte is 8, 25 or 43,
so the signed grid is selected with v_perm_b32 (selector from one carry-free
multiply plus the popcount parity), the grid table is staged in LDS, and the
DS4.1 shapes (K = 5120 / 2304) use a fixed-K launch with several one-wave
rows per workgroup. Integer dot products are bit-identical and each row's
float accumulation and wave-reduction order is unchanged; other targets keep
the existing code.

Lucebox 6 (gfx1201 + gfx1151, conditioned MXFP8-dense DS4.1, 12 GiB Strix
stream cache): IQ2_XXS matvec time 29.4 -> 15.2 ms/token (1.93x, rocprofv3);
canary and all four golden answers byte-identical to the previous engine;
decode 10.4-12.2 -> 12.1-13.9 tok/s. CUDA builds; test_ds41_mxfp8 passes on
H200, gfx1201 and gfx1151.

(cherry picked from commit 688ffe7134004d9dd59aa96da35f2b7ca2c695db)
(cherry picked from commit a7b02b7)

* bench(ds4): routed-expert decode matvec timing and output hash without the model

MUL_MAT_ID at decode width (1 token, 6 of E experts) for IQ3_XXS and IQ2_XXS on DS4.1's gate/up
and down shapes, on every GPU: median/best time per op over chained nodes and an FNV hash of the
outputs for bit-exactness against a baseline build. Lets kernel work continue on a box without the
150 GB GGUF.

(cherry picked from commit 00871ce71030860c3e24ba83ff30a96dc5ce8f39)
(cherry picked from commit 3968f9e)

* perf(hip): IQ3_XXS decode matvec on the IQ2_XXS shared-grid fixed-K launch

The IQ3_XXS decode matvec reuses the IQ2_XXS path (one 8-byte index load, perm-based sign
expansion, 1 KiB grid in LDS, 8 waves x 2 rows per workgroup, packed K=2304 tail, DPP reduction);
integer dot products are regrouped only, so outputs are bit-identical.

Measured (geo-evo lucebox_ds41_iq3xxs_mmvq c2): lucebox6 full DS4.1 decode, IQ3_XXS kernel time
5334 -> 3358 us/token with the exact-token gate passing; lucebox5 bench_ds41_iq_mmid (6 of 64
experts, 1 token), identical output hashes to the base: R9700 down 113.0 -> 58.3 us (1.94x),
gate/up 91.3 -> 57.9 us (1.58x); Strix down 214.2 -> 124.3 us (1.72x), gate/up 159.7 -> 128.5 us
(1.24x); IQ2_XXS unchanged. The LDS sign-selector variant (c3) measured no faster.

(cherry picked from commit 307a6ea246f32e0cbf561bb7db718e4949b6847c)
(cherry picked from commit 4ee10b6)

* fix(ds4): batch-invariant MUL_MAT_ID so DSpark verify matches decode on routed experts

Verification sets ggml_backend_cuda_set_mmvq_batch_invariant and documents every
verified token as bit-identical to plain decode, but the width-invariant launch
excluded MUL_MAT_ID: a multi-token routed-expert product went to the dedicated MoE
kernel (or MMQ past the per-type MMVQ limit), which reduces in another order than
the single-token decode kernel (and on HIP bypasses the IQ2_XXS/IQ3_XXS fixed-K
decode kernels, which apply at one column only). In batch-invariant mode each token
of a MUL_MAT_ID now runs the single-token path, and small batches stay on MMVQ.

test_ds41_mmid_width_invariance compares a T-token batch with T single-token
products bit for bit per expert format and DS4.1 surface. H200 (sm_90), T = 2..5:
IQ2_XXS, IQ2_XS, IQ3_XXS, Q2_K and MXFP4 differ without the fix and match with it;
Q8_0 routed experts still differ (another dispatch; not used by DS4.1 plans).

(cherry picked from commit 91a6cb9)

* test(ds4): width invariance of the dense verify-batch products

BF16 output head, F16 indexer/compressor, F32 router, MXFP8 and Q8_0 MUL_MAT: under
ggml_backend_cuda_set_mmvq_batch_invariant all are bit-identical between a q-wide batch
and single columns on sm_90; without it the BF16/F16 products differ.

(cherry picked from commit 751c63e5)

* fix(ds4): keep all six routes in one graph for tokenwise verify lanes

The fused verify graph represented the six routed experts of a q>1 batch as a
4 + 2 decomposition (head and tail owner graphs added afterwards), while the q=1
graph sums all six routes in one combine. The two orders round differently, so
a DSpark verify built with the decomposition was not bit-identical to the fused
q=1 decode it is documented to match: on an H200 pair with DS4.1-Flash the first
differing cache bytes appear at layer 1 of the first verify, and greedy traces
with the drafter diverge from plain decode on 8 of 8 items. With whole routes
(formerly opt-in through LUCE_DS4_TP_NATIVE_ROUTE_WIDTH) the q=3 verify and the
q=1 decode agree bit for bit at every compared cache field and argmax.

Tokenwise verify lanes (hc_staggered_pre models) now keep the routes whole by
default; LUCE_DS4_TP_HEAD4_TAIL2=1 restores the decomposition for bisection.
The layered verify path was unaffected: against a layered decode baseline
(LUCE_DS4_FUSED_VERIFY=0 LUCE_DS4_FUSED_HYBRID_DECODE=0) the drafter is
byte-identical on 8 of 8 items with the default rollback.

* fix(cuda): review fixes for the DS4.1 engine changes

- mmvq: the IQ2_XXS/IQ3_XXS multi-row block is a wave32 kernel; a wave64 target
  (gfx9) now compiles it to an inert stub instead of failing a static_assert, and
  the host launch requires wave32 plus the kernel's own one-wave/one-row table
  conditions so a mismatch is declined rather than launched.
- ggml-cuda: batch-invariant MUL_MAT_ID routes to MMVQ only for types that have an
  MMVQ case (the mix formats keep their own dispatch instead of aborting); the
  MXFP8 cuBLAS branch is gated on BF16 GEMM support and its comments say that
  wide batches round the activations to BF16 (the <=8-column GEMV keeps F32).
- test_ds41_mmid_width_invariance: only the batch-invariant mode of the contract
  formats decides the exit status; the non-invariant runs and routed Q8_0 (known
  to differ on CUDA) are diagnostics. H200: 16/16 contract cases identical, exit 0.
- fused verify: the whole-routes decision for tokenwise lanes is computed once
  per graph next to the lane count.

* fix(ds4): reserve index-selection candidate rows whenever the model has a candidate source

The candidate source publishes [top_k + candidate_topk_blocks, n] once a query sees more
than candidate_topk_blocks * candidate_block_size rows: a condition on the context at
that layer's ratio (V4.1-Flash: ratio 1 at layer 20, so from position 16,384 inside an
18,432 context). Ds4IndexSelectionStore::ensure reserved those rows only when its column
count exceeded that product, a condition on the step width that happens to hold for the
load-time store (18,432 columns) and not for the hybrid step's runtime store (10,240).
The first hybrid-path graph past position 16,384 then aborted in
ds4_publish_index_selection (selection [2560, 1] into a [512, 10240] store; reproduced
on the B300 with a diagnostic build, 2026-10-05). Reserve the rows whenever the model has
a candidate source: 8 KiB per column.

* test(ds41): keep the DS4.1 tests and bench in main's test layout

Main keeps unit tests in server/test/unit and benches in
server/test/bench. Move the MXFP8 width-invariance test and the IQ
MUL_MAT_ID bench there, and point the registry and Laguna daemon
checks back at their test/unit paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(cuda): keep MXFP8 out of the fused MMVQ path

ggml_cuda_should_fuse_mul_mat_vec_q accepted any ggml_is_quantized type,
and MXFP8 counts as quantized, so a one-column MXFP8 MUL_MAT followed by
an ADD or GLU was fused into MMVQ. MMVQ has no MXFP8 kernel and aborts at
the default case of mul_mat_vec_q_switch_type. MXFP8 now keeps its own
GEMV there.

test_ds41_mxfp8 gains fused_add: a one-column MXFP8 product feeding an
ADD, checked bit for bit against the plain product plus the bias. It
aborts without the fix and passes with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Deano Calver <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants