[PR #1764] [CLOSED] EXL3: run the EXL3 trellis format on the engine #3657

Closed
opened 2026-11-07 15:29:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1764
Author: @Yxmura
Created: 10/9/2026
Status: ❌ Closed

Base: main ← Head: exl3


📝 Commits (10+)

  • e1c6774 EXL3: run the EXL3 trellis format on the engine
  • abe5609 EXL3 model-open path: load and run an EXL3 model in the engine
  • 33985ae EXL3: decode the trellis with ExLlamaV3's window read
  • 1660ea8 EXL3: stage the GDN weights the way the converter does
  • 7c38149 EXL3: check the staged weights against the converter's transforms
  • f9d8415 docs/EXL3: the engine's form of the weights, and the measured end-to-end numbers
  • 4274b8d EXL3: check every released branch's decode on its own weights
  • 025566b EXL3: keep the routed experts in VRAM (--expert-cache, per layer)
  • e708df8 docs/EXL3: the VRAM expert cache and the steady-state numbers
  • bb17322 EXL3: retune the dense GEMV (hoisted window geometry, 256 threads, 2 tiles)

📊 Changes

43 files changed (+6633 additions, -35 deletions)

View changed files

📝 CMakeLists.txt (+93 -2)
➕ docs/EXL3.md (+511 -0)
➕ include/strata/artifact/exl3_model.hpp (+139 -0)
➕ include/strata/artifact/exl3_pack.hpp (+55 -0)
➕ include/strata/artifact/safetensors.hpp (+265 -0)
📝 include/strata/core/weights.hpp (+11 -0)
➕ include/strata/kernels/cpu/exl3.hpp (+44 -0)
➕ include/strata/kernels/exl3.hpp (+70 -0)
➕ include/strata/kernels/exl3_experts.hpp (+74 -0)
📝 include/strata/kernels/ngram.hpp (+7 -0)
➕ src/artifact/exl3_model_check.cpp (+63 -0)
➕ src/artifact/exl3_pack.cpp (+701 -0)
➕ src/artifact/exl3_pack_check.cpp (+103 -0)
➕ src/artifact/safetensors_exl3_check.cpp (+59 -0)
📝 src/core/layer.cpp (+40 -4)
➕ src/kernels/cpu/exl3.cpp (+285 -0)
➕ src/kernels/cuda/exl3.cu (+687 -0)
➕ src/kernels/cuda/exl3_experts.cu (+695 -0)
📝 src/kernels/cuda/gr.cu (+35 -10)
➕ src/kernels/exl3_gemv_parity.cpp (+97 -0)

...and 23 more files

📄 Description

Runs a turboderp EXL3 model (Qwen3.8-Flash-Next and its variants) end to end:

strata --exl3 <model_dir> --ple-exl3 <ngram_embedding.safetensors> --tokens ... --stop-eos

K is read per tensor from the trellis shape (integer K = 1..8, all three codebooks mul1/mcg/3inst), so every released branch runs: 2.05, 3.05, 4.05, 5.05, 6.05 bpw.

What

  • docs/EXL3.md, tools/exl3/, tools/test_exl3_*.py. Format spec, numpy codec (codebook, reconstruct, ngram), safetensors/tokenizer adapters, the engine-form checker.
  • CPU kernel src/kernels/cpu/exl3.cpp. Decode LUT, sliding window, tensor-core perm, H128, folded GEMV, ngram row.
  • GPU kernels src/kernels/cuda/exl3.cu, exl3_experts.cu. Reconstruct, fused decode-GEMV, batched MoE expert FFN, Exl3ExpertStore, Exl3ExpertStream (per-token expert streaming with an LRU VRAM cache, --expert-cache), exl3_moe_rows, exl3_embed_gather, exl3_shared_expert.
  • Loader src/artifact/exl3_pack.cpp builds the engine WeightTable from the model directory (1079 roles): the EXL3 linears attached as Exl3Mat, the norms/router/hyper-connection/GDN parameters/embedding staged in the engine's form. Plus include/strata/artifact/{safetensors,exl3_model}.hpp.
  • ngram PleTable::open_exl3.
  • Engine seam WeightRef::exl3 + gemv_quantized (src/core/layer.cpp), --exl3/--ple-exl3 in generate.cpp.

Bitrates

Every released branch is checked on its own weights (tools/exl3/fetch_branch_tensors.py pulls one expert and one dense linear from each branch's shards, strata-exl3-gpu compares the GPU decode-GEMV against the CPU reference on them):

branch experts attn / head GPU vs CPU
2.05bpw_h4_ng4 K=2 K=4 rel 2.9e-4
3.05bpw_h5_ng5 K=3 K=5 rel 2.9e-4
4.05bpw_h6_ng6 K=4 K=6 rel 2.9e-4
5.05bpw_h6_ng6 K=5 K=6, K=7 rel 2.9e-4
6.05bpw_h6_ng6 K=6 K=8 rel 2.9e-4

Measured

Radeon PRO W7800 (gfx1100, 32 GB, ROCm), 8 CPU pool threads, model on a SATA SSD, --expert-cache 0 (every routed expert streamed from disk), Qwen3.8-Flash-Next-exl3 3.05bpw.

load 15.4 s (1079 roles, 2117.4 MiB EXL3 linears, 2679.3 MiB staged); 21.2 s with the dense linears requantized to Q8_0 (3592.6 MiB)
prefill 9.0 tok/s (14 tokens)
decode 11.9 tok/s (40 tokens, steady state); 5.5 tok/s with --expert-cache 0
expert FFN 0.36 ms/layer on the GPU (48 layers); 493 ms/layer on one CPU thread
layer 0 / 47 vs CPU rel 1.1e-3 / 1.0e-3

Five passes on the decode path, each measured on its own:

change decode
(before) 2.3 tok/s
routed experts cached in VRAM (--expert-cache per layer, auto/unset sizes it from the free VRAM; without it the stream reads and uploads 890 MB per token) 8.9
dense GEMV retuned (window geometry hoisted out of the k loop, 256 threads, 2 output tiles per block, a k split that keeps ~256 blocks in flight) 10.2
the misses read with pread (0.3 GB/s through the mmap against 10.4 GB/s with preadv on the same page-cached tensors) spread over 4 threads into pinned staging 10.8
the resident experts' FFN enqueued before the staging starts (its own staging stream, then a scatter back into the router's order) 11.05
gr_inject / gr_down given four partial sums (one block of four warps walked 10,240 elements in 320 dependent steps) 11.9
the expert GEMV at four output tiles per block, swept on the real layer with strata-exl3-moe (T=2 0.385 -> T=4 0.308 ms/layer, -20%) 3.7 ms/token
the reconstructed fp16 weight freed after its transpose (it leaked ~7 GiB of VRAM across the 301 dense projections, and the expert cache could not have it) 216 -> 297 slots/layer
the expert FFN's accumulator zeroing folded into the prescale before it, and its f32 accumulator written as the f16 output (four kernels fewer) k=1: 0.108 -> 0.093 ms/layer
the native bf16 projections on by default for EXL3 (the SSM gates, router and indexer are bf16 rows in the engine's form either way) dense token 38.798 -> 35.572 ms
the dense linears requantized to Q8_0 at load and served by native_mmvq (measured with the experts skipped, so it prices the dense work alone: 47.4 -> 28.9 ms/token) 21.1 -> 34.5 (dense only)

The token is now: expert FFN 17 ms (the miss half ~5), dense GEMVs 23 ms, expert reads 13-27 ms (tracking the
70-94% hit rate), hyper-connections ~7 ms, the rest in the smaller kernels. The per-layer chain is serial by
construction (router, host reads, expert FFN, combine, next layer).

Where the dense token's time is. --stage-timing --no-capture --no-pool on the dense path: 35.572 ms per token, of which the attention block is 15.1 (the GDN's sub-stages sum to 9.5), the hyper-connection reads 8.1 (gr_read (attn) 4.1 + gr_read (ffn) 4.0), the router 1.3, the writes 0.8, everything else under 1. The hyper-connections are the biggest fixable block and the reason is concrete: gr_down_kernel stages the whole xn (D = 10,240 floats, 40 KB) in shared memory, which caps it at one block per compute unit against 121 blocks for 70 units, and the pair measures 8.1 ms against the ~2.6 ms its 1.27 GB/token of bf16 weights costs at bandwidth. The change is to keep each thread's k-slice in registers and reduce the norm's sums in a small shared buffer; it is in fused_gr.cu, which the native pack shares, so it needs that path's selftest too.

The expert FFN's geometry and kernel count, measured on the real layer. strata-exl3-moe runs the whole expert FFN on layer 0 with real weights, and both the tiles per block and the kernel count were settled on it. Tiles: T=1 0.534, T=2 0.385 (what it was), T=3 0.321, T=4 0.308, T=5 0.319, T=6 0.327, T=7 0.342, T=8 0.325 ms/layer, so T=4. Kernel count: k = 1, 2, 5, 10 measures 0.108, 0.130, 0.214, 0.332, i.e. 0.0249 ms per expert and 0.083 ms/layer of fixed cost; folding the three accumulator memsets into the prescale and the f32 accumulator into the f16 output takes the k=1 case to 0.093. Three things measured worse and are not in the tree: shared-memory tile staging (0.462-0.487), a higher k-group count (0.330 at x2, 0.543 at x4), and launch bounds (256x4/6/8 within 0.004 ms of each other).

The leak the VRAM accounting hid. stage_exl3_requantized allocates the reconstructed fp16 matrix, transposes it, and never freed the untransposed copy. It is the same size as the matrix, so the 301 dense projections leaked ~7 GiB, and the expert cache was sized from what was left: 18.52 GiB free -> 216 slots/layer before, 25.28 GiB -> 297 after. The decode's steady state (a 200-token run, the median of the last 30 tokens) went from a 97.4 ms pool to 83.1 ms with the uploads at 76.2 -> 62.0 ms, and a 15-token prompt from 14.0 s to 12.2 s.

The steady state is the saturated routing, and it takes a while to get there. Measured on a 220-token run,
the per-token cache hit rate climbed 82% -> 90% -> 92.5% -> 98.8% -> 99.0% and the uploads fell from 400+ ms to
20-37 ms; a token then measures ~76-100 ms (~10-12 tok/s): dense work 29 ms (Q8_0), routed experts' FFN ~17 ms,
the host's wait on it ~19 ms, hyper-connections ~7 ms, the trickle of first-time experts 20-37 ms, the smaller
kernels ~10 ms. With the reads priced at zero those parts sum to ~46 ms (~21 tok/s). The prefill is the same
reads without a warm cache: a 15-token prompt measured 14-22 s (0.6-1.0 tok/s) with 113-2121 ms of uploads per
token against 1.8-3.6 ms of FFN, and a prompt's distinct experts are ~85% of the sum of its tokens' routes, so
batching would save that 15% and no more. What makes a 64 GB machine's prefill 447-966 tok/s is that its whole
expert set is in RAM; this model's 45 GB of experts do not fit in 24.5 GiB of free VRAM plus ~20 GB of RAM, so
those reads are structural.

Why a GGUF pack of the same model decodes faster, measured

  • A trellis weight costs about two loads and eleven ALU ops to decode; a ggml block quant's vec_dot costs
    about one load per 4-5 weights. The dense GEMV was load-instruction-bound: 3.5 G dense weights x 2 loads per
    token, 23 ms. The dense linears are now requantized to Q8_0 at load (stage_exl3_requantized) and served
    by the engine's native MMVQ, the path a GGUF pack's dense projections already take. Measured on the W7800, a
    2560x10240 matrix: the decode-GEMV kernel 106.8 us against the native Q8_0 MMVQ kernel's 31.8 us, 3.4x.
    Q5_K was tried first and rejected on the measurement: a 5-bit block quant on top of the trellis decode's own
    10-bit codes measures a 4% round-trip error and the model answers "surface表面的表面的"; Q8_0's is 0.65%
    and the model is correct. Q8_0 is 1.7x the bytes of the trellis it replaces (3592.6 against 2117.4 MiB of
    dense linears, ~31 MiB per layer, about 16 expert slots), and the requantization streams through small
    row-chunk buffers so the model's page cache survives the load. STRATA_EXL3_DENSE=exl3 keeps the trellis.

    The bytes are the price, and they show up in the batched prefill, which reads the weights once per batch: the
    dense work of a 14-token prompt measures 20.5 ms against 31.6 ms with Q8_0 (683.8 against 442.5 tok/s), the
    same 1.5x that the byte counts predict. In the pooled prefill the dense projections are 20-32 ms of a
    1.55 s batch (9.0 tok/s measured), so that is ~1% there, while the decode reads those weights every token and
    gains the 18.4 ms.

  • The v-head reorder is part of the weight, and a requantized copy has to carry it. The GDN's v projections
    (attn_qkv, attn_gate, ssm_out) are staged with their v heads permuted and the activations are permuted to
    match, so the requantizer runs stage_exl3's own host-side reorder before it reconstructs. Without it those
    three roles answer nonsense while the QSA roles (Vr::None) are correct, measured.

  • The experts cannot go on the CPU pool the way a GGUF pack's do: the CPU's EXL3 folded GEMV is 493 ms/layer
    against the GPU's 0.36 ms/layer (strata-exl3-moe, 10 experts), so the trellis decode has to stay on the
    GPU and its streaming is on the per-layer critical path.

Both prompts answer correctly: "The capital of France is Paris." and a Python hello-world program, with and without PLE.

Validation

  • ctest -R exl3: 20/20. CPU numpy fixture + parity per K=1..8; exl3_gpu_parity K=1..8; exl3_gemv_parity K=1..8 plus the expert (640x2560) and attn (2560x10240) shapes; ple_exl3_parity.
  • strata-exl3-pack --run: 1079 roles, 301 dense EXL3 projections, 0 faults.
  • strata-exl3-pack --dump + tools/exl3/check_engine_form.py: 22/22 roles match llama.cpp's converter on the real weights (the v-head reorder, -exp(A_log), +1 gammas, [out][in] indexer staging), byte-exact for the trellis permutations.
  • python3 tools/test_exl3_{codebook,reconstruct,ngram}.py: OK.
  • Full strata target builds.

Two bugs the parity tests cannot see

The parity tests share the decode with the numpy reference, so only the BF16 base model can catch a decode error. Comparing against it found:

  • the trellis window read was a linear LSB bitstream read; ExLlamaV3 packs per 16-value span, MSB-first, then byte-swaps, and reads with a funnel shift (unpack_trellis/dq). Fixed in the numpy codec, the CPU decoder and both GPU kernels.
  • the loader was missing llama.cpp's converter transforms, so every GDN layer paired q/k/v from the wrong heads and the decay was wrong. Fixed, and checked on the real model by check_engine_form.py.

🔄 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/1764 **Author:** [@Yxmura](https://github.com/Yxmura) **Created:** 10/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `exl3` --- ### 📝 Commits (10+) - [`e1c6774`](https://github.com/Niko1221/Strata/commit/e1c67740fa14f823043db1eee16b04e9baa01f00) EXL3: run the EXL3 trellis format on the engine - [`abe5609`](https://github.com/Niko1221/Strata/commit/abe56090432d6d6bb1c3c89c60052282240360b0) EXL3 model-open path: load and run an EXL3 model in the engine - [`33985ae`](https://github.com/Niko1221/Strata/commit/33985aecf2975e49af971c9ecfe155d1737e5d84) EXL3: decode the trellis with ExLlamaV3's window read - [`1660ea8`](https://github.com/Niko1221/Strata/commit/1660ea8b0ffe6920ee0be6ef82a136b1cb58b5b6) EXL3: stage the GDN weights the way the converter does - [`7c38149`](https://github.com/Niko1221/Strata/commit/7c381491127f626d8c2adf49a9e835692d46c157) EXL3: check the staged weights against the converter's transforms - [`f9d8415`](https://github.com/Niko1221/Strata/commit/f9d84158928b92ce0b8d2c3c9c2326aec3bcfa09) docs/EXL3: the engine's form of the weights, and the measured end-to-end numbers - [`4274b8d`](https://github.com/Niko1221/Strata/commit/4274b8daa483a7ae34c5551728489091b26ea34b) EXL3: check every released branch's decode on its own weights - [`025566b`](https://github.com/Niko1221/Strata/commit/025566bdc166ee81df3e98fd39ee8928f6afd868) EXL3: keep the routed experts in VRAM (--expert-cache, per layer) - [`e708df8`](https://github.com/Niko1221/Strata/commit/e708df80ce19ceba79cdc3839970dffe4f48f35d) docs/EXL3: the VRAM expert cache and the steady-state numbers - [`bb17322`](https://github.com/Niko1221/Strata/commit/bb173222acd2e029d592377b1bf934052aea7d4f) EXL3: retune the dense GEMV (hoisted window geometry, 256 threads, 2 tiles) ### 📊 Changes **43 files changed** (+6633 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+93 -2) ➕ `docs/EXL3.md` (+511 -0) ➕ `include/strata/artifact/exl3_model.hpp` (+139 -0) ➕ `include/strata/artifact/exl3_pack.hpp` (+55 -0) ➕ `include/strata/artifact/safetensors.hpp` (+265 -0) 📝 `include/strata/core/weights.hpp` (+11 -0) ➕ `include/strata/kernels/cpu/exl3.hpp` (+44 -0) ➕ `include/strata/kernels/exl3.hpp` (+70 -0) ➕ `include/strata/kernels/exl3_experts.hpp` (+74 -0) 📝 `include/strata/kernels/ngram.hpp` (+7 -0) ➕ `src/artifact/exl3_model_check.cpp` (+63 -0) ➕ `src/artifact/exl3_pack.cpp` (+701 -0) ➕ `src/artifact/exl3_pack_check.cpp` (+103 -0) ➕ `src/artifact/safetensors_exl3_check.cpp` (+59 -0) 📝 `src/core/layer.cpp` (+40 -4) ➕ `src/kernels/cpu/exl3.cpp` (+285 -0) ➕ `src/kernels/cuda/exl3.cu` (+687 -0) ➕ `src/kernels/cuda/exl3_experts.cu` (+695 -0) 📝 `src/kernels/cuda/gr.cu` (+35 -10) ➕ `src/kernels/exl3_gemv_parity.cpp` (+97 -0) _...and 23 more files_ </details> ### 📄 Description Runs a turboderp EXL3 model (Qwen3.8-Flash-Next and its variants) end to end: strata --exl3 <model_dir> --ple-exl3 <ngram_embedding.safetensors> --tokens ... --stop-eos K is read per tensor from the trellis shape (integer K = 1..8, all three codebooks mul1/mcg/3inst), so every released branch runs: 2.05, 3.05, 4.05, 5.05, 6.05 bpw. ## What - **docs/EXL3.md, tools/exl3/, tools/test_exl3_*.py.** Format spec, numpy codec (codebook, reconstruct, ngram), safetensors/tokenizer adapters, the engine-form checker. - **CPU kernel** `src/kernels/cpu/exl3.cpp`. Decode LUT, sliding window, tensor-core perm, H128, folded GEMV, ngram row. - **GPU kernels** `src/kernels/cuda/exl3.cu`, `exl3_experts.cu`. Reconstruct, fused decode-GEMV, batched MoE expert FFN, `Exl3ExpertStore`, `Exl3ExpertStream` (per-token expert streaming with an LRU VRAM cache, `--expert-cache`), `exl3_moe_rows`, `exl3_embed_gather`, `exl3_shared_expert`. - **Loader** `src/artifact/exl3_pack.cpp` builds the engine `WeightTable` from the model directory (1079 roles): the EXL3 linears attached as `Exl3Mat`, the norms/router/hyper-connection/GDN parameters/embedding staged in the engine's form. Plus `include/strata/artifact/{safetensors,exl3_model}.hpp`. - **ngram** `PleTable::open_exl3`. - **Engine seam** `WeightRef::exl3` + `gemv_quantized` (`src/core/layer.cpp`), `--exl3`/`--ple-exl3` in `generate.cpp`. ## Bitrates Every released branch is checked on its own weights (`tools/exl3/fetch_branch_tensors.py` pulls one expert and one dense linear from each branch's shards, `strata-exl3-gpu` compares the GPU decode-GEMV against the CPU reference on them): | branch | experts | attn / head | GPU vs CPU | |---|---|---|---| | 2.05bpw_h4_ng4 | K=2 | K=4 | rel 2.9e-4 | | 3.05bpw_h5_ng5 | K=3 | K=5 | rel 2.9e-4 | | 4.05bpw_h6_ng6 | K=4 | K=6 | rel 2.9e-4 | | 5.05bpw_h6_ng6 | K=5 | K=6, K=7 | rel 2.9e-4 | | 6.05bpw_h6_ng6 | K=6 | K=8 | rel 2.9e-4 | ## Measured Radeon PRO W7800 (gfx1100, 32 GB, ROCm), 8 CPU pool threads, model on a SATA SSD, `--expert-cache 0` (every routed expert streamed from disk), Qwen3.8-Flash-Next-exl3 3.05bpw. | | | |---|---| | load | 15.4 s (1079 roles, 2117.4 MiB EXL3 linears, 2679.3 MiB staged); 21.2 s with the dense linears requantized to Q8_0 (3592.6 MiB) | | prefill | 9.0 tok/s (14 tokens) | | decode | 11.9 tok/s (40 tokens, steady state); 5.5 tok/s with `--expert-cache 0` | | expert FFN | 0.36 ms/layer on the GPU (48 layers); 493 ms/layer on one CPU thread | | layer 0 / 47 vs CPU | rel 1.1e-3 / 1.0e-3 | Five passes on the decode path, each measured on its own: | change | decode | |---|---| | (before) | 2.3 tok/s | | routed experts cached in VRAM (`--expert-cache` per layer, `auto`/unset sizes it from the free VRAM; without it the stream reads and uploads 890 MB per token) | 8.9 | | dense GEMV retuned (window geometry hoisted out of the k loop, 256 threads, 2 output tiles per block, a k split that keeps ~256 blocks in flight) | 10.2 | | the misses read with `pread` (0.3 GB/s through the mmap against 10.4 GB/s with preadv on the same page-cached tensors) spread over 4 threads into pinned staging | 10.8 | | the resident experts' FFN enqueued before the staging starts (its own staging stream, then a scatter back into the router's order) | 11.05 | | `gr_inject` / `gr_down` given four partial sums (one block of four warps walked 10,240 elements in 320 dependent steps) | 11.9 | | the expert GEMV at four output tiles per block, swept on the real layer with `strata-exl3-moe` (T=2 0.385 -> T=4 0.308 ms/layer, -20%) | 3.7 ms/token | | the reconstructed fp16 weight freed after its transpose (it leaked ~7 GiB of VRAM across the 301 dense projections, and the expert cache could not have it) | 216 -> 297 slots/layer | | the expert FFN's accumulator zeroing folded into the prescale before it, and its f32 accumulator written as the f16 output (four kernels fewer) | k=1: 0.108 -> 0.093 ms/layer | | the native bf16 projections on by default for EXL3 (the SSM gates, router and indexer are bf16 rows in the engine's form either way) | dense token 38.798 -> 35.572 ms | | the dense linears requantized to Q8_0 at load and served by `native_mmvq` (measured with the experts skipped, so it prices the dense work alone: 47.4 -> 28.9 ms/token) | 21.1 -> 34.5 (dense only) | The token is now: expert FFN 17 ms (the miss half ~5), dense GEMVs 23 ms, expert reads 13-27 ms (tracking the 70-94% hit rate), hyper-connections ~7 ms, the rest in the smaller kernels. The per-layer chain is serial by construction (router, host reads, expert FFN, combine, next layer). **Where the dense token's time is.** `--stage-timing --no-capture --no-pool` on the dense path: 35.572 ms per token, of which the attention block is 15.1 (the GDN's sub-stages sum to 9.5), **the hyper-connection reads 8.1** (`gr_read (attn)` 4.1 + `gr_read (ffn)` 4.0), the router 1.3, the writes 0.8, everything else under 1. The hyper-connections are the biggest fixable block and the reason is concrete: `gr_down_kernel` stages the whole `xn` (D = 10,240 floats, 40 KB) in shared memory, which caps it at one block per compute unit against 121 blocks for 70 units, and the pair measures 8.1 ms against the ~2.6 ms its 1.27 GB/token of bf16 weights costs at bandwidth. The change is to keep each thread's k-slice in registers and reduce the norm's sums in a small shared buffer; it is in `fused_gr.cu`, which the native pack shares, so it needs that path's selftest too. **The expert FFN's geometry and kernel count, measured on the real layer.** `strata-exl3-moe` runs the whole expert FFN on layer 0 with real weights, and both the tiles per block and the kernel count were settled on it. Tiles: T=1 0.534, T=2 0.385 (what it was), T=3 0.321, T=4 0.308, T=5 0.319, T=6 0.327, T=7 0.342, T=8 0.325 ms/layer, so T=4. Kernel count: k = 1, 2, 5, 10 measures 0.108, 0.130, 0.214, 0.332, i.e. 0.0249 ms per expert and 0.083 ms/layer of fixed cost; folding the three accumulator memsets into the prescale and the f32 accumulator into the f16 output takes the k=1 case to 0.093. Three things measured worse and are not in the tree: shared-memory tile staging (0.462-0.487), a higher k-group count (0.330 at x2, 0.543 at x4), and launch bounds (256x4/6/8 within 0.004 ms of each other). **The leak the VRAM accounting hid.** `stage_exl3_requantized` allocates the reconstructed fp16 matrix, transposes it, and never freed the untransposed copy. It is the same size as the matrix, so the 301 dense projections leaked ~7 GiB, and the expert cache was sized from what was left: 18.52 GiB free -> 216 slots/layer before, 25.28 GiB -> 297 after. The decode's steady state (a 200-token run, the median of the last 30 tokens) went from a 97.4 ms pool to 83.1 ms with the uploads at 76.2 -> 62.0 ms, and a 15-token prompt from 14.0 s to 12.2 s. **The steady state is the saturated routing, and it takes a while to get there.** Measured on a 220-token run, the per-token cache hit rate climbed 82% -> 90% -> 92.5% -> 98.8% -> 99.0% and the uploads fell from 400+ ms to 20-37 ms; a token then measures ~76-100 ms (~10-12 tok/s): dense work 29 ms (Q8_0), routed experts' FFN ~17 ms, the host's wait on it ~19 ms, hyper-connections ~7 ms, the trickle of first-time experts 20-37 ms, the smaller kernels ~10 ms. With the reads priced at zero those parts sum to ~46 ms (~21 tok/s). The prefill is the same reads without a warm cache: a 15-token prompt measured 14-22 s (0.6-1.0 tok/s) with 113-2121 ms of uploads per token against 1.8-3.6 ms of FFN, and a prompt's distinct experts are ~85% of the sum of its tokens' routes, so batching would save that 15% and no more. What makes a 64 GB machine's prefill 447-966 tok/s is that its whole expert set is in RAM; this model's 45 GB of experts do not fit in 24.5 GiB of free VRAM plus ~20 GB of RAM, so those reads are structural. ## Why a GGUF pack of the same model decodes faster, measured - A trellis weight costs about **two loads and eleven ALU ops** to decode; a ggml block quant's `vec_dot` costs about one load per 4-5 weights. The dense GEMV was load-instruction-bound: 3.5 G dense weights x 2 loads per token, 23 ms. **The dense linears are now requantized to Q8_0 at load** (`stage_exl3_requantized`) and served by the engine's native MMVQ, the path a GGUF pack's dense projections already take. Measured on the W7800, a 2560x10240 matrix: the decode-GEMV kernel **106.8 us** against the native Q8_0 MMVQ kernel's **31.8 us**, 3.4x. Q5_K was tried first and rejected on the measurement: a 5-bit block quant on top of the trellis decode's own 10-bit codes measures a **4%** round-trip error and the model answers "surface表面的表面的"; Q8_0's is **0.65%** and the model is correct. Q8_0 is 1.7x the bytes of the trellis it replaces (3592.6 against 2117.4 MiB of dense linears, ~31 MiB per layer, about 16 expert slots), and the requantization streams through small row-chunk buffers so the model's page cache survives the load. `STRATA_EXL3_DENSE=exl3` keeps the trellis. The bytes are the price, and they show up in the batched prefill, which reads the weights once per batch: the dense work of a 14-token prompt measures 20.5 ms against 31.6 ms with Q8_0 (683.8 against 442.5 tok/s), the same 1.5x that the byte counts predict. In the pooled prefill the dense projections are 20-32 ms of a 1.55 s batch (9.0 tok/s measured), so that is ~1% there, while the decode reads those weights every token and gains the 18.4 ms. - **The v-head reorder is part of the weight, and a requantized copy has to carry it.** The GDN's v projections (`attn_qkv`, `attn_gate`, `ssm_out`) are staged with their v heads permuted and the activations are permuted to match, so the requantizer runs `stage_exl3`'s own host-side reorder before it reconstructs. Without it those three roles answer nonsense while the QSA roles (`Vr::None`) are correct, measured. - The experts cannot go on the CPU pool the way a GGUF pack's do: the CPU's EXL3 folded GEMV is **493 ms/layer** against the GPU's **0.36 ms/layer** (`strata-exl3-moe`, 10 experts), so the trellis decode has to stay on the GPU and its streaming is on the per-layer critical path. Both prompts answer correctly: "The capital of France is **Paris**." and a Python hello-world program, with and without PLE. ## Validation - `ctest -R exl3`: 20/20. CPU numpy fixture + parity per K=1..8; `exl3_gpu_parity` K=1..8; `exl3_gemv_parity` K=1..8 plus the expert (640x2560) and attn (2560x10240) shapes; `ple_exl3_parity`. - `strata-exl3-pack --run`: 1079 roles, 301 dense EXL3 projections, 0 faults. - `strata-exl3-pack --dump` + `tools/exl3/check_engine_form.py`: 22/22 roles match llama.cpp's converter on the real weights (the v-head reorder, -exp(A_log), +1 gammas, [out][in] indexer staging), byte-exact for the trellis permutations. - `python3 tools/test_exl3_{codebook,reconstruct,ngram}.py`: OK. - Full `strata` target builds. ## Two bugs the parity tests cannot see The parity tests share the decode with the numpy reference, so only the BF16 base model can catch a decode error. Comparing against it found: - the trellis window read was a linear LSB bitstream read; ExLlamaV3 packs per 16-value span, MSB-first, then byte-swaps, and reads with a funnel shift (`unpack_trellis`/`dq`). Fixed in the numpy codec, the CPU decoder and both GPU kernels. - the loader was missing llama.cpp's converter transforms, so every GDN layer paired q/k/v from the wrong heads and the decay was wrong. Fixed, and checked on the real model by `check_engine_form.py`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:29:51 +07:00
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#3657
No description provided.