mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1764] [CLOSED] EXL3: run the EXL3 trellis format on the engine #3657
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3657
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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+)
e1c6774EXL3: run the EXL3 trellis format on the engineabe5609EXL3 model-open path: load and run an EXL3 model in the engine33985aeEXL3: decode the trellis with ExLlamaV3's window read1660ea8EXL3: stage the GDN weights the way the converter does7c38149EXL3: check the staged weights against the converter's transformsf9d8415docs/EXL3: the engine's form of the weights, and the measured end-to-end numbers4274b8dEXL3: check every released branch's decode on its own weights025566bEXL3: keep the routed experts in VRAM (--expert-cache, per layer)e708df8docs/EXL3: the VRAM expert cache and the steady-state numbersbb17322EXL3: 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:
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
src/kernels/cpu/exl3.cpp. Decode LUT, sliding window, tensor-core perm, H128, folded GEMV, ngram row.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.src/artifact/exl3_pack.cppbuilds the engineWeightTablefrom the model directory (1079 roles): the EXL3 linears attached asExl3Mat, the norms/router/hyper-connection/GDN parameters/embedding staged in the engine's form. Plusinclude/strata/artifact/{safetensors,exl3_model}.hpp.PleTable::open_exl3.WeightRef::exl3+gemv_quantized(src/core/layer.cpp),--exl3/--ple-exl3ingenerate.cpp.Bitrates
Every released branch is checked on its own weights (
tools/exl3/fetch_branch_tensors.pypulls one expert and one dense linear from each branch's shards,strata-exl3-gpucompares the GPU decode-GEMV against the CPU reference on them):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.--expert-cache 0Five passes on the decode path, each measured on its own:
--expert-cacheper layer,auto/unset sizes it from the free VRAM; without it the stream reads and uploads 890 MB per token)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 staginggr_inject/gr_downgiven four partial sums (one block of four warps walked 10,240 elements in 320 dependent steps)strata-exl3-moe(T=2 0.385 -> T=4 0.308 ms/layer, -20%)native_mmvq(measured with the experts skipped, so it prices the dense work alone: 47.4 -> 28.9 ms/token)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-poolon 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_kernelstages the wholexn(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 infused_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-moeruns 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_requantizedallocates 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_dotcostsabout 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 servedby 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=exl3keeps 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 tomatch, so the requantizer runs
stage_exl3's own host-side reorder before it reconstructs. Without it thosethree 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 theGPU 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_parityK=1..8;exl3_gemv_parityK=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.stratatarget 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:
unpack_trellis/dq). Fixed in the numpy codec, the CPU decoder and both GPU kernels.check_engine_form.py.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.