Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Experimental K6/K8 fused MoE
This path supports Qwen routed experts with K6 weights and shared experts with K8 weights. All projections must use the mul1 codebook. The default remains disabled. Rebuild the extension before use.
Set these variables before you start the server:
export EXL3_MOE_FUSED=1
export EXL3_MOE_FUSED_LAYOUT=native
export EXL3_MOE_FUSED9=1441792
export EXL3_MOE_FUSED_K6S8=1
Only the native six-stage variant is supported. Timing and other variants are excluded. Without this setting, the existing fallback remains in use. No model conversion is required.
Checks
Run the CPU checks from the repository root:
python -m pytest --noconftest -q tests/test_moe_fused_k8_cpu.py tests/test_moe_fused_k6_cpu.py tests/test_moe_k56_cpu.py
On an idle ROCm GPU, run the real-weight check with the model directory:
python tools/qwen/check_k6k8_layers.py --model "$MODEL_DIR"
The GPU check loads one block at a time. It does not stop services.
It checks buffer bounds, finite outputs, repeatability, batch shape,
and error against the unfused path. Exit code 2 reports a relative update RMS
error above --max-rel-error (default 1e-3; 0 requires bit-exact outputs).
Differences below the limit are counted and reported, not hidden.
It does not establish full-model quality or long-context correctness.
Earlier hardware results
The prototype was tested on an EVO-X2 with 128 GB RAM and gfx1151. The local Qwen3.8 Flash-Next EXL3 pack was labelled 6.05 bpw. These results used base commit 7844feb. They are not a GPU test of the rebased PR. Each comparison used the same experimental binary and changed EXL3_MOE_FUSED_K6S8 from 0 to 1. Context was 262144, cache was 16-bit, sessions was 2, and ndt was 3. The ngram table used disk streaming.
| Prompt | Before (tokens/s) | After (tokens/s) |
|---|---|---|
| Explanation | 16.08 | 18.45 |
| Code | 21.71 | 25.67 |
| Story | 13.95 | 16.29 |
These are medians from two repetitions. Paired-request wall time changed from 16.80 s to 15.79 s. These are small-sample observations.
All 64 real-weight half-layer comparisons had numerical differences. Relative update RMS error ranged from 0.0149% to 0.0347%. Bounds, finite-output, repeatability, and batch-shape checks passed. The 128-token output checks matched. A 256-token code response differed at token 204 in both repetitions. Its AST matched, but its text did not. The largest shared top-10 probability change was 6.411 percentage points.
Numerical acceptance
Where the half-layer difference comes from. Blocks: main layers 0, 24, 47 and the MTP layer of the 6.05 bpw pack (K6 routed, K8 shared), rows 1 to 4, two seeds. The mixed inputs and the expert selection were identical in every case. Only the shared expert or only the routed experts were left active:
| Active experts | Fused vs unfused, relative update RMS (min / median / max) |
|---|---|
| Routed only (K6) | 1.4e-4 / 2.0e-4 / 2.9e-4 |
| Shared only (K8) | 2.1e-4 / 3.0e-4 / 4.1e-4 |
| Both | 1.9e-4 / 2.3e-4 / 2.9e-4 |
The same comparison on a K4 routed / K4 shared pack is bit-exact in 24 of 24 cases. The K6 routed / K6 shared MTP layer of that pack, which already ships on the existing fused path, differs by 1.6e-4 to 2.4e-4, and the difference comes from its routed experts. So a K6 routed difference of this size is already present in the merged code. K8 adds a somewhat larger one.
Neither path is closer to exact arithmetic. Against an fp64 evaluation of the same quantized weights, both the fused and the unfused path sit at about 7e-4 of the output RMS (the two are within 3% of each other). The distance between them (2.4e-4 of the output RMS) is about three times smaller than the distance of either one to the exact result.
Why the K8 shared expert differs. The unfused K8 shared expert reconstructs an fp16 weight and runs a half-precision GEMM. K4 and K6 shared experts run through a direct decode GEMV, and the fused tile matches that GEMV bit for bit. The fused tile decodes and accumulates in fp32. Measured against fp64, the K8 gate and up tile output is correctly rounded to fp16 (error equal to the rounding floor, ratio 1.00, for K4, K6 and K8). The unfused K8 reconstruct route is 2.1 to 2.3 times the floor. The down projection (fp32 output) is about 7 times the rounding floor for every K, K4 included, so it is not specific to K8. We found no indexing or decode error in the K6 or K8 tile.
Served comparison on this revision
Full model, 6.05 bpw K6 routed / K8 shared pack, gfx1151, context 65536,
greedy, thinking off. Unfused is the default; fused sets
EXL3_MOE_FUSED=1 EXL3_MOE_FUSED_LAYOUT=native EXL3_MOE_FUSED9=1441792 EXL3_MOE_FUSED_K6S8=1.
32 prompts of 256 tokens, top-10 log-probabilities compared at every position
whose context is identical in both runs (5407 positions):
| Quantity | Fused vs unfused |
|---|---|
| Prompts whose greedy text diverges | 19 of 32 |
| Largest change of a top-10 probability | 6.96 points |
| Mean top-10 total variation | 0.0031 |
| RMS change of the log-probability of the chosen token | 0.012 |
| Mean change of that log-probability (bias) | -0.0004 |
The unfused server is deterministic: two unfused runs that differ only in the draft policy are bit-identical (1849 positions, largest change 0.000 points), so every difference above comes from the fused kernels. The size of the effect is what a rounding-level change does to this model, not a sign of a wrong kernel: a separate change that only touches the dense attention projections (direct K8 decode instead of reconstruct plus half-precision GEMM, relative error 5e-4 per projection) gives 17 of 32 diverging prompts, 9.58 points, RMS 0.013 and bias -0.0004 on the same prompts. Divergence of the greedy text is expected whenever two top tokens are close, so a diverging text is not a quality measure by itself.
Speed, same prompts and runs, medians of nine runs (three arms of three runs, ranges in brackets):
| Context | Unfused (tokens/s) | Fused (tokens/s) | Prefill, fused / unfused |
|---|---|---|---|
| 4K | 14.6 [12.9 to 15.4] | 16.4 [14.9 to 17.5] (+12%) | 0.98 |
| 32K | 15.1 [10.4 to 17.6] | 16.6 [0.6 to 17.8] (+10%) | 0.99 |
The host had under 6 GiB of free memory during these runs, which explains the wide ranges (one 32K fused run stalled at 0.6 tokens/s).
Build size and registers
Measured on gfx1151 with the build script of tools/strix_halo/rebuild.sh
(three parallel jobs): the extension grows from 134.66 MB to 136.20 MB
(+1.54 MB, +1.1%) with this change. A full build took 469 s here against 490 s
for the base; the machine was not idle, so treat build times as equal within noise.
Compiled alone with the same flags, exl3_moe_fused takes 46 s instead of 41 s
and its object grows from 3.30 MB to 3.76 MB.
Registers and spills (hipcc -Rpass-analysis=kernel-resource-usage) of the new
K6S8 kernels. The six stage kernels are the ones that run in the native layout:
| Kernel | VGPRs | Spilled VGPRs | Waves/SIMD |
|---|---|---|---|
moe_fused_kernel<QwenK6S8> |
220 | 0 | 6 |
moe_fused9s_kernel<QwenK6S8>, stages 0 to 5 |
179, 180, 139, 190, 178, 29 | 0 | 8 |
moe_fused9_kernel<QwenK6S8> |
234 | 0 | 6 |
moe_fused9o_kernel<QwenK6S8> |
192 | 32 | 8 |
moe_fused_kernel<SmallK6S8> |
160 | 0 | 9 |
moe_fused9s_kernel<SmallK6S8>, stages 0 to 5 |
94, 150, 34, 132, 123, 29 | 0 | 9 to 16 |
Only the o variant spills (32 registers, 84 bytes per lane). Kernels that
existed before did not change their register or spill counts.
The check script now accepts the numbers above and keeps exit code 2 for larger errors. The numerical differences of the fused path are at rounding level (see above). Use tools/bench.sh with the same machine and command for each comparison.