Repository navigation
feat(ds41): MXFP8 dense weights and exact IQ2_XXS / IQ3_XXS decode (#800 on main) - #813
Merged
Merged
Conversation
…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)
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.
- 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.
…as 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.
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]>
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]>
davide221
force-pushed
the
fix/mxfp8-mmvq-fusion
branch
from
October 5, 2026 22:44
3e97810 to
3ab4893
Compare
davide221
added a commit
that referenced
this pull request
Oct 6, 2026
…hes decode (#815) #813 made batch-invariant MUL_MAT_ID (the DS4.1 DSpark verify) run every token through the single-token MMVQ path, one launch per token, so verify would match decode bit for bit. That also replaced the multi-token MoE kernel (and its gfx1151 expert prefetch) for formats where the MoE kernel already matched decode, and cost 10% of code decode on an R9700 + Ryzen AI Max+ PRO 495 with --profile ds41-gorgon (49.5 -> 44.8 tok/s, identical text). The MoE kernel computes each (token, row) like the generic single-column kernel with one wave per row: same per-lane K walk, one warp reduction. Batch-invariant MUL_MAT_ID now keeps it when the decode launch is that kernel and the batch fits the MoE kernel's per-type width (mmvq_moe_matches_single_column): ROCmFP2, MXFP4, and on the gfx1151 table Q2_K and Q8_0. Multi-wave tables and the specialized single-column launches (gfx1151 fixed-K ROCmFP, the FP4 unroll, the multi-row IQ kernels on AMD) still take the single-token kernel, now in one launch: the tokens become the sample dimension and each block reads its token's expert ids (ids_tokenwise_samples). Expert-bias fusions keep the per-token loop, since the kernel offsets biases by sample. test_ds41_mmid_width_invariance gains ROCmFP2 (type 107) as a contract format, is registered with ctest at five tokens (the DSpark verify width) and runs in the ROCm GPU job. Measured (R9700 + Ryzen AI Max+ PRO 495, ds41-gorgon, ROCMFP2S, two fresh servers each): code decode 44.7-44.9 -> 49.0-49.4 tok/s, 2K decode 30.6-31.0 -> 32.5-32.6, outputs byte-identical. test_ds41_mmid_width_invariance 5 64: every contract case identical in batch-invariant mode on gfx1201 and gfx1151. Co-authored-by: Claude Opus 5.5 <[email protected]>
davide221
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 7, 2026
… into feat/qwen4exp-strix-halo # Conflicts: # server/deps/llama.cpp/gguf-py/gguf/constants.py
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.
Summary
#800 (DS4.1 MXFP8 dense weights, exact IQ2_XXS / IQ3_XXS HIP decode, mixed-type streamed expert cache, batch-invariant DSpark verify) on top of
main, ready to merge there. #800 targetsfeat/ds41-engine, which is 102 commits ahead of and 22 behindmain, so merging it would not reachmain, and its branch does not accept maintainer edits.The ten #800 commits keep their author and content; see #800 for what each one does and its measurements. On top:
test(ds41): the new DS4.1 tests and bench move toserver/test/unitandserver/test/bench, wheremainkeeps them since test(server): unify pytest and CTest execution #805, and two existing test paths that the rebase had reverted point attest/unitagain.fix(cuda): keep MXFP8 out of the fused MMVQ path.ggml_cuda_should_fuse_mul_mat_vec_qaccepted any quantized type, so a one-column MXFP8MUL_MATfollowed by anADDor GLU was fused into MMVQ, which has no MXFP8 kernel, and the server aborted atmmvq.cuon the first one-token step after a 2K-token prompt.test_ds41_mxfp8gains afused_addcase that aborts without the fix and matches bit for bit with it.Impact
With the IQ2_XXS / IQ3_XXS + MXFP8 DS4.1 GGUF on an R9700 + Ryzen AI Max+ PRO 495 (with #811): 2K, 15K and 30.7K-token prompts run end to end (they aborted before 3), code decode 41.7 tok/s, prefill 431 / 607 / 579 tok/s at 2K / 15K / 30.7K. On our internal hard bench the same GGUF answers 164 of 177 with exact decoding, against 141 for the public Q2 at the same size.
Validation
test_ds41_mxfp8(cpu, gpu incl.fused_add),test_moe_expert_slot_stride,test_ds41_mmid_width_invariance,test_rocmfp3_mix_registry,test_server_unit(609),test_deepseek4_unit, on an R9700 + Ryzen AI Max+ PRO 495fused_addwithout fix 3mmvq.cu(exit 134)git merge-tree)Merge order: #812 and #811 first or in either order, then this. #800 can close once this merges.
🤖 Generated with Claude Code