[PR #5357] [Engine] DeepSeek: accept an MXFP4 down beside a low-bit gate / up (Unsloth UD-Q2_K_XL) #5401

Open
opened 2026-11-07 16:34:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5357
Author: @R-Okauchi
Created: 11/5/2026
Status: 🔄 Open

Base: main ← Head: dsv41-mxfp4-down


📝 Commits (1)

  • 47cdfc5 DeepSeek engine: a low-bit layer's down may be MXFP4

📊 Changes

7 files changed (+98 additions, -40 deletions)

View changed files

📝 src/dsv41/ds4_gg_cpu.cpp (+4 -2)
📝 src/dsv41/ds4_gguf.cu (+2 -2)
📝 src/dsv41/ds4_gguf.cuh (+3 -2)
📝 src/dsv41/ds4_iq.cu (+27 -3)
📝 src/dsv41/ds4_iq.cuh (+5 -1)
📝 src/dsv41/ds4_model.cu (+7 -2)
📝 tests/dsv41/iq_expert_test.cpp (+50 -28)

📄 Description

Problem and result

Unsloth's dynamic quants of DeepSeek-V4.1-Flash-1017 keep DeepSeek's own MXFP4 for the down matrices of some layers
beside low-bit gate and up. In UD-Q2_K_XL, layers 0-1 are IQ2_XS / IQ2_XS / MXFP4 and layers 15-19 IQ2_S / IQ2_S / MXFP4.
strata-dsv41 0.1.57 (v0.2.11; main has the same engine code) refuses such a pack at load:

layers.0.ffn.experts.: gate / up / down of types IQ2_XS / IQ2_XS / MXFP4 (gate and up must match; MXFP4 does not mix with the others)

With this change it loads and serves that pack on CUDA. For the types the engine already took, the kernels give the
same bits as main's (Validation).

None. It is a focused fix: no default changes, and nothing changes for a pack the engine already loads.

Approach

The low-bit kernels already decode MXFP4 blocks (decode_b, which the light sets use), so what was missing is the down
role taking MXFP4 where a backend has it:

  • ds4_iq.cu: the down role's token, window and prompt-set kernels take MXFP4 (DS4_IQ_SWITCH_DOWN). deq8 gets the
    MXFP4 branch the prompt tiles need; an MXFP4 block there fell through to Q3_K's. block_values / block_bytes /
    name know MXFP4. supported_down() names the down types the low-bit path takes: not MXFP4 on Metal, whose sets have
    no MXFP4 down, so Metal refuses such a pack as before.
  • ds4_gguf.cu: iq_args takes a supported_down() down.
  • ds4_gg_cpu.cpp: the CPU lane computes such a down with ggml-cpu's MXFP4 x Q8_0 dot. An all-MXFP4 layer keeps
    cpu_experts_mx.
  • ds4_model.cu: the load check lets an MXFP4 down beside a low-bit gate / up through where supported_down() does. An
    MXFP4 gate or up still needs the whole layer in MXFP4.
  • tests/dsv41/iq_expert_test.cpp: --down T gives the down matrices a type of their own. The gate / up data and
    inputs stay those of the run without it, so its gate / up checks must give the same numbers.

Validation

Every run is of this branch's tree, built with CUDA 13.0 unless noted.

Passed:

  • ds4_iq_test, RTX 4070 Ti (sm_89, x86-64), main's and this branch's built the same way: main's --dump, then this
    branch's --cmp against it: bit-compare vs golden: 84 buffers, 0 differ -> IDENTICAL, ALL OK. This branch's
    --type 16,17,22,18,21,23,29 --down 39: ALL OK. Its 21 gate / up checks give the default run's numbers exactly, and
    the MXFP4 down's worst errors are 5.7e-08 on the token path (tol 1e-06), 1.8e-03 in the prompt sets (tol 3e-03) and
    8.0e-08 on the CPU lane (tol 1e-05).

  • ds4_iq_test, DGX Spark (GB10, sm_121; the CPU lane on aarch64), built with spark/build_engine.sh's flags and the
    tests on: main's --dump, then this branch's --cmp: bit-compare vs golden: 84 buffers, 0 differ -> IDENTICAL, ALL OK.
    --type 16,17,22,18,21,23,29 --down 39: ALL OK, the 21 gate / up checks the default run's numbers exactly, the MXFP4
    down's worst errors 5.7e-08 on the token path, 1.8e-03 in the prompt sets and 6.0e-08 on the CPU lane (ggml-cpu on
    aarch64).

  • A real UD pack, x86-64: pack_gguf.py with the plain recipe on AtomicChat's build of UD-Q2_K_XL (layer for layer
    the same expert types as Unsloth's), all its shards but the Engram table's. That one is Q5_K, which the Engram reader
    does not take (MXFP8, Q6_K, IQ4_NL), so --engram names the IQ4_NL table the ISTA-DAS sets share. 47,284 tensors:
    MXFP4 16.8 GB, IQ3_XXS 86.7 GB, IQ2_XXS 33.9 GB, IQ2_S 29.0 GB, IQ3_S 19.5 GB, IQ2_XS 5.2 GB. The engine (built for
    sm_120 with packaging/build_dsv41_cuda.sh's flags) on 2 x RTX PRO 5000 Blackwell 48 GB with 125 GiB of RAM loads it:
    6,515 experts on the cards, 8,845 on the CPU lane, a 94.8 GB RAM store. With DS4_STREAM=1 DS4_LANE_CHECK=1 the two
    new formats go through both lanes at load like the others:

    ds4: lane check: IQ2_XS/IQ2_XS/MXFP4 13111296 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.23 (0.0249 of the largest output)
    ds4: lane check: IQ2_XXS/IQ2_XXS/IQ2_XXS 9148416 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.255 (0.0282 of the largest output)
    ds4: lane check: IQ2_XXS/IQ2_XXS/IQ3_XXS 10622976 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.259 (0.0273 of the largest output)
    ds4: lane check: IQ2_S/IQ2_S/MXFP4 13848576 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.264 (0.0245 of the largest output)
    ds4: lane check: IQ2_S/IQ2_S/IQ3_S 12650496 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.294 (0.0304 of the largest output)
    ds4: lane check: IQ2_S/IQ2_S/IQ3_S 12650496 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.277 (0.0268 of the largest output)
    ds4: lane check: IQ3_XXS/IQ3_XXS/IQ3_S 14125056 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.218 (0.0292 of the largest output)
    ds4: lane check: IQ3_XXS/IQ3_XXS/IQ3_XXS 13572096 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.283 (0.0348 of the largest output)
    

    The spread is the same for every format: the two lanes round the activations differently with DS4_IQ_Q8K off.
    Through serve/server.py: chat, a tool call at every reasoning effort, and a replayed tool turn answered correctly.

  • Builds: strata-dsv41 for sm_121 (aarch64, spark/build_engine.sh's configuration) and sm_120 (x86-64);
    ds4_iq_test for sm_89 / sm_120 / sm_121; HIP, ROCm 7.2.4, gfx1151 / gfx1201
    (tools/dsv41/build_hip_linux.sh strata-dsv41 ds4_iq_test); Metal (strata_ds4, macOS 26.4, metal-cpp 26 and
    llama.cpp 3cf03257 as in metal-build.yml); the CPU-only ds4_gg_bench (-DSTRATA_BUILD_DSV41=ON with no GPU
    backend, macOS arm64). No new warnings: where I built main the same way (sm_121, the sm_89 / sm_120 tests, HIP,
    Metal), the touched files give main's warnings, the same ones; on sm_120 they give the two that main has in
    ds4_model.cu (lines 102 and 106) and nothing else; the CPU-only build gives none.

Failed: none observed.

Not run:

  • HIP and Metal on hardware: I have neither an AMD GPU nor a Metal run for this, so HIP is compiled only. On Metal,
    supported_down() keeps such a pack refused, as before.
  • SYCL: the DeepSeek engine has no SYCL build.
  • Other UD sets: only UD-Q2_K_XL's mixes (IQ2_XS and IQ2_S with an MXFP4 down) ran on a real model. The kernel test
    covers the other low-bit types with an MXFP4 down.
  • The UD pack's output quality beyond the chat and tool-call checks: no perplexity or benchmark runs.
  • Greedy outputs of a whole model against main's: on the Spark the engine's VRAM share follows the free memory, which
    moves from run to run (9,621-9,674 of 15,360 experts in VRAM over four runs with --no-expert-cache, main's
    included), so two runs of the same build already write different tokens. The kernel test's bit-for-bit
    comparison above stands in for it.

Limits

  • UD-Q2_K_XL's own Engram table (Q5_K) still cannot be read; it is packed with the ISTA-DAS sets' table instead (above).
  • This makes the UD sets load; it does not make them fast where their CPU-lane experts do not fit the RAM. On the box
    above, about 22 GB of them came from a SATA SSD and it decoded at about 13 tok/s (the ISTA-DAS IQ2_XS set: 70).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5357 **Author:** [@R-Okauchi](https://github.com/R-Okauchi) **Created:** 11/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `dsv41-mxfp4-down` --- ### 📝 Commits (1) - [`47cdfc5`](https://github.com/Niko1221/Strata/commit/47cdfc5c562d5bc3288dad9a8c3a337fd2bf0fc5) DeepSeek engine: a low-bit layer's down may be MXFP4 ### 📊 Changes **7 files changed** (+98 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_gg_cpu.cpp` (+4 -2) 📝 `src/dsv41/ds4_gguf.cu` (+2 -2) 📝 `src/dsv41/ds4_gguf.cuh` (+3 -2) 📝 `src/dsv41/ds4_iq.cu` (+27 -3) 📝 `src/dsv41/ds4_iq.cuh` (+5 -1) 📝 `src/dsv41/ds4_model.cu` (+7 -2) 📝 `tests/dsv41/iq_expert_test.cpp` (+50 -28) </details> ### 📄 Description ## Problem and result Unsloth's dynamic quants of DeepSeek-V4.1-Flash-1017 keep DeepSeek's own MXFP4 for the down matrices of some layers beside low-bit gate and up. In UD-Q2_K_XL, layers 0-1 are IQ2_XS / IQ2_XS / MXFP4 and layers 15-19 IQ2_S / IQ2_S / MXFP4. strata-dsv41 0.1.57 (v0.2.11; main has the same engine code) refuses such a pack at load: ``` layers.0.ffn.experts.: gate / up / down of types IQ2_XS / IQ2_XS / MXFP4 (gate and up must match; MXFP4 does not mix with the others) ``` With this change it loads and serves that pack on CUDA. For the types the engine already took, the kernels give the same bits as main's (Validation). ## Related discussion None. It is a focused fix: no default changes, and nothing changes for a pack the engine already loads. ## Approach The low-bit kernels already decode MXFP4 blocks (`decode_b`, which the light sets use), so what was missing is the down role taking MXFP4 where a backend has it: - `ds4_iq.cu`: the down role's token, window and prompt-set kernels take MXFP4 (`DS4_IQ_SWITCH_DOWN`). `deq8` gets the MXFP4 branch the prompt tiles need; an MXFP4 block there fell through to Q3_K's. `block_values` / `block_bytes` / `name` know MXFP4. `supported_down()` names the down types the low-bit path takes: not MXFP4 on Metal, whose sets have no MXFP4 down, so Metal refuses such a pack as before. - `ds4_gguf.cu`: `iq_args` takes a `supported_down()` down. - `ds4_gg_cpu.cpp`: the CPU lane computes such a down with ggml-cpu's MXFP4 x Q8_0 dot. An all-MXFP4 layer keeps `cpu_experts_mx`. - `ds4_model.cu`: the load check lets an MXFP4 down beside a low-bit gate / up through where `supported_down()` does. An MXFP4 gate or up still needs the whole layer in MXFP4. - `tests/dsv41/iq_expert_test.cpp`: `--down T` gives the down matrices a type of their own. The gate / up data and inputs stay those of the run without it, so its gate / up checks must give the same numbers. ## Validation Every run is of this branch's tree, built with CUDA 13.0 unless noted. **Passed:** - `ds4_iq_test`, RTX 4070 Ti (sm_89, x86-64), main's and this branch's built the same way: main's `--dump`, then this branch's `--cmp` against it: `bit-compare vs golden: 84 buffers, 0 differ -> IDENTICAL`, ALL OK. This branch's `--type 16,17,22,18,21,23,29 --down 39`: ALL OK. Its 21 gate / up checks give the default run's numbers exactly, and the MXFP4 down's worst errors are 5.7e-08 on the token path (tol 1e-06), 1.8e-03 in the prompt sets (tol 3e-03) and 8.0e-08 on the CPU lane (tol 1e-05). - `ds4_iq_test`, DGX Spark (GB10, sm_121; the CPU lane on aarch64), built with `spark/build_engine.sh`'s flags and the tests on: main's `--dump`, then this branch's `--cmp`: `bit-compare vs golden: 84 buffers, 0 differ -> IDENTICAL`, ALL OK. `--type 16,17,22,18,21,23,29 --down 39`: ALL OK, the 21 gate / up checks the default run's numbers exactly, the MXFP4 down's worst errors 5.7e-08 on the token path, 1.8e-03 in the prompt sets and 6.0e-08 on the CPU lane (ggml-cpu on aarch64). - A real UD pack, x86-64: `pack_gguf.py` with the plain recipe on AtomicChat's build of UD-Q2_K_XL (layer for layer the same expert types as Unsloth's), all its shards but the Engram table's. That one is Q5_K, which the Engram reader does not take (MXFP8, Q6_K, IQ4_NL), so `--engram` names the IQ4_NL table the ISTA-DAS sets share. 47,284 tensors: MXFP4 16.8 GB, IQ3_XXS 86.7 GB, IQ2_XXS 33.9 GB, IQ2_S 29.0 GB, IQ3_S 19.5 GB, IQ2_XS 5.2 GB. The engine (built for sm_120 with `packaging/build_dsv41_cuda.sh`'s flags) on 2 x RTX PRO 5000 Blackwell 48 GB with 125 GiB of RAM loads it: 6,515 experts on the cards, 8,845 on the CPU lane, a 94.8 GB RAM store. With `DS4_STREAM=1 DS4_LANE_CHECK=1` the two new formats go through both lanes at load like the others: ``` ds4: lane check: IQ2_XS/IQ2_XS/MXFP4 13111296 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.23 (0.0249 of the largest output) ds4: lane check: IQ2_XXS/IQ2_XXS/IQ2_XXS 9148416 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.255 (0.0282 of the largest output) ds4: lane check: IQ2_XXS/IQ2_XXS/IQ3_XXS 10622976 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.259 (0.0273 of the largest output) ds4: lane check: IQ2_S/IQ2_S/MXFP4 13848576 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.264 (0.0245 of the largest output) ds4: lane check: IQ2_S/IQ2_S/IQ3_S 12650496 B: an expert on the CPU lane vs streamed to CUDA0: 0 of 20480 outputs bit-identical, max |diff| 0.294 (0.0304 of the largest output) ds4: lane check: IQ2_S/IQ2_S/IQ3_S 12650496 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.277 (0.0268 of the largest output) ds4: lane check: IQ3_XXS/IQ3_XXS/IQ3_S 14125056 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.218 (0.0292 of the largest output) ds4: lane check: IQ3_XXS/IQ3_XXS/IQ3_XXS 13572096 B: an expert on the CPU lane vs streamed to CUDA1: 0 of 20480 outputs bit-identical, max |diff| 0.283 (0.0348 of the largest output) ``` The spread is the same for every format: the two lanes round the activations differently with `DS4_IQ_Q8K` off. Through `serve/server.py`: chat, a tool call at every reasoning effort, and a replayed tool turn answered correctly. - Builds: `strata-dsv41` for sm_121 (aarch64, `spark/build_engine.sh`'s configuration) and sm_120 (x86-64); `ds4_iq_test` for sm_89 / sm_120 / sm_121; HIP, ROCm 7.2.4, gfx1151 / gfx1201 (`tools/dsv41/build_hip_linux.sh strata-dsv41 ds4_iq_test`); Metal (`strata_ds4`, macOS 26.4, metal-cpp 26 and llama.cpp 3cf03257 as in `metal-build.yml`); the CPU-only `ds4_gg_bench` (`-DSTRATA_BUILD_DSV41=ON` with no GPU backend, macOS arm64). No new warnings: where I built main the same way (sm_121, the sm_89 / sm_120 tests, HIP, Metal), the touched files give main's warnings, the same ones; on sm_120 they give the two that main has in `ds4_model.cu` (lines 102 and 106) and nothing else; the CPU-only build gives none. **Failed:** none observed. **Not run:** - HIP and Metal on hardware: I have neither an AMD GPU nor a Metal run for this, so HIP is compiled only. On Metal, `supported_down()` keeps such a pack refused, as before. - SYCL: the DeepSeek engine has no SYCL build. - Other UD sets: only UD-Q2_K_XL's mixes (IQ2_XS and IQ2_S with an MXFP4 down) ran on a real model. The kernel test covers the other low-bit types with an MXFP4 down. - The UD pack's output quality beyond the chat and tool-call checks: no perplexity or benchmark runs. - Greedy outputs of a whole model against main's: on the Spark the engine's VRAM share follows the free memory, which moves from run to run (9,621-9,674 of 15,360 experts in VRAM over four runs with `--no-expert-cache`, main's included), so two runs of the same build already write different tokens. The kernel test's bit-for-bit comparison above stands in for it. ## Limits - UD-Q2_K_XL's own Engram table (Q5_K) still cannot be read; it is packed with the ISTA-DAS sets' table instead (above). - This makes the UD sets load; it does not make them fast where their CPU-lane experts do not fit the RAM. On the box above, about 22 GB of them came from a SATA SSD and it decoded at about 13 tok/s (the ISTA-DAS IQ2_XS set: 70). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5401
No description provided.