Repository navigation
Conversation
- cuda/exl3/format.py: the EXL3 format as checkpoints store it (3inst, mcg and mul1 codebooks; 1 to 8 bits, and 1.5 / 2.5 / 3.5 with mul1), each tensor group parsed from the safetensors headers (bits, codebook, K, N, suh/su, svh/sv, bias), a numpy reference decoder, and require_config: a checkpoint's config.json checked before anything is downloaded. - cuda/exl3/decode.cuh: header-only device functions that decode a 16x16 tile of any codebook and width straight into mma.m16n8k16 B fragments. - python -m tensorfold.cuda.exl3.inspect MODEL_DIR: bits per category, codebooks, plain tensors and any unreadable group, from headers alone. - families: a family whose CUDA engine reads every codebook and width declares EXL3_VARIANT = "any" (EXL3_VARIANT_ANY); require_readable then refuses an EXL3 config the module does not read (an unknown codebook, a head width outside 1-8, an average outside 1-8 bits), naming the tested checkpoints. Nothing here imports torch. - tests/test_exl3_format.py: every codebook and width against a bit-by-bit decoder, group parsing, the inspector on a synthetic mixed checkpoint; tests/test_unsupported_checkpoints.py: the refusals.
The dense half of EXL3 support, for every family (docs/recipes/exl3.md): y = x @ W + bias for 1 to
128 rows with W = diag(suh) H W_q H diag(svh), no cuBLAS.
- cuda/exl3/linear.cu: rot_in (the input Hadamard) and the linear kernel: each warp owns a fixed run
of k tiles and decodes them straight into mma.m16n8k16 fragments with per-lane cached loads, one
128-column block and K split per program, K splits added in split order by the last program to
arrive (one atomic counter), fp32 sums, output Hadamard then * svh + bias. The k ranges depend
only on (K, N), so no output depends on how many rows are being computed.
- cuda/exl3/linear.py: Exl3Linear.load / from_tensors (strips or stored read order, packed su/sv
signs), plan(), out/xh/z buffers, fp16/bf16/fp32 in and out, optional scratch. A group the
index does not name is looked up in the shards' headers, and a group no shard holds is named in
the error ("<prefix>.trellis is in no file of <dir>").
- tests/cuda/test_exl3_linear.py: row invariance at 1, 2, 3, 16, 17, 64 and 128 rows, the device
decoder bit for bit against format.unpack, a float64 reference, and ExLlamaV3 when it is
importable. tests/cuda/test_exl3_checkpoint.py, with TENSORFOLD_EXL3_MODEL: every width of a real
checkpoint decodes bit for bit like ExLlamaV3's reconstruct, and the layer's forward matches
ExLlamaV3's.
- tools/bench_exl3.py: the layer against ExLlamaV3's LinearEXL3 on a checkpoint's own tensors (CUDA
graphs over enough copies to exceed L2).
…e next k step in flight At 1 and 2 bits a lane's windows span two 32-bit words of a 16x16 tile, so the warp loads its k step's words as one coalesced run (tile_words / 32 = 2 or 4 words a lane) and each lane takes its two words of a tile from their owners by shuffle, instead of every lane loading its own two through the read-only cache. The next k step's words are loaded while the current one is decoded, up to 6 bits; at 7 and 8 bits a step is 224 or 256 B of words a warp and the same build prefetching there reads 1-2% slower, so those widths load per tile. The reduction buffer is half as deep (a program now holds WK * min(M, 8) rows of 128 floats). Same arithmetic in the same order: 2472 outputs over every codebook, width, split and row count are torch.equal to the kernel before this commit. Measured on one DGX Spark (GB10), exclusive GPU, tools/bench_exl3.py (CUDA graphs over copies that exceed L2, median of 9 replays), rows 1/8/16, SM clock 2405-2418 MHz of 3003, before and after this commit in two exclusive slots of the same harness, GB/s at 1 row: MiMo-V2.6-Flash 2.50bpw 2-bit q_proj 4096x12288 157 -> 220 MiMo-V2.6-Flash 2.50bpw 2-bit o_proj 8192x4096 76 -> 186 MiMo-V2.6-Flash 2.50bpw 2-bit down_proj 4096x16896 79 -> 193 MiMo-V2.6-Flash 2.50bpw 3-bit q_proj 4096x12288 158 -> 192 MiMo-V2.6-Flash 2.50bpw 5-bit q_proj 4096x12288 188 -> 218 Qwen3.8-27B 3.00bpw 3-bit down_proj 17408x5120 163 -> 194 Qwen3.8-27B 4.00bpw 4-bit in_proj_qkv 5120x10240 196 -> 216 ExLlamaV3's own linear reads 176-233 GB/s on the same tensors in the same runs, so the 2-bit rows now come out at its level instead of 25-60% behind. Nothing measured was slower (the 6-bit heads are within 1.5%).
- cuda/exl3/experts.cu, experts_grouped.cuh, experts_cb{0,1,2}.cu: one
grouped trellis GEMV launch per projection covers a whole MoE layer
whose experts each carry their own width (1 to 8 bits in half-bit
steps) in the 3inst, mcg or mul1 codebook, read in place through
per-expert pointer tables; device grouping, input rotations, the SwiGLU
epilogue, and the down epilogue and the fixed-order combine fused into
one launch. No atomics, no host synchronisation, nothing allocated per
call, so a CUDA graph can capture it.
- cuda/exl3/experts.py: prepare / prepare_stacked / Scratch / routed /
dequant. Tile settings and K splits depend only on the shape.
- On 4-bit mcg experts with the GLM tile settings every kernel does the
GLM path's arithmetic in its order: per-slot and combined outputs are
bit-identical to families/glm5_next's exl3_mm.routed.
- tests/cuda/test_exl3_experts.py: the decode against a bit-by-bit
decoder for every codebook and width and against ExLlamaV3's
reconstruct; mixed-width rows alone equal the same rows in windows of
1, 2, 3, 16, 17, 64 and 128 (torch.equal); a float64 reference; GLM
parity at 1 to 16 rows; the lane map for every width; graphs captured
at 1, 2, 4 and 8 rows replay torch.equal to eager after allocator churn
and new inputs; the fused down + combine equals the two launches.
A request with "return_token_ids": true gets the reply's token ids in the response's "tensorfold" block (streamed replies: in the final chunk, also with stream_options.include_tensorfold), so drafted == serial can be checked by token-id SHA-256 through the OpenAI path of tensorfold serve. Nothing changes for a request that does not ask.
The qwen3_5 CUDA engine reads EXL3 packs (turboderp/Qwen3.8-27B-exl3, any codebook and width) as
well as the MLX 4-bit checkpoint. weights.load picks the path from the checkpoint's
quantization_config; the MLX path is untouched.
- cuda/exl3_load.py: an EXL3 pack loads into the same Config/Layer/Weights dataclasses the MLX
path fills in. Trellis groups run on the row-invariant EXL3 linear (cuda/exl3); the tensors the
pack leaves alone (the embedding, the GDN's in_proj_a/b, conv, A_log and dt_bias) are read as
stored. The layer keeps only its strip-ordered copy of the words.
- The packs store the five centred RMSNorm weights (input, post-attention, q and k norms, the final
norm) centred on 0, as the HF module computes x * (1 + w); the loader adds 1. The GDN's gated
norm, A_log, dt_bias, conv and in_proj_a/b carry no offset (checked tensor by tensor against the
MLX checkpoint).
- cuda/b16.{cu,cpp,py}: the plain fp16/bf16 linear for those unquantized tensors: one warp per
output, 16-byte loads, each lane's strided run of k summed in fp32 and the 32 lane sums added by
a fixed xor butterfly, so an element's bits depend on its own row and column only. No cuBLAS.
- exl3_load.PLANS: the (K split, warps) that were fastest at one and twelve rows for the down, GDN
qkv/z/out and attention o projections at 3 and 4 bits. Like plan(), a function of the shape and
width alone, so the rows of a verify window keep one reduction.
- cuda/dflash2.py: the drafter reads the target's 6-bit head over its draft vocabulary by slicing
the head's 128-column strips as they are stored, with the target's K split, so its logits are the
target head's bit for bit; nothing is decoded or requantized. The embedding is read by row. A
two-rank drafter still needs the MLX checkpoint's head.
- families/qwen3_5: turboderp/Qwen3.8-27B-exl3 among the tested checkpoints, QUANT_METHODS
cuda = (mlx, exl3), EXL3_VARIANT = "any".
- tests/cuda/test_qwen27_exl3.py: every tuned split keeps a row's bits alone or among 16; a GDN
verify window on EXL3 and plain weights equals serial steps, rows and committed state; drafted
decoding keeps serial's tokens; the sliced head equals the target head. With
TENSORFOLD_QWEN27_EXL3 and TENSORFOLD_QWEN27_DRAFTER, the real pack's drafted replies equal
serial by SHA-256 of the token ids (greedy and two seeds).
The qwen4_exp CUDA engine reads EXL3 packs of Qwen3.8 Flash Next as well as its MLX 4-bit checkpoint: any codebook, a width per tensor (mixed-K packs such as a 2-8 bit SAGE pack), one GPU. The MLX path is unchanged; weights.load hands an EXL3 pack to cuda/exl3.py, which fills the same Weights dataclasses. - Dense trellis groups (attention, DeltaNet, MTP fc, head) on the row-invariant EXL3 linear; projections reading the same input are stacked side by side, and at one row each part writes straight into its column slice (no scratch copy). - Routed experts and the shared expert (as expert 512 of one table) on the grouped EXL3 expert kernel, each expert matrix at its own width. The fp32 router, its top-k with id tie-break and the slot-ordered write-back are the MLX path's; the EXL3 branch takes the top-k alone (moe.select_rows), since the expert kernel groups the window itself. - Tensors the packs leave unquantized (hyper-connection down/inject/up, DeltaNet in_proj_a/b, n-gram key/value) on an fp16 Triton matmul whose tiles and K split depend on the shape only. - The n-gram tables are ExLlamaV3's row codec, not EXL3 tiles: a row is an fp16 scale and 160 values of K bits in a tail-biting mul1 trellis, plus a per-head bias. ple_rows decodes them as ngram_dequant does; the rows stay in the checkpoint, memory-mapped. - The packs store every centred RMSNorm weight as gamma - 1 (hyper-connection, q/k, indexer, n-gram and MTP input norms): the loader detects it and adds 1 in fp32. DeltaNet's gated norm, A_log, dt_bias, conv weights and the router are the MLX checkpoint's values. - turboderp's packs keep the MTP mixer in mtp_hyper_connection_mixer_patch.safetensors, outside the index; the reader takes it from there. - MTP drafts: the head's draft-vocabulary rows decoded through the EXL3 linear and requantized to 4-bit groups of 32 for the draft head (drafts change speed only; verify uses the full head). - families/qwen4_exp: QUANT_METHODS cuda = (mlx, exl3), EXL3_VARIANT = "any"; check() accepts an EXL3 pack and notes a missing MTP head. - tests/cuda/test_qwen4_exp_exl3.py: the fp16 matmul against fp64 and row-invariant (windows of 1, 2, 3, 16, 17, 64, 128 rows); ple_rows bit-equal to the row codec at 2-8 bits. With TENSORFOLD_EXL3_FLASHNEXT=<pack>: the centred norms, n-gram rows bit-equal to ngram_dequant, a real layer's experts against fp64 and row-invariant, and the model cut to 4 layers: windows of 1..128 rows give one-row steps' logits bit for bit, a kept prefix continues like serial, and MTP-drafted decoding (eager and CUDA graphs, greedy and sampled) emits serial's tokens.
…X checkpoints - docs/recipes/exl3.md: the format, what a family declares, using the module, the layer's arithmetic, a kernel table, the linear against ExLlamaV3's on real tensors, and the traps. - docs/recipes/exl3-universal-experts.md: the grouped routed-expert kernel, where the width enters, against ExLlamaV3's mixed-K and coop dispatch on MiMo-V2.6-Flash's real experts, and how its exactness is checked. - docs/recipes/qwen3.8-27b.md, qwen3.8-flash-next.md: serving the EXL3 packs, drafted == serial, agreement with ExLlamaV3 on the same packs, speed against ExLlamaV3 and the MLX checkpoint. - docs/recipes/cuda.md, docs/recipes/README.md, README.md, families/README.md, families/qwen3_5/cuda/README.md: the module, the checkpoints and the kernels. - THIRD_PARTY_NOTICES.md: the ExLlamaV3 entry covers the shared module, the expert kernel and the two families' EXL3 readers; the EXL3 packs the families list, with their licenses.
|
Two follow-ups, both from runs that finished after I opened this. Timing re-measure on
The two 27B drafted cells read about 4% lower on this branch than in the earlier session while the ExLlamaV3 cell reads the same, and I do not want to sell that as either a regression or a match: this box's run-to-run spread on this model is wider than that (in one arm the five reps ranged from 56.2 to 78.9 tok/s). The tables above stay labeled with the commit each number came from. If you would rather see every cell re-run on the branch, I will spend the hour. The per-commit row for Codebooks. |
|
Thanks @vcruz305, this is a big and careful piece of work, and beating ExLlamaV3 on its own packs is a strong result. We're reviewing it now and targeting 0.3.6, after tonight's 0.3.5: it needs to merge with 0.3.5's CUDA changes, and we'll run the exactness and speed checks on our Sparks. Your commits will land under your name, and review notes will follow here. |
|
Phenomenal work! |
|
EXL3 on CUDA is in 0.3.6 as experimental: your eight commits (b16fb91 through 654e4ad) shipped under your name. Both packs are exact on the lanes: 9/9 drafted equal to serial, resumed prompts 6/6, and four concurrent streams equal their solo runs. On one DGX Spark against vLLM with MTP=3, the 27B pack decodes 1.62-3.56x and Flash Next's 1.79-1.91x, and Flash Next's pack admits its full 262k window with 21 GiB less GPU memory. Prompt processing is about half the MLX checkpoints' speed today. An FP8 prompt path over your decoded tiles is next, in 0.3.6.1. Thank you for a careful, well-measured PR. #47 is next in line. |
…on engine's EXL3 module (#42)
Main keeps its newer app work and its credits page; the release brings the engine changes since 1.0.10, followed by the EXL3 docs and credit (#42).
…rts for every codebook and width The merged commit is #837's with its author, date and message, without its five fixture scripts under zig/tests/cuda/oracle/: they import the Python engine, which does not land here. The tests still read recorded bytes from a folder when one is given. The kernel list, the runtime's exports, the test runner's usage and qlinear's weight views take both sides. #837's kernels port the Python engine's EXL3 module from #42. Co-authored-by: vcruz305 <[email protected]>
…nsorfold block The #840 row (Python #42, @vcruz305): a request that sends return_token_ids gets the reply's token ids in tensorfold.token_ids, the same slice token_sha/token_sha256 hash, on the whole reply and on the streamed finish event. Without the flag, replies are unchanged. Co-authored-by: vcruz305 <[email protected]>
TensorFold's CUDA engines can now read ExLlamaV3's trellis checkpoints (EXL3) in any linear, at whatever width the checkpoint keeps per tensor, with one kernel shared by every family. Two engines use it in this PR: Qwen3.8-27B (2 to 6 bits,
mul1) and Qwen3.8 Flash Next, including mixed-K packs where one expert matrix sits at 2 bits and the next at 8.The real checkpoints I have on this box are the 27B at
3.00bpwand4.00bpw, Flash Next's mixed-K SAGE pack and turboderp's3.05bpw, and MiMo-V2.6-Flash's2.50bpw.mcgand3instare verified bit-exact against ExLlamaV3'sreconstructon real converter output, 50 of 50 groups each, from partial packs. Their full-pack conversions were still running while I wrote this, so beyond that specific check the two codebooks rest on synthetic data, and I say so below rather than leaving it to be discovered.Speeds on one DGX Spark, greedy, same client for both engines. The 27B
3.00bpwpack with the DFlash2 drafter decodes at 63.2 / 45.7 tok/s (code / chat) against ExLlamaV3's 39.6 / 30.1 on the same pack and drafter. Flash Next's SAGE pack reads 47.3 / 67.3 against ExLlamaV3's serial path at 22.3 / 22.2. Drafted replies are identical to"draft": falsereplies by token-id SHA-256 on both families, 30 of 30 replies each. That is the check I ran the most times, because it is the one the engine's contract stands on.Nothing here changes an existing path. GLM-5.3-Flash's own EXL3 kernel is untouched and the MLX 4-bit engines of both families are unchanged. The diff is 49 files, +5,673 / -37, 8 commits, no merge commits, based on
bb4b4a3.What is in it, commit by commit:
28ef5a4, the format, for every codebook and width.src/tensorfold/cuda/exl3/format.pyparses a checkpoint's tensor groups out of the safetensors headers alone (trellisint16[K/16, N/16, 16*bits],suh/svhor the packedsu/svsigns, an optionalbias, and the zero-sizemcg/mul1marker), names the codebook and the width per tensor, and carries a NumPy float64 reference decoder for every codebook at 1 to 8 bits plus the half widths (mul1).decode.cuhholds the header-only device functions that decode a 16x16 tile straight into the B fragments of twomma.m16n8k16.python -m tensorfold.cuda.exl3.inspect MODEL_DIRprints what a checkpoint holds from its headers without loading it. A family that reads every codebook and width declaresEXL3_VARIANT = "any", and TensorFold then checksconfig.jsonbefore anything is downloaded (src/tensorfold/families/__init__.py).pyproject.tomlgains the new*.cu/*.cuhpackage data. Tests:tests/test_exl3_format.py(a bit-by-bit decoder for all 27 codebook and width combinations, the group parsing, the inspector on a synthetic mixed checkpoint) andtests/test_unsupported_checkpoints.py(the refusals). Nothing in this commit imports torch.2be548d, a row-invariant EXL3 linear, 1 to 128 rows.src/tensorfold/cuda/exl3/linear.{py,cu,cpp}:y = ((((x * suh) @ H_K) @ W_q) @ H_N) * svh + bias, no cuBLAS, no split-K that depends on the row count, no reduction across rows. The K split and the warps a program uses are a function of(K, N)only, the splits are summed in split order, andmma.m16n8k16keeps rows independent, which is the CUDA recipe's verify contract.tools/bench_exl3.pytimes it against ExLlamaV3'sLinearEXL3.bc.runon a checkpoint's own tensors, with CUDA graphs over enough copies to exceed L2. Tests:tests/cuda/test_exl3_linear.py(row invariance at 1, 2, 3, 16, 17, 64 and 128 rows, the device decoder against the reference bit for bit, a float64 reference, ExLlamaV3 when it is importable) andtests/cuda/test_exl3_checkpoint.py(a real checkpoint's every width againstreconstruct).b16f2db, the low-bit loader. At 1 and 2 bits a lane's windows span two 32-bit words, so a warp now loads its k step's words as one coalesced run, takes each tile's two words from their owners by shuffle, and keeps the next k step in flight while the current one decodes. That holds up to 6 bits; at 7 and 8 bits it measured 1 to 2% slower, so those widths load per tile. Same arithmetic in the same order: 2472 outputs over every codebook, width, split and row count aretorch.equalto the kernel before this commit.1703060, grouped routed experts, mixed widths inside a layer.src/tensorfold/cuda/exl3/experts_{grouped.cuh,cu,cpp,cb0.cu,cb1.cu,cb2.cu}andexperts.py: one grouped trellis GEMV per projection runs a whole MoE layer in one launch, each expert matrix at its own width (1 to 8 bits in half-bit steps) in any codebook. The codebook is the compilation unit, the widths present in a layer are the instances built, the trellis stays where the checkpoint put it (an expert is a pointer), the grouping happens on the device, and there are no atomics or host synchronisations, so a CUDA graph can capture the pipeline.tests/cuda/test_exl3_experts.pyruns the decode against a bit-by-bit decoder and against ExLlamaV3'sreconstruct, rows alone against the same rows in windows of 1, 2, 3, 16, 17, 64 and 128, a float64 reference, graph replay against eager after allocator churn, and the fused down+combine against the two launches it replaces.ad19d4a,"return_token_ids"on the CUDA server (src/tensorfold/cuda/server.py, 6 lines). The reply's token ids ride in the response'stensorfoldblock, and in the final chunk withstream_options.include_tensorfoldwhen streaming. That is how drafted == serial gets checked through the OpenAI path. Nothing changes for a request that does not ask for it.4b95136, Qwen3.8-27B on EXL3.src/tensorfold/families/qwen3_5/cuda/exl3_load.pyfills the sameConfig/Layer/Weightsdataclasses the MLX path fills. The pack's trellis groups run on the shared linear, tensors the pack leaves alone are read as stored, the packs' centred RMSNorm weights (w - 1) get their 1 back, andexl3_load.PLANSholds the measured(K split, warps)per projection shape at 3 and 4 bits, a function of shape and width alone, so a verify window keeps one reduction.cuda/b16.{cu,cpp,py}is the plain fp16/bf16 linear for the unquantized tensors (one warp per output, no cuBLAS).cuda/dflash2.pylets the DFlash2 drafter read the target's 6-bit head over its draft vocabulary by slicing the head's 128-column strips as stored, so the drafter's logits are the target head's bit for bit and nothing is decoded or requantized.tests/cuda/test_qwen27_exl3.pychecks that every tuned split keeps a row's bits, a GDN verify window against serial steps on both weight paths, that drafted decoding keeps serial's tokens, and the sliced head against the target head.f836a4b, Qwen3.8 Flash Next on EXL3.src/tensorfold/families/qwen4_exp/cuda/exl3.py(718 lines) fills the same weight structures: dense groups (attention, DeltaNet, MTP, head) on the shared linear with same-input projections stacked side by side, routed experts and the shared expert (as expert 512 of the table) on the grouped kernel at their own widths, the packs' unquantized tensors on an fp16 Triton matmul whose tiles and K split depend on the shape only, and theple.ngram_embeddingshards through ExLlamaV3's n-gram row codec, where a row is an fp16 scale and 160 tail-bitingmul1values, decoded bit for bit likengram_dequant. MTP drafts decode the head's draft-vocabulary rows and requantize them to 4-bit groups for the draft head; verification uses the full EXL3 head.tests/cuda/test_qwen4_exp_exl3.pychecks the fp16 matmul against fp64 and its row invariance, the n-gram rows bit-equal to the row codec, a real layer's experts against fp64, and the model cut to 4 layers: a window of 1 to 128 rows gives one-row steps' logits bit for bit, a kept prefix continues like serial, and MTP-drafted decoding (eager and in CUDA graphs, greedy and sampled) emits serial's tokens.d409822, docs and notices.docs/recipes/exl3.md(the format, what a family declares, the layer's arithmetic, the kernel table, the traps),docs/recipes/exl3-universal-experts.md(the grouped kernel and the measured comparison against ExLlamaV3's two dispatch paths), the EXL3 sections ofdocs/recipes/qwen3.8-27b.mdanddocs/recipes/qwen3.8-flash-next.md,docs/recipes/cuda.md, the two recipe lists,README.md,src/tensorfold/families/README.md,src/tensorfold/families/qwen3_5/cuda/README.md(its kernel table gainsb16.cuandexl3_load.py), andTHIRD_PARTY_NOTICES.md, where the existing ExLlamaV3 entry (MIT, Copyright (c) 2025 Turboderp) now covers the shared module, the grouped expert kernel and the two families' EXL3 readers, and the checkpoints the families list are named with their licenses. The README's speed table and the hero image that mirrors it are unchanged: this PR adds two rows to its checkpoint table (both EXL3 packs, NVIDIA only) and keeps the speeds in the two recipes.Measured on a GB10 (DGX Spark)
One DGX Spark (GB10, driver 580.178.04, CUDA 13.0 through torch 2.11.0+cu130, 128 GB unified, SM clock 2405 to 2418 MHz of 3003 during the timing sessions). Every timing row comes from a
gpurun timingsession with the GPU otherwise idle and the page cache of each pack dropped before its server starts. The client is the same for every engine,tools/bench_openai.py --tokens 64 --reps 5(one warm-up, seeds 1234-1238, greedy as temperature 0), and the cell is the median of the five. Each column names the commit its numbers came from. "ExLlamaV3" always means the fork at commit249f22a, whose package reports1.5.1.post1; the commit and the version string name the same tree.The kernels, against ExLlamaV3's
Dense linear,
tools/bench_exl3.py, medians of 9 CUDA-graph replays on an idle GB10, the checkpoint's own tensors, the ExLlamaV3 fork at249f22aon the same tensors (4c37180;docs/recipes/exl3.mdcarries the same table):layers.0.self_attn.q_projlayers.0.self_attn.q_projlayers.2.self_attn.o_projlayers.2.self_attn.o_projlayers.41.self_attn.o_projlayers.41.self_attn.o_projlm_headlm_headThe loader commit (
b16f2db) measured against the commit before it, same harness, two exclusive slots, GB/s at 1 row: MiMo 2-bitq_proj157 -> 220, 2-bito_proj76 -> 186, 2-bitdown_proj79 -> 193, 3-bitq_proj158 -> 192, 5-bitq_proj188 -> 218, 6-bitlm_head227 -> 232; 27B3.00bpw3-bitdown_proj163 -> 194 (160 -> 187 at 8 rows, 153 -> 180 at 16),4.00bpw4-bitin_proj_qkv196 -> 216. Nothing measured got slower, and the 6-bit head cells are within 1.5%. ExLlamaV3's own linear reads 176 to 233 GB/s on the same tensors in the same runs, and the 237 GB/s streaming ceiling of this box is the rest of the gap.Grouped routed experts, MiMo-V2.6-Flash-RL-EXL3
2.50bpwreal layers (mul1, per-expert 2 to 5 bits),tools/mimo_exl3_bench.py, medians of 5 reps x 30 iters x 2 sets, GB/s over the trellis bytes actually read (4c37180/f836a4bparents;docs/recipes/exl3-universal-experts.mdhas the same table with the intermediate row counts):exl3_moe_mixedkexl3_moe_coopThe part that matters for reading that table: MiMo's layers are mixed-K, so what ExLlamaV3 actually dispatches there is its per-expert
exl3_moe_mixedkpath, and this kernel is 1.5x to 3.6x faster per layer. Where a layer is uniform, ExLlamaV3 dispatches itscoopkernel instead, andcoopis still the faster of the two on this box. On the uniform L3 layer the two are within 2% (179.6 against 177.8 at 1 row, 219.6 against 220.2 at 8), and on the GLM-5.3-shaped synthetic 4-bitmcglayercoopreads 219 to 232 GB/s against 208 to 220 here. This work does not beatcoopon uniform layers. It removes the mixed-K penalty and lands atcoop's level rather than above it. The dense table says the same thing: ExLlamaV3 is ahead on the small-N 3-bit shapes at 16 rows (184 against 198 GB/s) and on the 6-bit 16-row cells (203 against 217, 222 against 229).Qwen3.8-27B, EXL3 packs and the MLX 4-bit checkpoint
tensorfold serve, or ExLlamaV3'sGeneratorbehind a minimal OpenAI shim (-cs 8192), DFlash2 at its default 7 drafts. Dynamic draft length was slower on every column. Cells are code / chat, as the project's README table has them. Every number in this table comes from4c37180onwip/exl3-engines, measured before this branch existed, so treat it as this code's numbers rather than this branch's; a re-run onpr/exl3is in flight and I will paste it in a comment. The 27B rows useturboderp/Qwen3.8-27B-exl3revision6fe61ad6(3.00bpw) and113cf7ab(4.00bpw), drafted withz-lab/Qwen3.8-27B-DFlash2.GB/tokenis the weight bytes one serial decode step reads (every linear, the head, one embedding row, the norms) at the bits per weight the engine actually holds. The bandwidth floor at the measured 237 GB/s streaming ceiling of this box is 23.4 tok/s at3.00bpwand 18.0 at4.00bpw, and the measured serial step is 16.7 and 14.5, so a step is 59.4 ms of wall time against a 42.8 ms floor. On the GPU that step is 57.8 ms, of which the EXL3 projections are 51.9 ms for 10.1 GB (194 GB/s) and the 6-bit head alone 238 GB/s. What is left is drafting: the tree verifies several rows a round, and the recipe's step profile plus the--no-draftsrows above is the bookkeeping behind it. Sampled columns are indocs/recipes/qwen3.8-27b.md; 3.00bpw code sampled is 82.1 (ours) against 45.0 (ExLlamaV3).Quality, same eval set and engine, teacher-forced (
~/tfwork/results/qwen27b-quality.md; wikitext-2 test, 16 x 1024-token windows, 16,368 scored positions, full 248,320-token vocabulary, fp64 sums):The 3.00bpw pack beats the MLX 4-bit checkpoint on every measure here and is cheaper to read (KLD 0.0431 against 0.0480, 10.14 against 14.42 GB/token) even though the MLX pack is nominally wider. The arithmetic floor of this measurement is KLD 2.11e-04, because the engine returns bf16 logits. Brackets and the row-level caveats are in the file the table comes from.
Qwen3.8 Flash Next, both EXL3 packs
Cells are code / chat, greedy and sampled, median of seeds 1234-1238. Every number here comes from
5e76c85onwip/flashnext-exl3, measured before this branch existed. ExLlamaV3 (249f22a) has no draft support for this model, so its column is its serial path.Two things about that table. The SAGE pack's code prompt emits a real
<think>block where the other packs and the chat prompt do not, so SAGE's drafted row is a much longer reply than its neighbours: the numbers are real, the comparison across packs is not, though SAGE's own serial against drafted pair is. And SAGE is a mixed-K pack of ours, so it is the one row here with no ExLlamaV3 counterpart for drafting at all.Serially, on the mixed-K pack TensorFold is 1.51x to 1.55x ExLlamaV3's serial path, and on the uniform 3.05bpw pack it is 5 to 6% behind it (34.9 against 37.0). That pack is one ExLlamaV3 has tuned for, and it is the one place in this PR where ExLlamaV3's serial decode wins. Both EXL3 packs are also 5 to 9% behind TensorFold's own MLX 4-bit path in serial. With drafts, both packs beat ExLlamaV3's serial speed by 1.5x to 2.1x.
On the same packs, teacher-forced over 2,048 positions, the two engines' mean NLLs agree within 0.0005 (SAGE 1.0640 against 1.0642; 3.05bpw 0.8510 against 0.8506) and their top-1 accuracies within half a point (0.718 against 0.720; 0.774 against 0.779). The per-position NLL difference has a mean absolute value of about 0.10 and a median of 0.018 / 0.011, which sounds large next to the agreement figures, so here is the context: ExLlamaV3 reproduces its own top-1 on only 96.4% (SAGE) and 97.2% (3.05bpw) of positions when the same text is split differently, meaning the first 1,025 tokens on their own instead of as part of all 2,049. Where its top two logits are at least 0.5 apart the two engines agree on 98.8% / 99.1% of positions, and 99.7% at a gap of 1.0. Two engines that keep near-ties differently look like this.
Measured after this branch was frozen, and belonging to the follow-up PR rather than this one: the same
3.05bpwpack with TensorFold's newer default drafting policy (depth 6, confidence 0.6) reads 91.6 / 71.8 / 55.3 tok/s (code / devops / prose, 400 tokens, min-median-max of 3) against TabbyAPI on this box at 87.2 / 63.9 / 54.9, with serial at 36.0 to 36.1 and the best policy measured at 94.5 (depth 7, confidence 0.75). At 128 tokens it is 77.1 / 59.4 / 54.1 against 76.2 / 56.7 / 55.1, at 64 tokens 82.4 / 56.7 / 56.6 against 83.6 / 57.6 / 61.2, so prose is behind at very short replies. Time to first token is 0.14 to 0.18 s against 0.51 to 0.77 s. TabbyAPI runs the recipe's 8-bit KV where ours is bf16. Nothing on this box reached 100 tok/s in any arm: the best single request was 94.46 (TensorFold, code, 400 tokens), then exllamav3's 89.52 and the recipe's ownchat.pyat 80.04. Greedy replies diverge between the two engines inside the first 10% of the reply (first differing token: code 7 of 400, devops 48, prose 26). TensorFold's replies are identical across repeats, TabbyAPI's are not. Those numbers, the policy sweep and the changes behind them live in~/tfwork/results/flashnext-recipe.md.Tests
Host suite, no GPU, the same command and
--ignoreset on every tree:upstream/mainbb4b4a3: 4 failed, 130 passed, 27 skipped in a venv with no torch (~/tfwork/venv-notorch: numpy, tokenizers, jinja2, safetensors, huggingface_hub, pytest), and 4 failed, 130 passed, 27 skipped with torch present (~/tensorfold/venv,CUDA_VISIBLE_DEVICES=).28ef5a4throughd409822, same command on the no-torch venv: 4 failed, 167 passed, 28 skipped, the same counts on all eight commits.d409822on the torch venv: 4 failed, 168 passed, 27 skipped. The 27 against 28 skip difference between those two rows is the venv, where one MLX-only test skips rather than passes when torch is present, not the branch.upstream/main, none of them ours: this box has no MLX (test_nucleus_without_top_k_matches_the_whole_vocabulary_drawimportsmlx.core), the CLI refuses a model with no CUDA engine before the context check (test_context_override_cannot_exceed_model_window), and the other two import a family's MLX kernel package (test_every_family_names_an_importable_kernel_version,test_serve_finishes_a_config_only_cache_before_loading).tests/test_exl3_format.py36 passed, 1 skipped (no-torch venv), andtests/test_unsupported_checkpoints.py9 passed, against 8 onupstream/main.~/tfwork/scratch/p/host/summary.txtand~/tfwork/scratch/p/host/notorch_<rev>.log.CUDA tests, run from the installed wheel built at the tip with nothing on
sys.pathbut the wheel. The tests are copied out ofgit archive d409822with--rootdiroutside the source tree, so a stale source tree cannot be what ran. One file per invocation, so each count stands on its own, withninjaonPATHand a freshTORCH_EXTENSIONS_DIR:The 18 skips in the expert file are the ExLlamaV3 comparison cells this ExLlamaV3 fork cannot instantiate: the half-integer widths only exist with
mul1, and itsreconstructstops at 3.5. After the run the extension cache held six.sofiles for six extension directories, so every kernel this branch ships got built from this source inside the run.One thing worth knowing about that first attempt: it failed with 187 errors, and the cause was environmental, not this branch. The JIT builds died because
ninjawas not onPATH, which left empty extension directories behind, and the next import of each of those found a directory with no.so. Those runs are not in the numbers above. If you build these tests yourself, putninjaonPATHand clearTORCH_EXTENSIONS_DIRfirst.Per-commit evidence. Each commit checked out detached in its own worktree (
~/tfwork/wt/p-commits) with its ownTORCH_EXTENSIONS_DIR, because the two linear commits share the extension nametensorfold_exl3_linear_v2and no commit should be served another's.so. Real packs named by the same environment variables.28ef5a4tests/test_exl3_format.py+tests/test_unsupported_checkpoints.py)2be548dtests/cuda/test_exl3_linear.py+test_exl3_checkpoint.py)b16f2db1703060tests/cuda/test_exl3_experts.py)4b95136tests/cuda/test_qwen27_exl3.py, 66 s). The per-commit run got 8 passed and then hung intest_window_rows_equal_serial_steps, ten minutes asleep with the GPU idle, so it was killed and is not counted. Re-run afterwards at this commit with its ownTORCH_EXTENSIONS_DIR: 35 s, passed. The hang was a build lock in the extension directory that eight commits sharedf836a4btests/cuda/test_qwen4_exp_exl3.py)ad19d4areturn_token_idsd409822Row invariance and exactness, as the recipe book asks (
torch.equal, neverallclose):tests/cuda/test_exl3_linear.py);tests/cuda/test_exl3_experts.py);reconstructbit for bit;torch.equalto GLM-5.3-Flash's ownexl3_mm.routedon 4-bitmcgdata, GLM's arithmetic in the same order, and within 2e-4 relative of a float64reconstruct-based reference;Drafted == serial through
tensorfold serve, comparing the token-id SHA-256 of every reply between"draft": falseand drafts on (two prompts, the raw prompt as chat, two 256-token chats, greedy and seeds 1234-1238):5e76c85, and the same 30 of 30 with the same aggregates onpr/exl3atd409822, from the installed wheel throughtensorfold serve(~/tfwork/results/p/sha_fn-3.05.json).pr/exl3atd409822(~/tfwork/results/p/sha_q27-3.00.json). The 27B server does not report draft tallies the way Flash Next's does. The same harness onwip/exl3-enginesat4c37180gave 12 of 12 replies on3.00bpwand 12 of 12 on4.00bpw, greedy and five seeds.5e76c85(4,224 tokens, 1,444 rounds, 2.93 tokens a round).Style and hygiene. LF in the index,
git diff --checkclean,git ls-files --eoli/lf for every file I touched. No version bump. Torch is imported only inside engine modules, since the CLI imports every family on the Mac too. New*.cu/*.cuhpackage data inpyproject.toml. Versioned extension names (tensorfold_exl3_linear_v2,tensorfold_exl3_experts_v1).ruff check --select E4,E7,E9,F,E501,W --line-length 120over the 27 changed.pyfiles reports 17 findings; the same command on the 13 of those files that exist onupstream/mainreports 10, all of them still present (5 E501, 4 E741, 1 F401). The 7 new ones are all E741, usingIas the expert width incuda/exl3/experts.pyand its test, a rule the tree already carries 50 of. I can fold a rename in if you would rather have those files clean.Overlap with other open PRs
Checked with
git merge-tree --write-treeagainst each open external PR's head as I wrote this, and by intersecting changed-file lists:git merge-treevspr/exl3README.md,docs/recipes/README.md,src/tensorfold/families/README.md,THIRD_PARTY_NOTICES.mdREADME.md,docs/recipes/README.md(both merge cleanly withupstream/main)README.md,docs/recipes/README.mdREADME.md(clean withupstream/main)README.mddocs/recipes/qwen3.8-flash-next.md,docs/recipes/README.md,README.md,src/tensorfold/families/__init__.pydocs/recipes/qwen3.8-27b.md,README.md,src/tensorfold/families/qwen3_5/__init__.pysrc/tensorfold/cuda/server.pyREADME.mdI will rebase on whichever of those lands first. The only real overlap is a table row and a list line in
README.mdanddocs/recipes/README.md, so it is a small conflict either way.What is not claimed
families/glm5_next/cuda/exl3.py, 4-bitmcg, routed experts only) is untouched by this PR, and there was no GLM EXL3 checkpoint on this box. What I checked is parity on GLM-5.3-shaped synthetic 4-bitmcgdata against GLM's ownexl3_mm.routed,torch.equal, not on a real GLM pack.mul1is verified on real packs: every quantized tensor ofturboderp/Qwen3.8-27B-exl34.00bpwdecodes bit for bit like ExLlamaV3'sreconstruct, 409 of 409 groups, and the same holds for the MiMo pack and the Flash Next packs through their family tests.mcgand3insthave real partial packs here, 50 of 50 groups each and bit-exact, including themcgmarker values and the absence of markers in3inst. The full-pack conversions formcg,3instand a mixed per-tensor recipe were still running, so I have not measured agreement, NLL or speed on those packs. Everything else about those two codebooks, and the half-bit widths, rests on synthetic data plus the NumPy reference and the bit-by-bit decoder, plus the 4-bitmcgparity above.exl3_moe_cooppath reads 219 to 232 GB/s on uniform layers against 208 to 220 here, up to about 5%. ItsLinearEXL3wins several 16-row cells of the dense table (3-bit small-N: 198 against 184 GB/s; 6-bit: 217 against 203 and 229 against 222). On the 27B's4.00bpwpack its serial decode is 10% ahead (15.8 against 14.5 tok/s), and on Flash Next's uniform 3.05bpw pack 5 to 6% ahead (37.0 against 34.9).qwen3_5orqwen4_exp, so every long-context number here is a bf16 KV cache against the recipe's-cq 8,8. The engine's context capacity is fixed at start and one stream decodes at a time, both documented in the two recipes' Limits sections.Not in this PR
MiMo-V2.6-Flash's engine is a follow-up: the grouped expert kernel this PR adds is what it needs, but its reader, its bench and its numbers are not here. The Flash Next serving improvements measured while this branch was frozen are also a follow-up, covering per-shape K splits, the graph-captured draft pick, 128-row prefill chunks instead of 64, and the depth-6 / confidence-0.6 default drafting policy that takes the
3.05bpwpack to 91.6 / 71.8 / 55.3 tok/s at 400 tokens against TabbyAPI's 87.2 / 63.9 / 54.9 on the same box. Their numbers, tables and method are in~/tfwork/results/flashnext-recipe.md, and none of it is in any commit of this branch. One line to be plain about where that stands: cold 24k prefill is 481 tok/s against TabbyAPI's 642 on this box and the recipe's published 1,129, so prefill is the known weak spot rather than decoding. Both follow-ups are separate PRs, offered once this one is in and rebased on it.If you would rather review this in two pieces, the kernel infrastructure (
cuda/exl3/*plus the server'sreturn_token_ids) and then the two families that use it, say so and I will split it at that boundary. That is exactly where the branch's commits already fall.