Skip to content

Add standalone resident Metal EXL3 projections - #681

Merged
ashhart merged 1 commit into
ashhart:mainfrom
akol1:feat/metal-exl3-projections
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
akol1:feat/metal-exl3-projections

Conversation

@akol1

@akol1 akol1 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What this changes

Closes #677. Adds standalone resident EXL3 Metal projections, compact row scratch and a real CLI consumer with independent FP64-dot qualification. This is a generic operator contribution, not a model port or serving-support claim.

  • Borrowed trellis/scales/bias buffers, BF16 inputs and BF16/F32 outputs; storage, alignment, strides, overflow, mapped capacities and writable aliases checked before encoding.
  • Production uses hoisted trellis extraction; the arithmetic decoder is a private CLI comparator. Input rotation, compensated dots and output rotation keep the arithmetic/rounding boundaries unchanged.
  • Generic filtering, descriptor-indexed gather/scatter and caller-prepared grouped tiles. ID contents, unique scatter destinations, descriptor validity/residency and padding order are documented caller preconditions; no GPU readback or family-specific planning is hidden in the API.
  • No model loader, family registration, scheduler/server change, compatibility shim, captured kernel binary, checkpoint or CUDA implementation. Upstream scalar format implementation is unchanged; Turboderp/MIT attribution is preserved.

Receipt

  • Base e7c523eb; candidate 484508f9. Apple M3 Ultra, macOS 26.6.2, Zig 0.17.0, Xcode Metal toolchain. Deterministic compressed fixtures; no checkpoint, MLX or PyTorch dependency.
  • zig build test-exl3 test-exl3-gpu test -Dcpu=apple_m1 --summary all: 1332 passed, 0 failed, 2 skipped in the combined build. Dedicated targets: 13 host/oracle and 18 device tests, all passing. Unchanged baseline host build: 1290 passed, 0 failed, 2 skipped.
  • Actual freshly built tf-exl3-bench --help, --qualify-only 1 --warmup 0 --repeats 1, and --warmup 1 --repeats 3 --prefill 32 exercised.
  • All 196608 codebook states matched independent scalar FP16 bits. Full run exercised 82 operator cases: 54 compact width/codebook/output cases, one compact routed case and 27 large-shape one/routed6/prefill cases. Every compared candidate/baseline output bit matched.
  • Compact fixtures check every one of nine rows and all 128 columns across 27 supported width/codebook combinations in both output types. Maximum observed aggregate NRMS across exercised cases: BF16 0.001800786, F32 0.000000090; candidate equals arithmetic baseline. Per-checked-column squared and absolute errors cannot worsen.
  • Large-shape independent oracle is sampled, at most two rows and three complete 128-column blocks; metrics are labelled worst_sampled, not advertised as whole-matrix bounds. Full-output bit comparisons are not sampled. Independent oracle uses scalar-format decoding, direct FP64 rotations and FP64 dots with the declared FP16 input-rotation boundary.
  • Alternating dispatch order, one warmup and three timed repeats: observed large-shape operator mean ratios 1.2130–1.8702 versus the arithmetic decoder. These short synthetic measurements exclude allocation/oracle work; no release, whole-model or served-throughput conclusion is claimed.
  • GPU regressions cover cancellation-sensitive dots, supported formats/widths, resumed-row bits, mixed-width indexing/scatter, packed-sign filtering, grouped padding, guard preservation and rejected encodes leaving the encoder reusable.
  • zig fmt applied; lean checker: 534 inherited findings, equal to pinned baseline, zero added. Checker exit 1 is explicitly not clean. API/lifetime and numerical/benchmark specialist reviews found no blocking issues.
  • Not run: Metal M1/M2/M4/M5, other OS/toolchain versions, CUDA device execution, model/drafted/resumed/concurrent serving qualification. No support or speed claims for those surfaces. No packaged artifacts are uploaded.

Checklist

  • Existing lane rounds, drafts and server callers unchanged.
  • Precision/rounding boundaries explicit; independent FP64 reference and per-column non-regression exercised.
  • Real model-free device consumer, not compile-only scaffolding.
  • Unrun hardware and sampled-oracle limits disclosed.
  • Changed source files below 600 lines; single-line comments at most 120 columns; zero added lean findings.
  • Public tree, outgoing commit authorship/history and PR body scrubbed; no private identities, hosts, local paths, credentials or attribution trailers.

@mrv777

mrv777 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Validated 484508f9 on M1 Max (32-core GPU, 32 GB), macOS 26.7, Zig 0.17.0.

  • Dedicated checks: 13 host and 18 GPU tests passed twice, including Metal validation. All 196,608 codebook states and full outputs in 82 fixture cases matched the arithmetic decoder bit-for-bit.
  • Scalar-reference checks passed. The large-matrix oracle is sampled; 11 additional local cases checked every row/column on a 5120×512 shape, including all routed experts and prefill boundaries through 128 rows. A shared-output corruption was correctly rejected by the oracle.
  • Five independent batches, each with five warmups and 20 alternating timed pairs: median speedups across 27 large cases were 1.22–1.89× versus the private arithmetic comparator. The most variable case stayed faster in three longer 100-pair runs. These measure resident synthetic GPU projections, excluding allocation/oracle work; no whole-model speedup is claimed.
  • Benchmark memory pressure stayed normal with no new swap-outs; largest fixture buffers were 1.20 GiB.
  • Fresh full suite: 1,313 passed, the known GLM sparse-attention failure (GLM: fix sparse attention thread limit on M1 #704), two Linux-only skips. Native build and server goldens passed, with zero unexpected differences.

Raw logs remain local. Other GPUs and full-model integration were not tested.

@ashhart
ashhart merged commit 58bd07e into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @akol1. The proposal in #677 and this PR gave the Zig engine its first EXL3 operator on Metal, with the qualification we would have asked for already written: every codebook state against the scalar decoder, FP64 dots with the rounding boundaries stated, and the sampled-oracle limits labelled as such. It landed in 1.0.8 with the EXLR8 work, as your own commit (c61109515), and this PR's head (484508f94) is merged unchanged in 58bd07efd, so GitHub shows it as merged.

What we checked:

  • Its own tests on two chips. On an M5 Max and on an M3 Ultra, zig build test-exl3 passes 13 of 13, test-exl3-gpu passes 18 of 18, and tf-exl3-bench --qualify-only 1 finds 0 fp16 mismatches over all 196,608 codebook states and 0 bit mismatches in all 55 compact and routed cases. Your receipt covered the M3 Ultra; the M5 Max gives the same results.
  • The tree's rules. No file over 600 lines, one-line comments, zig fmt clean, and the lean checker's list unchanged from the base. A six-line-window copy scan against ExLlamaV3 found no shared code, only runs of struct fields.

What it led to: GLM-5.3 on two Macs. kindlingai's EXLR8 checkpoints use EXL3's trellis tiles with the codebook rounded to E4M3, so your operator's stages (rotate the input, decode and multiply, rotate the output) became the starting point for our EXLR8 projections on Metal and CUDA. Those rotate each token's activation once a layer and share it across experts, which the EXLR8 layout allows. In 1.0.8, GLM-5.3 from EXLR8 decodes at 21 tok/s with "draft": false and 31 to 32 with its MTP drafts on two M5 Ultras.

On our side there is a CHANGELOG line after your commit. If you take the operator further on M1, M2 or M4, or on a model, we'd like to see the numbers.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
…LM-5.3 on two M5 Ultras; ashhart#681 by akol1 as the Metal EXL3 base
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
…efault, --slide refusals, and Living Weights' 1.0.8 lines

Under Unreleased: the EXLR8 pull and reader (thanks to @akol1 for ashhart#681, which landed with it), GLM-5.3 on two M5
Ultras with its measured speeds, exactness and limits, the two-Mac servers' MCDMA_FABRIC_QOS=1 default and raised
send threads with the loaded and idle figures (and the speed-up guide's corrections), and the Metal --slide and
GLM-5.3 --learn refusals. The six Living Weights lines go in verbatim after ashhart#657's line,
which none of them repeats; their known issues are for the release notes.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#681 landed above as 841cdbbd3 (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…LM-5.3 on two M5 Ultras; ashhart#681 by akol1 as the Metal EXL3 base
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…efault, --slide refusals, and Living Weights' 1.0.8 lines

Under Unreleased: the EXLR8 pull and reader (thanks to @akol1 for ashhart#681, which landed with it), GLM-5.3 on two M5
Ultras with its measured speeds, exactness and limits, the two-Mac servers' MCDMA_FABRIC_QOS=1 default and raised
send threads with the loaded and idle figures (and the speed-up guide's corrections), and the Metal --slide and
GLM-5.3 --learn refusals. The six Living Weights lines go in verbatim after ashhart#657's line,
which none of them repeats; their known issues are for the release notes.
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.

Proposal: standalone Metal EXL3 projection operator and qualification

3 participants