Repository navigation
core: backend-neutral EXL3 trellis reference decoder with an oracle fixture - #496
Merged
Merged
Conversation
…ixture The format reader the CUDA and Metal trellis decoders are checked against: the circular bitstream (E(p) ends, wrapping 16-bit windows), the 3inst/mcg/mul1 codebooks with their single fp16 rounding, tile placement, W_q unpack, su/sv sign expansion and the Hadamard-rotated dequantize. Written one bit at a time so it reads like docs/recipes/exl3.md; the fast per-backend kernels are the follow-up this module gates. The fixture (zig/tests/fixtures/exl3_oracle.bin) carries 27 codebook x width records of random tiles with the numpy decoder's exact states, codebook spot values, and one complete 128x128 Hadamard block of a real mcg @ 8.00 bpw group (Qwen3.5-2B geometry, self_attn.q_proj) with its scales and expected W_q / float64 dequantize. The tests reproduce all of it: states and W_q bit-exactly, dequantize within a few ULP (the Hadamard sums are exact products in f64; BLAS and this loop may order them differently). Run from the repository root: zig test zig/src/core/exl3_format.zig
Owner
|
Thank you, @akol1. A one-bit-at-a-time EXL3 reference with a fixture tied to the numpy decoder is a good oracle to have. This is merged into main (85aa565), with one fix of ours (5daebf6): |
This was referenced Oct 10, 2026
Closed
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
…ith an oracle fixture Thanks @akol1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A backend-neutral reference decoder for the EXL3 trellis format at
zig/src/core/exl3_format.zig: the circular bitstream (E(p) ends with wrapping16-bit windows, alternating KA/KA+1 for the mul1 half widths), the 3inst/mcg/mul1
codebooks with their single fp16 rounding, tile placement, W_q unpack, su/sv sign
expansion, and the Hadamard-rotated dequantize. Written one bit at a time so it
reads exactly like
docs/recipes/exl3.md; the fast per-backend tile decoders(CUDA fragments today, Metal
simdgroupmma per #494) are the follow-up thismodule gates and the correctness oracle they are checked against.
The fixture
zig/tests/fixtures/exl3_oracle.bin(371,478 bytes) carries:tiles with the numpy decoder's exact 16-bit states — 162 tiles, 41,472 state
comparisons, all bit-exact
UnstableLlama/Qwen3.5-2B-exl3-8.00bpw(mcg codebook, 8.00 bpw,layers.3.self_attn.q_proj, the 2B geometry the native Metal engine pins):trellis words, suh/svh scales, the expected W_q (bit-exact) and the float64
dequantized block
Tests
zig test zig/src/core/exl3_format.zigfrom the repository root (the workingdirectory every
zig build teststep runs from):W_q bit-exact; the dequantize compares within a few ULP because the Hadamard
sums are exact f64 products whose order BLAS and this loop may choose
differently (the tolerance is
1e-9 * (1 + max|want|), measured headroom isfar below it)
Both pass on Linux x86-64 with Zig 0.17.0 (the pinned
.zig-version); themodule is pure
stdand touches no Metal or CUDA code.Relationship to #494 and #490
This is the first slice of #494: the oracle a Metal trellis decoder must pass
tile by tile, landed where both backends can consume it. #490's HIP draft ships
its own EXL3 machinery inside the HIP backend; this module is the shared,
backend-neutral piece that the CUDA and Metal readers can both verify against.
The doc pointer in
docs/recipes/exl3.mdsays where it lives and how to run it.Receipt
zig-flashnext@ 1.0.2 lineage (f8fe17d), Zig 0.17.0, Linuxx86-64, no GPU involved.
against xet-backed Hugging Face repositories return wrong bytes outside the
first chunk (the reassembled chunks do not map linearly to file offsets), so
EXL3 fixture pulls must go through
huggingface_hub's downloader. Worth aline in whichever doc covers checkpoint fixtures.