Repository navigation
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
zig/tests/fixtures/exl3_oracle.bin is a shipped binary; this tool regenerates it. Default arguments reproduce the committed bytes exactly (sha256 verified against the fixture PR ashhart#496 ships): 27 codebook x width synthetic records from a fixed rng seed, 384 codebook spot values, and one real 128x128 Hadamard block from the 8.00 bpw Qwen3.5-2B pack - the geometry the native Metal engine pins. The values come from TensorFold's numpy EXL3 decoder (the python-0.6 line), so the Zig reference decoder is validated against the implementation the CUDA reader already trusts; point TENSORFOLD_SRC at that checkout's src directory when the package is not installed. Checkpoints go through huggingface_hub's downloader: plain HTTP range requests against xet-backed repositories return wrong bytes outside the first chunk, which is worth knowing for any future fixture work. Rerun it after any change to the numpy decoder's arithmetic; a mismatch means the Zig oracle and the numpy decoder have drifted and one of them is wrong.
Owner
|
Thank you, @akol1. #496's decoder and its oracle fixture landed tonight (85aa565), with our fix for rectangular layers (5daebf6). We're removing Python from the repository rather than adding to it, so we're not taking the generator script: the fixture landed as data beside the Zig test, and this pull request keeps the script for anyone who wants to regenerate it. |
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
Stacked on #496 (the EXL3 reference decoder this tool's fixture validates): merge #496
first; this PR's diff is then just
tools/exl3_fixture.py.zig/tests/fixtures/exl3_oracle.bin(shipped by #496) is a 371,478-byte binary; thistool regenerates it. Default arguments reproduce the committed bytes exactly
(sha256
8eecb6ac56325a50634eaf75cd2c2ff4aed74e4341b5f2af6c05a3bf0985c810for both),so the fixture is a reproducible artifact rather than a blob to take on faith:
the committed fixture used), every tile's trellis words plus the numpy decoder's exact
16-bit states, k-major
UnstableLlama/Qwen3.5-2B-exl3-8.00bpw(
layers.3.self_attn.q_proj, mcg @ 8.00 bpw - the geometry the native Metal enginepins) with its suh/svh scales and the expected W_q / float64 dequantize
Design notes
tensorfold.cuda.exl3.format, thepython-0.6line), so the Zig reference decoder stays validated against theimplementation the CUDA reader already trusts.
TENSORFOLD_SRCpoints at thatcheckout's
srcdirectory when the package is not installed; the tool fails withinstructions otherwise.
huggingface_hub's downloader. Operational find from buildingthe fixture: plain HTTP range requests against xet-backed repositories return wrong
bytes outside the first chunk (reassembled chunks do not map linearly to file
offsets) - a manual ranged fetch silently poisons fixtures. Worth knowing for any
future fixture or checkpoint work.
oracle and the numpy decoder have drifted and exactly one of them is wrong.
Receipt
Tooling only - no engine, kernel or test code touched;
zig build testis unaffected(the tool is standalone Python under
tools/, where this repository already keeps itscapture and bench scripts). Environment for the record: Zig 0.17.0, mlx-cpu 0.32.3,
Python 3.14, Linux x86-64; the byte-identity check above ran offline against the local
Hugging Face cache.