Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
8192e54
feat(lfm3): add strict MLX checkpoint admission checks
BlivionIaG Oct 27, 2026
aa3d4c2
feat(lfm3): implement native Metal text and vision inference
BlivionIaG Oct 27, 2026
773a9af
build(lfm3): integrate host checks into the standard build graph
BlivionIaG Oct 27, 2026
87b04e8
build(lfm3): include the checkpoint inspector in the default build
BlivionIaG Oct 27, 2026
7c914f9
fix(lfm3): preserve the checkpoint text rotary rounding boundary
BlivionIaG Oct 27, 2026
c12411b
test(lfm3): strengthen convolution and normalization accumulation wit…
BlivionIaG Oct 27, 2026
122b6c4
test(lfm3): add independent fidelity diagnostics and accumulation proofs
BlivionIaG Oct 28, 2026
202bbf0
test(lfm3): prove production attention reductions against FP64
BlivionIaG Oct 28, 2026
576be60
perf(lfm3): pair projection rows without changing arithmetic
BlivionIaG Oct 28, 2026
b3d9d6a
build(lfm3): isolate admission in the standard build graph
BlivionIaG Oct 28, 2026
6f2b94f
docs(lfm3): name checkpoint licences and checked Macs
BlivionIaG Oct 28, 2026
a9e4da7
lfm3: separate text runtime from the stacked vision port
BlivionIaG Oct 28, 2026
b5e05a0
perf(lfm3): share attention dispatch across verification streams
BlivionIaG Oct 28, 2026
6f139f6
perf(lfm3): share attention dispatch across verification streams
BlivionIaG Oct 28, 2026
881fc16
Merge the text foundation beneath the LFM3 vision slice
BlivionIaG Oct 28, 2026
ec5f81c
test(lfm3): record shared-round qualification and real-image capture
BlivionIaG Oct 28, 2026
2da1634
test(lfm3): reproduce rounding and separate prompt decode image fidelity
BlivionIaG Oct 28, 2026
97a5c5d
test(lfm3): reproduce rounding and separate prompt decode image fidelity
BlivionIaG Oct 28, 2026
e624033
Keep text fidelity receipts in the vision stack ancestry
BlivionIaG Oct 28, 2026
d1b8187
test(lfm3): record equal-length performance at all six widths
BlivionIaG Oct 28, 2026
0535a8d
docs(lfm3): keep benchmark hashes and summaries without duplicate tim…
BlivionIaG Oct 28, 2026
595f9cc
tools(lfm3): reproduce matched long code and prose benchmarks
BlivionIaG Oct 28, 2026
1bcb5bc
test(lfm3): trace every disjoint prompt case and all-width image inputs
BlivionIaG Oct 28, 2026
b7535d2
docs(lfm3): omit duplicate per-token timing intervals from ABBA receipt
BlivionIaG Oct 28, 2026
75478ed
perf(lfm3): vectorize greedy selection and pair FFN projections
BlivionIaG Oct 28, 2026
72f733a
test(lfm3): record exact native tensor projection proof on M5
BlivionIaG Oct 28, 2026
71b7363
build(lfm3): keep unfinished attention probe outside developer targets
BlivionIaG Oct 28, 2026
167be82
lfm3: carry qualified throughput and fidelity fixes into the text fou…
BlivionIaG Oct 28, 2026
50aead0
test(contract): cache GLM reference input conversions without changin…
BlivionIaG Oct 28, 2026
0f3df0a
test(lfm3): record extracted text kernel-contract results
BlivionIaG Oct 28, 2026
5a2bdea
metal: add exact row twin for opt-in binned projection
BlivionIaG Oct 28, 2026
2b7ce25
Merge validated LFM3 text foundation into vision stack
BlivionIaG Oct 28, 2026
d527f37
test(contract): cache GLM reference input conversions without changin…
BlivionIaG Oct 28, 2026
d2f0799
metal: add exact row twin for opt-in binned projection
BlivionIaG Oct 28, 2026
60798de
Keep shared projection qualification in text foundation
BlivionIaG Oct 28, 2026
87d0655
docs(lfm3): retain extracted text foundation receipt in vision stack
BlivionIaG Oct 28, 2026
d3c7a1d
test(lfm3): retain guarded row twin equality and contract receipts
BlivionIaG Oct 28, 2026
5965e23
test(lfm3): retain guarded row twin equality and contract receipts
BlivionIaG Oct 28, 2026
66f224e
Align vision stack with recorded text projection proof
BlivionIaG Oct 28, 2026
7d5be3e
test(lfm3): record full extracted text regression after row twin
BlivionIaG Oct 28, 2026
76d3d74
Merge completed text regression receipt ancestry
BlivionIaG Oct 28, 2026
2e372cb
docs(lfm3): retain completed text foundation regression receipt
BlivionIaG Oct 28, 2026
6101b94
test(lfm3): expose first vision attention stages in explicit traces
BlivionIaG Oct 28, 2026
b62a0d7
test(lfm3): record canonical vision build after shared row twin
BlivionIaG Oct 28, 2026
7fc113f
test(lfm3): retain secondary MLX real-image vision comparison
BlivionIaG Oct 28, 2026
53f24a6
test(lfm3): account for real-image rounding through vision and text
BlivionIaG Oct 28, 2026
2b57cc1
test(lfm3): replay decoder elementary and attention rounding explicitly
BlivionIaG Oct 28, 2026
29ffb4f
Align vision replay with shared decoder reference foundation
BlivionIaG Oct 28, 2026
59ffb14
style(lfm3): normalize reference EOF and refresh source identity
BlivionIaG Oct 28, 2026
d5ace26
Align reference formatting across text and vision stack
BlivionIaG Oct 28, 2026
a4e2982
style(lfm3): remove trailing blank line from elementary reference
BlivionIaG Oct 28, 2026
021f5ce
lfm3: pair attention key and value projections without changing sums
BlivionIaG Oct 28, 2026
32405a0
test(lfm3): record all-width K/V dispatch byte and state proofs
BlivionIaG Oct 28, 2026
6a8a3b4
lfm3: pair attention key and value projections without changing sums
BlivionIaG Oct 28, 2026
9a26db7
test(lfm3): record all-width K/V dispatch byte and state proofs
BlivionIaG Oct 28, 2026
d28012c
Keep validated K/V dispatch in shared text foundation
BlivionIaG Oct 28, 2026
28e1901
test(lfm3): record 303 actual serving checks after K/V pairing
BlivionIaG Oct 28, 2026
45627cb
test(lfm3): record 303 actual serving checks after K/V pairing
BlivionIaG Oct 28, 2026
52e9775
test(lfm3): qualify extracted K/V text candidate on all three widths
BlivionIaG Oct 28, 2026
17b0819
Merge extracted text K/V serving qualification into vision stack
BlivionIaG Oct 28, 2026
b6413ff
test(contract): evaluate independent GLM oracle rows in parallel
BlivionIaG Oct 28, 2026
1b498fa
test(lfm3): retain complete M5 backend result and inherited failure
BlivionIaG Oct 28, 2026
074530e
bench(lfm3): record matched K/V serving gain and unchanged tokens
BlivionIaG Oct 28, 2026
8c3f0fd
test(contract): evaluate independent GLM oracle rows in parallel
BlivionIaG Oct 28, 2026
dd48a30
bench(lfm3): record matched K/V serving gain and unchanged tokens
BlivionIaG Oct 28, 2026
e1b1e80
test(contract): parallelize independent affine oracle outputs exactly
BlivionIaG Oct 28, 2026
8767d68
metal: preserve infinite affine products in binned projection
BlivionIaG Oct 28, 2026
3d62c57
docs(contract): distinguish original and current oracle source identi…
BlivionIaG Oct 28, 2026
b75a391
test(contract): parallelize the profiled GLM window reference loop
BlivionIaG Oct 28, 2026
c894584
test(contract): parallelize independent affine oracle outputs exactly
BlivionIaG Oct 28, 2026
5d06dc0
metal: preserve infinite affine products in binned projection
BlivionIaG Oct 28, 2026
4fed0a8
docs(contract): distinguish original and current oracle source identi…
BlivionIaG Oct 28, 2026
01132c7
test(contract): parallelize the profiled GLM window reference loop
BlivionIaG Oct 28, 2026
d172800
test(lfm3): retain full 317-control M5 backend qualification
BlivionIaG Oct 28, 2026
43e5f1a
metal: retain low-component sums through nonfinite multiplication
BlivionIaG Oct 28, 2026
8955fae
style(lfm3): keep regression comments within contributing rules
BlivionIaG Oct 28, 2026
d5cf1f2
test(lfm3): retain compensated cancellation nonfinite regressions
BlivionIaG Oct 28, 2026
e62dde0
metal: retain low-component sums through nonfinite multiplication
BlivionIaG Oct 28, 2026
c7396ae
style(lfm3): keep regression comments within contributing rules
BlivionIaG Oct 28, 2026
c53423d
test(lfm3): retain compensated cancellation nonfinite regressions
BlivionIaG Oct 28, 2026
1c7a35a
Merge corrected text projection and exact oracle qualification
BlivionIaG Oct 28, 2026
62fdf4a
test(lfm3): retain extracted text contract host verification
BlivionIaG Oct 28, 2026
b3a2a43
Merge completed extracted text contract verification
BlivionIaG Oct 28, 2026
07fa59f
test(lfm3): retain completed cancellation-corrected backend verification
BlivionIaG Oct 28, 2026
d05f599
docs(lfm3): retain independent FP32 image comparison
BlivionIaG Oct 28, 2026
70961ff
perf(lfm3): share convolution launches across streams
BlivionIaG Oct 28, 2026
6b318ce
docs(lfm3): record text shared convolution validation
BlivionIaG Oct 28, 2026
1cdcd2c
perf(lfm3): fuse post-add and following normalization
BlivionIaG Oct 28, 2026
21728fc
test(lfm3): reflect the actual postnorm rounding control
BlivionIaG Oct 28, 2026
dd7263c
fix(lfm3): preserve attention contributions outside FP32 range
BlivionIaG Oct 28, 2026
d3c5215
docs(lfm3): record text attention range validation
BlivionIaG Oct 28, 2026
6a111de
docs(lfm3): retain locked local standard-server baseline
BlivionIaG Oct 28, 2026
8bb5844
docs(lfm3): retain locked M5 standard comparison
BlivionIaG Oct 28, 2026
07a7cb4
docs(lfm3): retain exact-input M5 prefill diagnosis
BlivionIaG Oct 28, 2026
0ad9b08
docs: record locked M5 LFM3 6-bit and 8-bit comparisons
BlivionIaG Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub fn build(b: *std.Build) void {
@import("zig/build/step5_host.zig").steps(b, step5_mods.metal, step5_mods.engine, step5_mods.lanes);
}
@import("zig/build/h3_host.zig").tests(b, target, test_step);
@import("zig/build/lfm3_host.zig").steps(b, test_step);
@import("zig/build/digest.zig").steps(b, test_step, draft_ids, build_options);
@import("zig/build/flashnext_budget.zig").steps(b, test_step);
@import("zig/build/flashnext_batch_host.zig").tests(b, test_step);
Expand Down
188 changes: 188 additions & 0 deletions docs/receipts/lfm3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# LFM3 Metal qualification receipts

These receipts cover native LFM3-1.7B and LFM3-VL-2B from the official MLX exports.
They distinguish implementation checks from the still-required maintainer model/performance gate.
Checkpoint revisions and run instructions are in the [family recipe](../../recipes/lfm3-native.md).

## Builds and hardware

- Initial corrected native: `a8df9730ee637237545311a6753dd4bdcb13e860700d65a01a033ae818ee0d18`.
- Optimized benchmark native: `5c8a04d4af599879797f4f5bed8e00ab7d9d70732e698bd2a1ec2a01ec762e09`.
- Guarded row-pair build: `251079309919aa9b21ca8cc6a89c58fc3fc9a9baf800fa5ce6a6af313a5b5f65`.

The guarded row-pair build additionally closes a diagnostic encoder when counter setup fails.
That change does not alter the production projection or attention arithmetic. Its serving checks were rerun separately.

Correctness runs used an M4 Pro with 48 GB RAM, macOS 26.5.1 and Zig 0.17.0.
Controlled performance runs used an M5 Ultra with 256 GiB RAM and macOS 27.0 (26A428).
A measured footprint on the M5 is not a smaller-RAM qualification.

## Served and operator checks

The optimized M4 binary passed all six greedy/seeded-sampling suites: 303 passed, zero failed or skipped.
These cover drafted/plain, concurrent/solo, real cache reuse, edited prefixes, image order/content,
corrupt input and cancellation/recovery. The guarded row-pair binary also passed 303/303 on the M5.

Text4 and VL4 grammar runs on both hosts each passed 32 configurations, concurrent comparisons and five refusals.
On each host, full-token capture verified 64/64 configuration groups, including hidden reasoning, across drafted/plain/concurrent requests.
An additional 80 checks covered real required/named tools, typed arguments, streaming, tool-result history and image-conditioned calls.
Grammar requires the matching optional library; these tests used an isolated bundle with library SHA-256
`04133accdcecd01cd7dd4e8730855905850967ed8c6bd6d8a637258264ae7687`.

The 4-bit text long suite passed 73/73, including chunk and 8,193-token seams.
The row-pair LFM3-only contract run on the M4 reported:

```text
SUMMARY 50 kernels: 50 pass gates 1-4, 0 fail, 0 known findings; 13 controls: 13 red as planted, 0 missed; 0 limit problems; gates 19521 ms, limits 133 ms
```

The full earlier M5 runner reported 272/273 kernels passing, two known findings, all 298 controls red and zero limit problems.
Its Qwen4 HC activation failure reproduces exactly in a separate build of pinned base `b30d5b9d3`.
That is not a global pass or a final-source global-suite receipt.

## Shared-stream attention follow-up

`shared-attention.json` records the subsequent shared-dispatch source and binary identity.
Full and sliding attention reuse the serial partial and merge arithmetic, with stream-local cache addresses and row maps.
All 52 LFM3 kernels passed gates 1–4, all 14 controls were red as planted, and launch limits had zero problems.
The real text4 default exactness suite passed 68/68, including unequal two/four-stream state and logits.
All six sampled/cancellation serving suites on the M5 passed 303/303 with zero failures or skips.
This follow-up is byte-preserving shared scheduling; it does not qualify tensor-unit prompt attention or a speed gate.

## Numerical evidence

`projection-fp64-bounds.json` covers 66 projection/layout cells and 60,954,624 outputs.
The actual shared FP32 helper was captured before BF16 storage and compared with independently unpacked affine FP64 products.
No raw FP32 or BF16-store error exceeded the existing derived bounds. Worst-column errors were retained.

The row-pair optimization invokes the same shared helper and preserves its accumulation order.
All 132 checkpoint comparisons at widths 1 and 64 produced 123,814,080 bytes identical to the old selector.
A separate 8,193-token before/after check compared all 2,097,408,000 BF16 logit bytes exactly.
Thus this optimization does not worsen any output-based precision metric on those comparisons.

`fidelity-investigation.json` records the first actual primitive difference and its causal propagation.
Official MLX 0.32.4 uses different effective affine reconstruction in its vector and matrix paths.
The native engine consistently follows the FP32 affine equation rather than changing arithmetic with batch width.
The first captured FP32 error was about 6.81e-9, inside the existing derived 5.52e-5 pre-store bound;
it crossed a BF16 midpoint and propagated through recurrent history.

`model-fp64-comparison.json` retains all 18 originally disjoint native/MLX positions, including repeated histories.
With direct binary64-to-BF16 rounding, native belongs to the ideal model maximum set in nine cases, MLX in 16,
both in eight and neither in one. This ideal FP64 model is a diagnostic; it does not execute the native FP32 reductions.
No new tie tolerance or end-to-end acceptance threshold was applied. The primitive evidence does not replace that model gate.

The oracle is reproducible with `tools/lfm3/fp64_reference.py`; its tests include all finite BF16 encodings,
adjacent midpoints, double rounding, subnormals, overflow and six-bit cross-word unpacking.

## Binned projection candidate

`binned-projection.json` records the explicit candidate at `75478ed17`; ordinary model loading leaves it disabled.
It preserves each input value while partitioning exponent ranges and exact code nibbles. M5 uses the shared
`nax.h` tensor-unit fragments; M4 uses its fallback. Group affine sums use compensated FP32 pairs.
The integer argument is limited to finite normal aligned products without overflow or underflow.
It does not establish universal FP64 equivalence for extreme BF16 subnormals or arbitrary inputs.

The actual native M5 tool produced **61,907,040/61,907,040** direct FP64-to-BF16 reference values across 132 captures:
11 projection classes, all six checkpoints, and prompt/decode widths 64 and 1. All 66 first-row comparisons matched.
The six small attention-gate cells use the unchanged row fallback and are included explicitly.
No column had more FP64 error than either the retained original-native or MLX result.
Those two comparator captures are from the M4, not a same-device M5 performance comparison.
The file retains worst-column metrics, input/output hashes, artifact identities and the complete contract summaries.
Both M4 and M5 passed all six operator variants, both planted controls and launch limits.
These primitive results do not settle whole-model fidelity or served performance.

To reconstruct the fixtures, save `fixture_tokens` as a little-endian uint32 NPY array and run the default
`tf-lfm3-forward MODEL TOKENS.npy baseline.bf16 trace TRACE_DIR` for each named checkpoint.
Concatenate the trace files ending in `_<input_stage>.bf16` in filename order to recreate each `input_file`;
the first `2*k` bytes recreate its `one_row_file`. Verify the recorded input hash before comparing outputs.
Run `tf-lfm3-project MODEL MODULE INPUT.bf16 ROWS OUTPUT.bf16 --binned` at widths 64 and 1.
Save the receipt’s `cases` array as `manifest.json` beside the inputs for `tools/lfm3/projection_compare.py`.
Use the frozen candidate commit for these artifact identities.

`binned-row-twin.json` records the later opt-in row twin at `5a2bdea76`: all 132 captures retain
123,814,080 bytes exactly against the earlier FP64-exact tiled captures. Both M4 and M5 pass six
variants and two planted controls. The twin remains disabled for ordinary model loading because
its serving performance has not passed; these operator results do not qualify a whole model.

## Controlled performance

`cold-prefill-ab.json` contains all 16 matched pairs / 32 fresh-server cold requests.
It includes full output-token hashes, body hashes, client TTFT, engine prefill time and peak physical process footprint.
Both sides used the same body, exact prompt counts, 16 output tokens, context 70,000, four configured lanes and zero cached tokens.
The 2k and 8k cells have three alternating pairs each; 32k and 64k have one pair each.
Only 4-bit performance was measured.

Engine prefill seconds, before to after:

- Text: 2k 1.239530 to 0.812959; 8k 5.307524 to 3.608895; 32k 27.314691 to 20.488389; 64k 73.402432 to 61.632933.
- VL decoder, text requests: 2k 1.261845 to 0.815432; 8k 5.402433 to 3.617449; 32k 27.686643 to 20.536702; 64k 73.920498 to 59.646930.

These are engine prefill times, not client TTFT. All 16 paired full output-token hashes matched.
At 64k, physical footprint was 2,926,167,768 to 2,925,315,776 bytes for text and
3,586,115,720 to 3,584,559,264 bytes for VL. Device/pinned allocator peaks were not collected.

`decode-concurrency.json` records 256-token, three-repetition code/prose runs.
All 60 concurrent-to-solo comparisons and all eight serial checks matched.
Small decode-rate differences are descriptive; they are not a separately established speedup.

Earlier standard-server comparisons still showed MLX-VLM faster, especially for long cold prefill.
The faster arithmetic-changing matrix candidate failed the strict no-worse precision comparison and was excluded.
The slower uniform-exponential candidate was also excluded. No unvalidated GQA experiment is enabled.

## Paired FFN and CPU greedy follow-up

`greedy-dual.json` records the subsequent immutable `b804c6ed` native build.
The FFN gate/up projections share one dispatch while retaining each projection's shared helper and BF16 stores.
A SIMD CPU greedy reduction preserves the first maximum, signed-zero ties and nonfinite rejection;
masked and positive-temperature sampling keep the original path.
All 58 LFM3 kernel checks passed, all 16 controls were red, and launch limits had zero problems.
The real text4 exactness suite passed 68/68; six M5 sampled/cancellation serving suites passed 303/303.
Actual projection pairs retained 247,628,160 bytes, and six complete teacher-forced logit arrays retained 394,752,000 bytes.

Matched M5 old/new/new/old runs used three repetitions and 256 output tokens per request.
All 240 concurrent full-token digests matched across the corresponding prompts and legs;
240/240 concurrent-to-solo and 32/32 serial checks passed.
Text code/prose single-stream rates changed from 309.27/322.59 to 317.39/332.83 tok/s;
four-stream aggregate rates changed from 682.50/717.25 to 836.65/856.70 tok/s.
VL decoder code/prose rates changed from 292.69/290.90 to 301.68/299.90 tok/s;
four-stream rates changed from 656.00/658.15 to 813.40/810.10 tok/s.
These are medians of the two run medians, with all raw three-repetition cells retained.
This ABBA experiment measures only 4-bit performance and does not assert standard-server parity.

## Reproduce

Use the pinned Zig version and a complete local checkpoint. Developer references need NumPy; the MLX reference also needs MLX.

```sh
zig build native tf-lfm3-forward tf-lfm3-project tf-lfm3-profile tf-lfm3-exact tf-kernel-contract -Dcpu=apple_m1
zig build test test-lfm3-host test-kernel-contract test-golden fuzz-cortheon -Dcpu=apple_m1
python3 -m unittest discover -s tools/lfm3 -p 'test_*.py'
./zig-out/bin/tf-kernel-contract --only LFM3
./zig-out/bin/tf-lfm3-exact MODEL_DIR --long
python3 tools/lfm3/serve_check.py --binary ./zig-out/native/bin/tensorfold-native --model-dir MODEL_DIR --sampled --cancel --output served.json
python3 tools/lfm3/reference.py --model-dir MODEL_DIR --tokens TOKENS.npy --output mlx.bf16
python3 tools/lfm3/fp64_reference.py --model-dir MODEL_DIR --tokens TOKENS.npy --output fp64.bf16 --weight-mode exact
./zig-out/bin/tf-lfm3-forward MODEL_DIR TOKENS.npy native.bf16
./zig-out/bin/tf-lfm3-profile MODEL_DIR TOKENS.npy profile.json
```

Repeat the served command for all six checkpoints. Run one model process per GPU, using the native lock and admission guards.
`cold-prompts/` contains the exact request bodies and official rendered token arrays; SHA-256 hashes are in `cold-prompt-sha256.json`.
The native server did not return its rendered arrays, so matching counts are not described as a captured native-token identity proof.
To repeat cold HTTP measurements, start a fresh owned server with `--context 70000 --parallel 4 --prompt-cache-gib 0`,
POST a saved body to `/v1/chat/completions`, and retain usage, full token hash and timings from the stream.
The supplied bodies omit the optional model alias. Keep the exact bodies unchanged between compared builds.

## All-width matched baseline

`all-width-performance-baseline.json` records the shared-attention binary before the SIMD greedy and paired-FFN follow-ups.
Both native and the standard server completed 72 retained single-stream requests, 360 retained concurrency requests and 48 cold requests in total.
Every measured decode/concurrency reply has 256 tokens; each cold request has 16 output tokens and zero cached prompt tokens.
All 180 native concurrent-to-solo and 24 serial comparisons matched. Exact public prompts, client hashes, token hashes and timings are retained.
There is one cold sample per cell and three decode/concurrency repetitions. These baseline rates remain below the standard server; they are not a performance-gate pass.
The native binary SHA is `d1656249bdb581b147faacbd3b3c557c00b6c45b710eeddce517a67178b6ba2b`.

The public long-prompt wrapper is `tools/lfm3/bench_decode.py`; its prompts match the recorded JSON exactly.
Use `python3 tools/lfm3/bench_decode.py decode URL MODEL --tokens 256 --reps 3 --temperatures 0 --output decode.json`.
For concurrency use the `concurrent` mode with `--levels 1,4 --alone --serial` on native, or `--levels 1,4 --no-seed` on standard.
Verify every reply length in the evidence; a shorter standard reply does not establish an equal-length rate.
Loading
Loading