[PR #265] [MERGED] EXL3: exllamav3 1.6's half-integer bitrates (K 1.5 / 2.5 / 3.5) - every decoder bit for bit exllamav3's #434

Closed
opened 2026-10-29 21:25:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/265
Author: @sociolog
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @mw00

Base: main ← Head: exl3-half-k


📝 Commits (1)

  • 986ca21 EXL3: exllamav3 1.6's half-integer bitrates (K 1.5 / 2.5 / 3.5) - every decoder bit for bit exllamav3's

📊 Changes

24 files changed (+1108 additions, -676 deletions)

View changed files

➕ data/exl3-exllamav3/exl3_k2_3_cb2.bin (+0 -0)
➕ data/exl3-exllamav3/exl3_k2_5_cb2.bin (+0 -0)
➕ data/exl3-exllamav3/exl3_k2_7_cb2.bin (+0 -0)
📝 include/strata/core/glm_model.hpp (+2 -2)
📝 include/strata/kernels/cpu/exl3_cpu.hpp (+8 -5)
📝 include/strata/kernels/cpu/exl3_ref.hpp (+8 -4)
📝 include/strata/kernels/exl3.hpp (+18 -7)
📝 src/core/glm_fast_path.cu (+6 -6)
📝 src/core/glm_model.cu (+62 -21)
📝 src/core/glm_prefill.cu (+2 -2)
📝 src/ds4/ds4_gguf.cu (+5 -4)
📝 src/ds4/ds4_gguf.cuh (+7 -5)
📝 src/ds4/ds4_model.cu (+36 -28)
📝 src/kernels/cpu/exl3_cpu.cpp (+337 -180)
📝 src/kernels/cpu/exl3_cpu_bench.cpp (+32 -19)
📝 src/kernels/cpu/exl3_ref.cpp (+10 -6)
📝 src/kernels/cuda/exl3.cu (+182 -131)
📝 src/kernels/cuda/exl3_legacy.cu (+88 -75)
📝 tests/ds4_cpu_bench.cpp (+1 -1)
📝 tests/ds4_gguf_test.cu (+4 -4)

...and 4 more files

📄 Description

Rebased on main (456a5ca, after v1.1.18) now that #264 has merged: one commit, 986ca21. Since v1.1.16 added maya-ds4,
the rebase also moves its EXL3 path to k2 (the bullet below the device kernels).

What

exllamav3 1.6 writes half-integer bitrates K = KA + 0.5 - 24 / 40 / 56 int16 words a 16x16 tile, the mul1 codebook
only - where a self-calibrated quant's budget for a layer falls between two integer widths (e.g. a community SC 4.05 of
Qwen3.8-Flash-Next has K 3.5 gate / up in 8 of its MoE layers). Their trellis steps alternate KA bits (even step) and
KA + 1 (odd step), so step p's 16-bit window ends at

S(p) = floor((p + 1) k2 / 2),   k2 = 2 K

which is (p + 1) K for an integer K as well. Today tools/exl3_pack.py refuses such a model ("half-integer bitrate ...
not supported yet") and the engine and its kernels take K 1..8. This makes every path take K 1.5 / 2.5 / 3.5.

  • The bitrate is k2 = 2 K everywhere: exl3::Mat::k2, ExpertLayout::k2[3], cpu::Exl3Part::k2, the pack's
    matrices and layers, trellis_bytes -> trellis_bytes_k2, exl3_inner -> exl3_inner_k2 (renamed, so no caller
    passes a K where a k2 is meant). k2_supported(k2, cb): K 1..8 with any codebook, 1.5 / 2.5 / 3.5 with mul1.
  • The pack and its reader. The packer takes a tile's words as k2 (a half K without mul1, or a width that is no
    bitrate, refused by name) and writes such a K as 3.5 in exl3.txt. Integer packs are written byte for byte as
    before. The engine reads K or K.5 (by hand, so no locale's decimal point matters), checks every matrix and layer
    part against k2_supported at load (and that a layer's gate and up have one K, as the blob's layout needs), and
    sizes each part from k2 (16 k2 bytes a tile), every layer its own. An engine from before this change refuses a 3.5
    line ("exl3.txt: bad mat line" / "bad layer line") instead of misreading it.
  • Device kernels (exl3.cu): frag8 takes K2; an odd K2 decodes through frag8_half - exllamav3's dq8_half: a
    lane's 8 steps start even, so their windows end at S(p + 7) = (p / 2 + 4) K2 and then KA + 1, KA, KA + 1, ... bits
    earlier; four windows span 18 + 3 KA <= 27 bits, one funnel shift of two words for each group of four. One change for
    the decode GEMV, the routed experts, the verify window, the prompt path's tensor-core set kernels and its decoded W'.
    dispatch instantiates K 1..8 x 3 codebooks and the half K with mul1 (three more instances of each kernel), and
    refuses anything else before a launch. exl3_legacy.cu (GPUs before sm_80): state_at takes S(p).
  • maya-ds4 (DeepSeek-V4.1-Flash, added in v1.1.16): its EXL3 matrices and experts take k2 from the trellis (8 k2
    int16 a tile), its experts checked against k2_supported at load. The ggml types its GGUF matrices and experts kept in
    Mat::K and ExpertLayout::K get a field of their own (Mat::gg_type, ExpertLayout::gg_type[3]). Checked on an
    RTX 4000 (sm_75): ds4_gguf_test ALL OK (every streamed expert bit for bit its VRAM copy), exl3_test and
    exl3_exllamav3 pass.
  • CPU lane (exl3_cpu.cpp): the scalar and AVX-512 kernels are table-driven - their tables take S(p). The AVX2
    integer path rests on an invariant a half K breaks: a half row's 8 windows lie in one residue class of the words with
    one shift, but at K 3.5 the columns are 3.5 words apart. Its half-K path (Avx2TileHalf) uses what holds instead,
    as dq8_half does: a lane's 4 windows of one column span <= 27 bits, so per tile the k2 "pair" registers
    [class rho | class rho + KA] (128-bit loads and 4x4 transposes, never past the tile), per group of rows one vpermd
    for each of the span's two words, per-lane shifts and an or - every gather is still one vpermd, a row's states one
    immediate shift and a mask. The row kernels take a Tile (Avx2TileInt: the class registers exactly as before). An
    AVX-512 CPU runs a half K on the AVX2 kernels: the same bits, and the AVX-512 instances could not be run where this
    was written (a Zen 3). exl3_cpu_bench --K takes 3.5.
  • tools/exl3_exllamav3_fixture.py packs half-integer tiles with exllamav3's pack_trellis_frac (MASK 0xAAAA, the one
    pattern exllamav3 instantiates); data/exl3-exllamav3 gets K 1.5 / 2.5 / 3.5.

Same bits

RTX 3060 (sm_86), Ryzen 9 5900X (AVX2):

  • Against exllamav3 1.6.2 itself (exl3_test --exllamav3, tools/test_exl3_exllamav3.py): its tiles at K 1.5 /
    2.5 / 3.5 - states and W' 0 of 4,096 differ in the CPU reference, the CPU tiers' exact model and exl3_pack's
    decoder, the device's W' 0 of 16,384 in both layouts, the AVX2 tier bit for bit that model.
  • A real half-integer quant: no GLM-5.3-Flash quant at half K is published yet, so the matrices come from
    Vemloir's sc-exl3 4.05 of Qwen3.8-Flash-Next (the same EXL3 1.6 format) - experts at K 3.5 (layers 1, 4, 7, 9), 5, 3
    and 4 and a K 7 out_proj, 10 matrices, against exllamav3's reconstruct (exl3_test --expect): W' 0 differences in
    every one (CPU reference, device both layouts), the AVX2 tier bit for bit its model.
  • Every path at the half K (exl3_test, now with K 1.5 / 2.5 / 3.5 everywhere, and SC-style experts - gate / up
    3.5 with down 5, 1.5 with 3, 2.5 with 4 - in the routed-expert, verify-window and set kernels): 217 ok on the
    tensor-core kernels and 217 with MAYA_GLM_EXL3_DECODE=legacy; a half K with 3inst / mcg is refused. Its 142
    integer cases run first, in the order they always ran: the same numbers as before to the last digit.
  • The integer path is unchanged: turboderp's sc_3.10bpw (Maya's scorer, 1,135 held-out tokens, a two-GPU split,
    the CPU lane off) against v1.1.15: KL 0.000000 (max 0.0000), the same top token 100 %, nll 1.29114 both;
    with the CPU lane on (its plan fixed, the cards loaded one after the other) KL 0.000000, nll 1.28070 both, the same
    80,824 experts on the CPU and the same tiers; its 12 matrices against exllamav3 as before (84 / 84). The build's
    ctest (56 of 58 - ple_parity needs a Qwen3.8 model file and expert_multi_test an AVX-512 CPU), the tools tests
    (274) and tools/check_hip_compat.py pass.
  • GLM-5.3-Flash with a half-integer layer, end to end. No GLM quant at half K is published, so one was made:
    sc_3.10bpw with layer 10's routed gate and up (576 matrices, K 3) decoded by exllamav3's reconstruct and encoded
    again at K 3.5 by its own quantizer (quantize_tiles with mul1, pack_trellis_frac; its unpacker reads back the
    chosen states in all 576), everything else as stored. tools/exl3_pack.py packs it (layer 10 2 3.5 3.5 3 ...,
    3,682,304-byte gate / up parts beside layer 11's 3,158,016); three of the new matrices against exllamav3
    (exl3_test --expect): W' 0 of 8,388,608 differ in each, CPU reference and device both layouts. Maya's scorer
    (1,135 held-out tokens) against the unchanged sc_3.10bpw: KL 0.0135 with the CPU lane off (the same top token
    97.1 %, nll 1.2857 against 1.2911) and 0.0128 with it on (96.6 %, 80,914 experts on the lane) - the device's and the
    lane's half-K paths agree. The KL is the re-encoding of the layer (W'' is 9.3 % RMS from W'), not the half-integer
    path: the same pipeline gives back the stored weights exactly at their own K 3 (0.0000 RMS), and at an integer K 4
    (6.6 % RMS) costs KL 0.0117 (96.2 %) - the same size. v1.1.15 refuses the pack at load: exl3.txt: bad layer line: layer 10 2 3.5 3.5 3 ....

Not done

  • AVX-512 half-K kernel instances (above).
  • HIP: the device changes are template arguments and a new frag8 branch; not built here.

Credit: the half-integer layout and dq8_half's grouping are exllamav3's (MIT, turboderp).

🤖 Generated with Claude Code


🔄 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/mw00/project-maya/pull/265 **Author:** [@sociolog](https://github.com/sociolog) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `exl3-half-k` --- ### 📝 Commits (1) - [`986ca21`](https://github.com/mw00/project-maya/commit/986ca218982db1b3d4b237bb30448462415dc7d8) EXL3: exllamav3 1.6's half-integer bitrates (K 1.5 / 2.5 / 3.5) - every decoder bit for bit exllamav3's ### 📊 Changes **24 files changed** (+1108 additions, -676 deletions) <details> <summary>View changed files</summary> ➕ `data/exl3-exllamav3/exl3_k2_3_cb2.bin` (+0 -0) ➕ `data/exl3-exllamav3/exl3_k2_5_cb2.bin` (+0 -0) ➕ `data/exl3-exllamav3/exl3_k2_7_cb2.bin` (+0 -0) 📝 `include/strata/core/glm_model.hpp` (+2 -2) 📝 `include/strata/kernels/cpu/exl3_cpu.hpp` (+8 -5) 📝 `include/strata/kernels/cpu/exl3_ref.hpp` (+8 -4) 📝 `include/strata/kernels/exl3.hpp` (+18 -7) 📝 `src/core/glm_fast_path.cu` (+6 -6) 📝 `src/core/glm_model.cu` (+62 -21) 📝 `src/core/glm_prefill.cu` (+2 -2) 📝 `src/ds4/ds4_gguf.cu` (+5 -4) 📝 `src/ds4/ds4_gguf.cuh` (+7 -5) 📝 `src/ds4/ds4_model.cu` (+36 -28) 📝 `src/kernels/cpu/exl3_cpu.cpp` (+337 -180) 📝 `src/kernels/cpu/exl3_cpu_bench.cpp` (+32 -19) 📝 `src/kernels/cpu/exl3_ref.cpp` (+10 -6) 📝 `src/kernels/cuda/exl3.cu` (+182 -131) 📝 `src/kernels/cuda/exl3_legacy.cu` (+88 -75) 📝 `tests/ds4_cpu_bench.cpp` (+1 -1) 📝 `tests/ds4_gguf_test.cu` (+4 -4) _...and 4 more files_ </details> ### 📄 Description > Rebased on main (456a5ca, after v1.1.18) now that #264 has merged: one commit, 986ca21. Since v1.1.16 added maya-ds4, > the rebase also moves its EXL3 path to k2 (the bullet below the device kernels). ## What exllamav3 1.6 writes **half-integer bitrates** K = KA + 0.5 - 24 / 40 / 56 int16 words a 16x16 tile, the mul1 codebook only - where a self-calibrated quant's budget for a layer falls between two integer widths (e.g. a community SC 4.05 of Qwen3.8-Flash-Next has K 3.5 gate / up in 8 of its MoE layers). Their trellis steps alternate KA bits (even step) and KA + 1 (odd step), so step p's 16-bit window ends at S(p) = floor((p + 1) k2 / 2), k2 = 2 K which is (p + 1) K for an integer K as well. Today `tools/exl3_pack.py` refuses such a model ("half-integer bitrate ... not supported yet") and the engine and its kernels take K 1..8. This makes every path take K 1.5 / 2.5 / 3.5. - **The bitrate is k2 = 2 K everywhere**: `exl3::Mat::k2`, `ExpertLayout::k2[3]`, `cpu::Exl3Part::k2`, the pack's matrices and layers, `trellis_bytes` -> `trellis_bytes_k2`, `exl3_inner` -> `exl3_inner_k2` (renamed, so no caller passes a K where a k2 is meant). `k2_supported(k2, cb)`: K 1..8 with any codebook, 1.5 / 2.5 / 3.5 with mul1. - **The pack and its reader.** The packer takes a tile's words as k2 (a half K without mul1, or a width that is no bitrate, refused by name) and writes such a K as `3.5` in `exl3.txt`. Integer packs are written byte for byte as before. The engine reads `K` or `K.5` (by hand, so no locale's decimal point matters), checks every matrix and layer part against `k2_supported` at load (and that a layer's gate and up have one K, as the blob's layout needs), and sizes each part from k2 (16 k2 bytes a tile), every layer its own. An engine from before this change refuses a `3.5` line ("exl3.txt: bad mat line" / "bad layer line") instead of misreading it. - **Device kernels** (`exl3.cu`): `frag8` takes K2; an odd K2 decodes through `frag8_half` - exllamav3's `dq8_half`: a lane's 8 steps start even, so their windows end at S(p + 7) = (p / 2 + 4) K2 and then KA + 1, KA, KA + 1, ... bits earlier; four windows span 18 + 3 KA <= 27 bits, one funnel shift of two words for each group of four. One change for the decode GEMV, the routed experts, the verify window, the prompt path's tensor-core set kernels and its decoded W'. `dispatch` instantiates K 1..8 x 3 codebooks and the half K with mul1 (three more instances of each kernel), and refuses anything else before a launch. **`exl3_legacy.cu`** (GPUs before sm_80): `state_at` takes S(p). - **maya-ds4** (DeepSeek-V4.1-Flash, added in v1.1.16): its EXL3 matrices and experts take k2 from the trellis (8 k2 int16 a tile), its experts checked against `k2_supported` at load. The ggml types its GGUF matrices and experts kept in `Mat::K` and `ExpertLayout::K` get a field of their own (`Mat::gg_type`, `ExpertLayout::gg_type[3]`). Checked on an RTX 4000 (sm_75): `ds4_gguf_test` ALL OK (every streamed expert bit for bit its VRAM copy), `exl3_test` and `exl3_exllamav3` pass. - **CPU lane** (`exl3_cpu.cpp`): the scalar and AVX-512 kernels are table-driven - their tables take S(p). The AVX2 integer path rests on an invariant a half K breaks: a half row's 8 windows lie in one residue class of the words with one shift, but at K 3.5 the columns are 3.5 words apart. Its half-K path (`Avx2TileHalf`) uses what holds instead, as `dq8_half` does: a lane's 4 windows of one column span <= 27 bits, so per tile the k2 "pair" registers [class rho | class rho + KA] (128-bit loads and 4x4 transposes, never past the tile), per group of rows one `vpermd` for each of the span's two words, per-lane shifts and an or - every gather is still one `vpermd`, a row's states one immediate shift and a mask. The row kernels take a `Tile` (`Avx2TileInt`: the class registers exactly as before). An AVX-512 CPU runs a half K on the AVX2 kernels: the same bits, and the AVX-512 instances could not be run where this was written (a Zen 3). `exl3_cpu_bench --K` takes 3.5. - `tools/exl3_exllamav3_fixture.py` packs half-integer tiles with exllamav3's `pack_trellis_frac` (MASK 0xAAAA, the one pattern exllamav3 instantiates); `data/exl3-exllamav3` gets K 1.5 / 2.5 / 3.5. ## Same bits RTX 3060 (sm_86), Ryzen 9 5900X (AVX2): - **Against exllamav3 1.6.2 itself** (`exl3_test --exllamav3`, `tools/test_exl3_exllamav3.py`): its tiles at K 1.5 / 2.5 / 3.5 - states and W' 0 of 4,096 differ in the CPU reference, the CPU tiers' exact model and `exl3_pack`'s decoder, the device's W' 0 of 16,384 in both layouts, the AVX2 tier bit for bit that model. - **A real half-integer quant**: no GLM-5.3-Flash quant at half K is published yet, so the matrices come from Vemloir's sc-exl3 4.05 of Qwen3.8-Flash-Next (the same EXL3 1.6 format) - experts at K 3.5 (layers 1, 4, 7, 9), 5, 3 and 4 and a K 7 `out_proj`, 10 matrices, against exllamav3's reconstruct (`exl3_test --expect`): W' 0 differences in every one (CPU reference, device both layouts), the AVX2 tier bit for bit its model. - **Every path at the half K** (`exl3_test`, now with K 1.5 / 2.5 / 3.5 everywhere, and SC-style experts - gate / up 3.5 with down 5, 1.5 with 3, 2.5 with 4 - in the routed-expert, verify-window and set kernels): 217 ok on the tensor-core kernels and 217 with `MAYA_GLM_EXL3_DECODE=legacy`; a half K with 3inst / mcg is refused. Its 142 integer cases run first, in the order they always ran: the same numbers as before to the last digit. - **The integer path is unchanged**: turboderp's `sc_3.10bpw` (Maya's scorer, 1,135 held-out tokens, a two-GPU split, the CPU lane off) against v1.1.15: KL 0.000000 (max 0.0000), the same top token 100 %, nll 1.29114 both; with the CPU lane on (its plan fixed, the cards loaded one after the other) KL 0.000000, nll 1.28070 both, the same 80,824 experts on the CPU and the same tiers; its 12 matrices against exllamav3 as before (84 / 84). The build's ctest (56 of 58 - `ple_parity` needs a Qwen3.8 model file and `expert_multi_test` an AVX-512 CPU), the tools tests (274) and `tools/check_hip_compat.py` pass. - **GLM-5.3-Flash with a half-integer layer, end to end.** No GLM quant at half K is published, so one was made: `sc_3.10bpw` with layer 10's routed gate and up (576 matrices, K 3) decoded by exllamav3's `reconstruct` and encoded again at K 3.5 by its own quantizer (`quantize_tiles` with mul1, `pack_trellis_frac`; its unpacker reads back the chosen states in all 576), everything else as stored. `tools/exl3_pack.py` packs it (`layer 10 2 3.5 3.5 3 ...`, 3,682,304-byte gate / up parts beside layer 11's 3,158,016); three of the new matrices against exllamav3 (`exl3_test --expect`): W' 0 of 8,388,608 differ in each, CPU reference and device both layouts. Maya's scorer (1,135 held-out tokens) against the unchanged `sc_3.10bpw`: KL 0.0135 with the CPU lane off (the same top token 97.1 %, nll 1.2857 against 1.2911) and 0.0128 with it on (96.6 %, 80,914 experts on the lane) - the device's and the lane's half-K paths agree. The KL is the re-encoding of the layer (W'' is 9.3 % RMS from W'), not the half-integer path: the same pipeline gives back the stored weights exactly at their own K 3 (0.0000 RMS), and at an integer K 4 (6.6 % RMS) costs KL 0.0117 (96.2 %) - the same size. v1.1.15 refuses the pack at load: `exl3.txt: bad layer line: layer 10 2 3.5 3.5 3 ...`. ## Not done - AVX-512 half-K kernel instances (above). - HIP: the device changes are template arguments and a new `frag8` branch; not built here. Credit: the half-integer layout and `dq8_half`'s grouping are exllamav3's (MIT, turboderp). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:23 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#434
No description provided.