Skip to content

tools: the EXL3 oracle fixture generator - #507

Closed
akol1 wants to merge 2 commits into
ashhart:zig-flashnextfrom
akol1:exl3-fixture-tool
Closed

akol1 wants to merge 2 commits into
ashhart:zig-flashnextfrom
akol1:exl3-fixture-tool

Conversation

@akol1

@akol1 akol1 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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; this
tool regenerates it. Default arguments reproduce the committed bytes exactly
(sha256 8eecb6ac56325a50634eaf75cd2c2ff4aed74e4341b5f2af6c05a3bf0985c810 for both),
so the fixture is a reproducible artifact rather than a blob to take on faith:

TENSORFOLD_SRC=<python-0.6 checkout>/src python tools/exl3_fixture.py \
    --out zig/tests/fixtures/exl3_oracle.bin
  • 27 codebook x width synthetic records from a fixed rng seed (the same call order
    the committed fixture used), every tile's trellis words plus the numpy decoder's exact
    16-bit states, k-major
  • 384 codebook spot values (every 512th state, fp16 bit patterns)
  • one real 128x128 Hadamard block from UnstableLlama/Qwen3.5-2B-exl3-8.00bpw
    (layers.3.self_attn.q_proj, mcg @ 8.00 bpw - the geometry the native Metal engine
    pins) with its suh/svh scales and the expected W_q / float64 dequantize

Design notes

  • The oracle is TensorFold's numpy EXL3 decoder (tensorfold.cuda.exl3.format, the
    python-0.6 line), so the Zig reference decoder stays validated against the
    implementation the CUDA reader already trusts. TENSORFOLD_SRC points at that
    checkout's src directory when the package is not installed; the tool fails with
    instructions otherwise.
  • Checkpoints go through huggingface_hub's downloader. Operational find from building
    the 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.
  • Rerun after any change to the numpy decoder's arithmetic: a mismatch means the Zig
    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 test is unaffected
(the tool is standalone Python under tools/, where this repository already keeps its
capture 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.

akol1 added 2 commits October 7, 2026 18:22
…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.
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
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.

@ashhart ashhart closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants