Skip to content

inkling2 metal: lift UnsupportedInklingTree with 0-ULP tree convolutions, attention, and compaction - #5011

Open
gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:v4-3-verify-tree-rebased
Open

gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:v4-3-verify-tree-rebased

Conversation

@gilby

@gilby gilby commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: on main, the Inkling 2 Mini Metal backend only accepted linear verification chains (w.parents == null) and returned error.UnsupportedInklingTree whenever a lane verification window included tree-structured branches.

After: implements full 0-ULP tree verification and arbitrary surviving-path state compaction in the Inkling 2 Mini Metal backend (zig/src/families/inkling2/metal/{tree,tree_plan,attention,attention_plan,backend,forward,state,model}.zig), adding tf_ink2_conv_static_tree, tf_ink2_conv_dynamic_tree, tf_ink2_keep_kv, and tf_ink2_keep_conv in zig/kernels/metal/inkling2/tree.metal alongside ancestor-remapped tf_ink2_prep_tree, tf_ink2_attn_scalar_tree, tf_ink2_attn_prompt_tree_prefix, and tf_ink2_attn_prompt_tree_tail in attention.metal and prompt_attention.metal with fused on-the-fly relative bias (#5000, no rel_table scratch/dispatch), lifting UnsupportedInklingTree for non-linear verification windows while preserving linear non-tree decode performance and bounding tree scratch buffers to batch_rows (32). Adds host, GPU, serving, and contract.register-wired (#5058) kernel-contract suites (tree_test.zig, tree_gpu_test.zig, metal_inkling2_tree*.zig).

Checks on this head

  • Head commit: 7e8a1f29af
  • Lean checker, python3 tools/pr_check.py --base origin/main --pr 5011: lean 164 vs 164, 0 new, 0 error(s) (31 changed files, 2944 insertions(+), 76 deletions(-), max touched file 598 lines <= 600; tree_gpu_test.zig 584, metal_inkling2_tree_attn.zig 578); zig fmt --check build.zig zig and git diff --check origin/main..HEAD exit 0.
  • Builds (7e8a1f29af):
    • zig build -Dcpu=apple_m1 -Doptimize=ReleaseFast: exit 0.
    • zig build compile-inkling2-native-host: exit 0.
    • zig build compile-inkling2-native-host -Dtarget=x86_64-windows: exit 0.
    • zig build compile-native-cuda-windows: exit 0.
    • zig build tf-kernel-contract -Doptimize=ReleaseFast: exit 0.
  • Host & Metal GPU test suites (7e8a1f29af):
    • zig build test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all: 5/5 steps succeeded (46 pass, 4 skip (50 total) on 69149deee4, cached pass on 7e8a1f29af).
    • zig build test-inkling2-controls-host --summary all: 5/5 steps succeeded (26 pass (26 total) on 69149deee4, cached pass on 7e8a1f29af).
    • zig build test-kernel-contract --summary all: 45/45 steps succeeded; 260/260 tests passed (Metal launch map: 1321 registered launches, 2 controls, 0 missing; 304/304 uncached on 69149deee4).
    • zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all: 5/5 steps succeeded; 118/125 tests passed (7 skipped) (0 failed; tree_gpu_test.zig 48-visit differential + mixed-batch C2/C7 + lanes.Engine conformance all pass; JPEG/checkpoint env tests skipped).
  • Contracts on Apple M5 Max (7e8a1f29af):
    • ./zig-out/bin/tf-kernel-contract --only "metal inkling2": SUMMARY 70 kernels: 70 pass gates 1-4, 0 fail, 0 known findings; 76 controls: 76 red as planted, 0 missed; 0 limit problems; gates 55909 ms, limits 626 ms (exit 0).
    • ./zig-out/bin/tf-kernel-contract --only "metal inkling2 tree": SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 4709 ms, limits 52 ms (exit 0).
  • Real-checkpoint verification (TF_INKLING2_REAL_TREE=1): see Apple M5 Ultra 512 GiB + Apple M3 Ultra 512 GiB receipt comment (8/8 tests pass on both architectures with bit-for-bit FP32 logits & feature taps matching sequential replay, plain == tree == resumed).
  • CI: Pending GitHub Actions on 7e8a1f29af.
  • Not run, and why: Apple M1/M2/M3/M4 served A/Bs not run on this slice; Apple M5 Ultra and Apple M5 Pro plain decode A-B-B-A guard runs (pre-rebase) plus M5 Ultra + M3 Ultra real-checkpoint tree receipts (#issuecomment-7166583709) and post-rebase Apple M5 Max contract + 48-visit GPU tests verify exactness and zero regression.

Receipt

  • Main against branch: A-B-B-A served runs (pre-rebase c1a82fe5d1, tools/bench_concurrent.py --tokens 128 --reps 2 --no-drafts --parallel 4 --context 8192, 0 cross-leg token_sha256 mismatches across all cells on both machines):
    • Apple M5 Ultra 512 GiB (main vs branch, plain linear decode guard): -0.59%..+0.30% across cells (0 mismatches).
    • Apple M5 Pro 64 GiB (main vs branch, plain linear decode guard):
      • c=1: code T=0.0: 13.40 -> 13.40 tok/s (0.00%, TTFT +0.19%); chat T=0.0: 13.50 -> 13.50 tok/s (0.00%, TTFT -0.55%).
      • c=4: code T=0.0: 21.40 -> 21.35 tok/s (-0.23%, TTFT -3.31%); chat T=0.0: 22.85 -> 22.90 tok/s (+0.22%, TTFT -1.21%).
  • Real-checkpoint 48-visit tree + lanes.Engine conformance (TF_INKLING2_REAL_TREE=1): Apple M5 Ultra 512 GiB and Apple M3 Ultra 512 GiB (8/8 pass, 0-ULP FP32 logits & feature taps match sequential replay; see #issuecomment-7166583709).
  • Boxes it reaches: zig/kernels/metal/inkling2/{attention,prompt_attention,tree}.metal, tree_sources.zig, inkling2_sources.zig, inkling2_{attention,tree}_metal_records.zig, registry_joins.zig, contract.zig, zig/src/families/inkling2/metal/{attention,attention_plan,backend,forward,host_test,metal,model,state,tree,tree_plan,tree_test,tree_gpu_test}.zig, inkling2_serving_test.zig, zig/build/{inkling2_host,kernel_contract,metal_targets}.zig, zig/tests/contract/{metal_inkling2_controls_host,metal_inkling2_main,metal_inkling2_tree,metal_inkling2_tree_attn,metal_inkling2_tree_controls,metal_limits}.zig.
  • New switch? No (always active).
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Head 7e8a1f29af rebased onto origin/main (f3c0fa8c65), Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max (applegpu_g17); pre-rebase receipts on Apple M5 Ultra 512 GiB, Apple M3 Ultra 512 GiB, and Apple M5 Pro 64 GiB; checkpoint Inkling-2-Mini.
  • Paths and platforms the change reaches, which I ran and which I could not: Inkling 2 Metal tree verification and surviving-path compaction across Apple Silicon Metal GPUs; Apple M1/M2/M3/M4 served A/Bs not directly run on this slice.
  • Exactness: 0 cross-leg token_sha256 mismatches across all cells on Apple M5 Ultra and Apple M5 Pro; 0-ULP bitwise agreement for fused on-the-fly relative-bias tree convolutions, tree attention, and surviving-path compaction verified in metal_inkling2_tree*.zig and tree_gpu_test.zig, plus real-checkpoint Inkling-2-Mini verification in #issuecomment-7166583709.
  • Decode speed before and after: Non-regressive within -0.59%..+0.30% (M5 Ultra) / -0.23%..+0.22% (M5 Pro) noise band on linear decode while lifting UnsupportedInklingTree to enable tree-structured verification windows (and removing the separate rel_table scratch buffer and dispatch via #5000).
  • Prompt speed before and after: TTFT within noise / -3.31% (code c=4) and -1.21% (chat c=4) on M5 Pro.
  • Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: Adds tf_ink2_conv_static_tree, tf_ink2_conv_dynamic_tree, tf_ink2_keep_kv, tf_ink2_keep_conv (tree.metal / inkling2_tree_metal_records.zig) plus tf_ink2_prep_tree, tf_ink2_attn_scalar_tree, tf_ink2_attn_prompt_tree_prefix, tf_ink2_attn_prompt_tree_tail (attention.metal, prompt_attention.metal / inkling2_attention_metal_records.zig), extending the linear verify path with fused on-the-fly relative bias (#5000) to support tree-structured windows.
  • A planted control for each new kernel, and each one fails as planted: All 76/76 controls on Apple M5 Max (7e8a1f29af) fail red as planted (0 missed), including planted failure controls in metal_inkling2_tree_controls.zig (26/26 host control tests pass).
  • Each backend's SUMMARY line and exit status:
    • Apple M5 Max (7e8a1f29af, --only "metal inkling2"): SUMMARY 70 kernels: 70 pass gates 1-4, 0 fail, 0 known findings; 76 controls: 76 red as planted, 0 missed; 0 limit problems; gates 55909 ms, limits 626 ms (exit 0).
    • Apple M5 Max (7e8a1f29af, --only "metal inkling2 tree"): SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 4709 ms, limits 52 ms (exit 0).
    • Apple M5 Pro (pre-rebase a3a83b6e5d): SUMMARY 56 kernels: 56 pass gates 1-4, 0 fail, 0 known findings; 63 controls: 63 red as planted, 0 missed; 0 limit problems; gates 43253 ms, limits 7 ms (exit 0).
  • Chips I could not run: Apple M1/M2/M3/M4 contract suites not directly run on this rebased head (Apple M3 Ultra applegpu_g15 real-checkpoint tree suite ran pre-rebase in #issuecomment-7166583709).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled.

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged a3a83b6e5d cleanly into d2b43908db on M5 Max. The host targets passed 153 tests with 11 skips. The Metal contract passed 69 kernels, caught all 73 planted controls and found zero problems across 81 launch records.

zig build test-inkling2-host test-inkling2-metal-host tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'metal inkling2'

I also filtered the Metal test root in scratch to the sliding-wrap KV/history compaction and 48-visit synthetic verify/replay fixtures. That run had eight passes and zero skips, so both named cases executed. Live checkpoint serving and throughput were outside this run.

For integration, #4998 merges cleanly pairwise. There are source conflicts with #4981, #5000, #5001, #5004 and #5005, mostly in attention/forward and their registrations. The device receipt above is for the standalone trial.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I tested an integration of this head (a3a83b6e5d) and #5004 (23870c9381) on main at 4beda42498. Merging in that order conflicts only in Inkling's Metal forward.zig. In a scratch worktree, I shared the staging helper, kept the ancestor-indexed K/V convolution and post-convolution for tree segments, and used #5004's paired dispatch on linear segments. Mixed static/dynamic linear weights still use the two separate dispatches.

  • zig build test-inkling2-host test-inkling2-metal-host tf-kernel-contract -Dfixed-cpu -j2 --summary all passed, 153 tests and 11 skips.
  • ./zig-out/bin/tf-kernel-contract --only 'metal inkling2' on M5 Max passed all 71 kernels, caught all 75 planted controls, and had zero launch-limit problems.
  • Filtering the Metal host target to 48-visit Inkling and Cache beginTree gave 8 passes and zero skips. The 48-visit fixture checks tree verify against sequential replay bit for bit and includes a mixed linear/tree batch. The other fixture checks sliding-wrap KV and all four convolution histories.

Scope was this pair with synthetic inputs. The full-checkpoint and throughput checks are still outstanding.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @gilby. The tree code keeps ancestor order and the existing convolution and attention rounding points. The reported synthetic replay, wrap compaction and mixed linear/tree checks are useful.

The remaining gate is checkpoint-backed branch/keep/replay on both M3 and M5, plus final-tree serving and memory checks. The plain decode receipt does not exercise trees. With paired K/V, forward.zig needs to retain indexed tree convolutions while pairing linear segments; the reported combined synthetic run supports that approach, though its resolved bytes are still needed.

  • Synthena

@gilby
gilby force-pushed the v4-3-verify-tree-rebased branch from a3a83b6 to a7ba033 Compare November 25, 2026 09:35
@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the checkpoint-backed branch/keep/replay test on M5 Max at a7ba0336b2 and again with #5004 23870c9381 merged locally. Both focused runs passed 7/7 checks using thinkingmachines/Inkling-2-Mini@c9d028302cd0f035fdf8e7e91f089a4ce94d2195. The fixture forks a six-node tree, keeps three different paths, compares the verified and compacted logits bit for bit against serial target execution, then compares the next token and logits after replay.

Use the Mini Metal verify tree matches serial target test filter for the Metal test artifact and force the run to rerun with the local checkpoint present.

TF_INKLING2_METAL_DIR=/path/to/pinned/checkpoint zig build test-inkling2-metal-host -Dfixed-cpu -j2 --summary all

The broad combined run passed 157 host tests with 11 skipped, plus 71 Metal kernels and all 75 planted controls. M3, final-tree serving and memory, and #5004's baseline pipeline-load failure test remain open.

Exact forward.zig resolution for a7ba033 + 23870c9

In a scratch checkout of #5011, merge #5004 and take #5011's version of zig/src/families/inkling2/metal/forward.zig for the conflicted file before applying the diff. The resulting Git blob is 448d49ed9a1457a4952bc974c3bb7d58b4e99ae4. It retains indexed tree convolution, paired linear calls and the mixed-kind fallback.

diff --git a/zig/src/families/inkling2/metal/forward.zig b/zig/src/families/inkling2/metal/forward.zig
index 8548d6513..448d49ed9 100644
--- a/zig/src/families/inkling2/metal/forward.zig
+++ b/zig/src/families/inkling2/metal/forward.zig
@@ -181,11 +181,17 @@ fn prepareAttentionInputs(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scra
     }
 }
 
-fn staticPostConv(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, weight: ck.Tensor, out: Ref, base: usize, rows: usize, is_tree: bool) void {
+fn stageConvInput(m: *const Model, e: mtl.ComputeEncoder, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, base: usize, rows: usize) Ref {
     const channels = state.convWidth(conv_state);
     const taps = cache.staged(slot, conv_state, 0);
     copyBf16(m, e, cache.history(slot, conv_state), taps, 3 * channels);
     copyBf16(m, e, at(raw.buf, raw.off + base * channels * 2), cache.staged(slot, conv_state, 3), rows * channels);
+    return taps;
+}
+
+fn staticPostConv(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, weight: ck.Tensor, out: Ref, base: usize, rows: usize, is_tree: bool) void {
+    const channels = state.convWidth(conv_state);
+    const taps = stageConvInput(m, e, cache, slot, conv_state, raw, base, rows);
     if (is_tree) {
         tree.convStatic(&m.tree, e, taps, r(weight), at(s.conv_src, base * 4 * 4), at(out.buf, out.off + base * channels * 2), @intCast(rows), @intCast(channels));
     } else {
@@ -210,13 +216,14 @@ fn attendSegments(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, v:
             .segs = a(at(s.segs, si * @sizeOf(ap.Seg))),
         };
         const kv = attention.Cache{ .k = a(cache.keys(v.cache_slot)), .v = a(cache.values(v.cache_slot)) };
-        try convInputForAttention(m, e, s, cache, v, base, rows, true, sm.is_tree);
-        try convInputForAttention(m, e, s, cache, v, base, rows, false, sm.is_tree);
         if (sm.is_tree) {
+            treeConvInputForAttention(m, e, s, cache, v, base, rows, true);
+            treeConvInputForAttention(m, e, s, cache, v, base, rows, false);
             attention.prepTree(&m.attention, e, rr, layer, prep, meta, .{ a(at(s.q_raw, base * state.query_width * 2)), a(at(s.k_conv, base * state.kv_width * 2)), a(at(s.v_conv, base * state.kv_width * 2)), a(at(s.rel_raw, base * state.rel_width * 2)) }, .{ a(r(m.weights.layers[v.layer].attn.q_scale)), a(r(m.weights.layers[v.layer].attn.rel_scale)) }, a(at(s.q_prep, base * state.query_width * 2)), a(at(s.rel_prep, base * state.rel_width * 2)), kv);
             attention.relTable(&m.attention, e, rr, a(at(s.rel_prep, base * state.rel_width * 2)), a(r(m.weights.layers[v.layer].attn.rel_projection)), a(at(s.rel_tab, base * 24 * ap.extent * 2)));
             try attention.attendTree(&m.attention, e, rr, layer, state.max_attention_stride, @intCast(start), meta, a(at(s.tree_paths, base * state.window_rows * 4)), a(at(s.tree_tail_o, base * 2 * 24 * ap.head_dim * 4)), a(at(s.tree_tail_ml, base * 24 * 16)), a(at(s.q_prep, base * state.query_width * 2)), kv, a(at(s.rel_tab, base * 24 * ap.extent * 2)), a(at(s.part_o, base * 24 * state.max_attention_stride * ap.head_dim * 4)), a(at(s.part_ml, base * 24 * state.max_attention_stride * 8)), a(at(s.sink, base * 24 * 2)), a(at(s.gate, base * state.query_width * 2)), a(at(s.att, base * state.query_width * 2)));
         } else {
+            convInputsForAttention(m, e, s, cache, v, base, rows);
             attention.prep(&m.attention, e, rr, layer, prep, meta, .{ a(at(s.q_raw, base * state.query_width * 2)), a(at(s.k_conv, base * state.kv_width * 2)), a(at(s.v_conv, base * state.kv_width * 2)), a(at(s.rel_raw, base * state.rel_width * 2)) }, .{ a(r(m.weights.layers[v.layer].attn.q_scale)), a(r(m.weights.layers[v.layer].attn.rel_scale)) }, a(at(s.q_prep, base * state.query_width * 2)), a(at(s.rel_prep, base * state.rel_width * 2)), kv);
             attention.relTable(&m.attention, e, rr, a(at(s.rel_prep, base * state.rel_width * 2)), a(r(m.weights.layers[v.layer].attn.rel_projection)), a(at(s.rel_tab, base * 24 * ap.extent * 2)));
             try attention.attend(&m.attention, e, rr, layer, state.max_attention_stride, 0, meta, a(at(s.q_prep, base * state.query_width * 2)), kv, a(at(s.rel_tab, base * 24 * ap.extent * 2)), a(at(s.part_o, base * 24 * state.max_attention_stride * ap.head_dim * 4)), a(at(s.part_ml, base * 24 * state.max_attention_stride * 8)), a(at(s.sink, base * 24 * 2)), a(at(s.gate, base * state.query_width * 2)), a(at(s.att, base * state.query_width * 2)));
@@ -225,24 +232,45 @@ fn attendSegments(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, v:
     }
 }
 
-fn convInputForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize, key: bool, is_tree: bool) !void {
+fn treeConvInputForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize, key: bool) void {
     const lp = m.weight_plan.at(v.layer);
     const w = &m.weights.layers[v.layer];
     const raw = if (key) at(s.k_conv, base * state.kv_width * 2) else at(s.v_conv, base * state.kv_width * 2);
-    const projected = if (key) at(s.k_raw, base * state.kv_width * 2) else at(s.v_raw, base * state.kv_width * 2);
+    const projected = if (key) at(s.k_raw, 0) else at(s.v_raw, 0);
     const normalized = if (key) at(s.k_norm, 0) else if (v.hasMessages() or lp.kind == .global) at(s.v_norm, 0) else at(s.q_norm, 0);
-    const taps = cache.staged(v.cache_slot, if (key) 0 else 1, 0);
-    copyBf16(m, e, cache.history(v.cache_slot, if (key) 0 else 1), taps, 3 * state.kv_width);
-    copyBf16(m, e, projected, cache.staged(v.cache_slot, if (key) 0 else 1, 3), rows * state.kv_width);
-    if (is_tree) {
-        const src = at(s.conv_src, base * 4 * 4);
-        switch (if (key) w.attn.k_conv else w.attn.v_conv) {
-            .static => |weight| tree.convStatic(&m.tree, e, taps, r(weight), src, raw, @intCast(rows), state.kv_width),
-            .dynamic => |d| tree.convDynamic(&m.tree, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), src, raw, @intCast(rows), state.kv_width),
-        }
-    } else switch (if (key) w.attn.k_conv else w.attn.v_conv) {
-        .static => |weight| glue.convStatic(&m.glue, e, taps, r(weight), raw, @intCast(rows), state.kv_width),
-        .dynamic => |d| glue.convDynamic(&m.glue, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), raw, @intCast(rows), state.kv_width),
+    const taps = stageConvInput(m, e, cache, v.cache_slot, if (key) 0 else 1, projected, base, rows);
+    const src = at(s.conv_src, base * 4 * 4);
+    switch (if (key) w.attn.k_conv else w.attn.v_conv) {
+        .static => |weight| tree.convStatic(&m.tree, e, taps, r(weight), src, raw, @intCast(rows), state.kv_width),
+        .dynamic => |d| tree.convDynamic(&m.tree, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), src, raw, @intCast(rows), state.kv_width),
+    }
+}
+
+fn convInputsForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize) void {
+    const lp = m.weight_plan.at(v.layer);
+    const w = &m.weights.layers[v.layer];
+    const k_taps = stageConvInput(m, e, cache, v.cache_slot, 0, at(s.k_raw, 0), base, rows);
+    const v_taps = stageConvInput(m, e, cache, v.cache_slot, 1, at(s.v_raw, 0), base, rows);
+    const k_out = at(s.k_conv, base * state.kv_width * 2);
+    const v_out = at(s.v_conv, base * state.kv_width * 2);
+    const k_in = at(s.k_norm, base * state.hidden * 2);
+    const v_norm = if (v.hasMessages() or lp.kind == .global) at(s.v_norm, 0) else at(s.q_norm, 0);
+    const v_in = at(v_norm.buf, v_norm.off + base * state.hidden * 2);
+    switch (w.attn.k_conv) {
+        .static => |kw| switch (w.attn.v_conv) {
+            .static => |vw| glue.convStaticKv(&m.glue, e, k_taps, r(kw), k_out, v_taps, r(vw), v_out, @intCast(rows), state.kv_width),
+            .dynamic => |vd| {
+                glue.convStatic(&m.glue, e, k_taps, r(kw), k_out, @intCast(rows), state.kv_width);
+                glue.convDynamic(&m.glue, e, v_taps, v_in, r(vd.static_w), r(vd.projection), v_out, @intCast(rows), state.kv_width);
+            },
+        },
+        .dynamic => |kd| switch (w.attn.v_conv) {
+            .dynamic => |vd| glue.convDynamicKv(&m.glue, e, k_taps, k_in, r(kd.static_w), r(kd.projection), k_out, v_taps, v_in, r(vd.static_w), r(vd.projection), v_out, @intCast(rows), state.kv_width),
+            .static => |vw| {
+                glue.convDynamic(&m.glue, e, k_taps, k_in, r(kd.static_w), r(kd.projection), k_out, @intCast(rows), state.kv_width);
+                glue.convStatic(&m.glue, e, v_taps, r(vw), v_out, @intCast(rows), state.kv_width);
+            },
+        },
     }
 }
 

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the paired integration after #4981 landed at b5df430692. There are two additional source conflicts and one clean-looking hunk that needs a correction:

That scratch integration passed 157 host tests with 11 skips, all 71 Metal kernels and 75 planted controls, and the pinned checkpoint replay again on M5 Max (7/7 focused checks). M3 and the final serving, memory and #5004 failure-path gates remain open.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I tested c1a82fe5d1 on M5 Max after a clean trial merge into a3c3e5cef. The native host build completed, 156 tests passed with 11 skipped, and the Metal contract passed 69 kernels and caught all 73 planted controls.

I also added #5004's current ca7cb9485b to that trial tree. The only conflict was forward.zig. The resolution below keeps indexed convolutions on tree segments, pairs the linear K/V dispatch when both weights use the same kind, and keeps the separate static/dynamic fallback for mixed weights. The combined tree passed 156 tests with 11 skipped, and the Metal contract passed 71 kernels, caught all 75 controls and reported zero launch-limit problems.

zig build test-inkling2-host test-inkling2-metal-host tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'metal inkling2'

The resolved forward.zig blob is 688fdf08adb67d7b096647414a6b6803e93f4ac7. These are synthetic and kernel checks on the revised heads. The earlier pinned checkpoint replay is on the previous heads. M3, final checkpoint serving and memory, and #5004's separate cleanup finding remain open.

Exact forward.zig resolution
diff --git a/zig/src/families/inkling2/metal/forward.zig b/zig/src/families/inkling2/metal/forward.zig
index a5b13f0e6..688fdf08a 100644
--- a/zig/src/families/inkling2/metal/forward.zig
+++ b/zig/src/families/inkling2/metal/forward.zig
@@ -198,11 +198,17 @@ fn prepareAttentionInputs(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scra
     }
 }
 
-fn staticPostConv(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, weight: ck.Tensor, out: Ref, base: usize, rows: usize, is_tree: bool) void {
+fn stageConvInput(m: *const Model, e: mtl.ComputeEncoder, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, base: usize, rows: usize) Ref {
     const channels = state.convWidth(conv_state);
     const taps = cache.staged(slot, conv_state, 0);
     copyBf16(m, e, cache.history(slot, conv_state), taps, 3 * channels);
     copyBf16(m, e, at(raw.buf, raw.off + base * channels * 2), cache.staged(slot, conv_state, 3), rows * channels);
+    return taps;
+}
+
+fn staticPostConv(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, slot: usize, conv_state: usize, raw: Ref, weight: ck.Tensor, out: Ref, base: usize, rows: usize, is_tree: bool) void {
+    const channels = state.convWidth(conv_state);
+    const taps = stageConvInput(m, e, cache, slot, conv_state, raw, base, rows);
     if (is_tree) {
         tree.convStatic(&m.tree, e, taps, r(weight), at(s.conv_src, base * 4 * 4), at(out.buf, out.off + base * channels * 2), @intCast(rows), @intCast(channels));
     } else {
@@ -227,13 +233,14 @@ fn attendSegments(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, v:
             .segs = a(at(s.segs, si * @sizeOf(ap.Seg))),
         };
         const kv = attention.Cache{ .k = a(cache.keys(v.cache_slot)), .v = a(cache.values(v.cache_slot)) };
-        try convInputForAttention(m, e, s, cache, v, base, rows, true, sm.is_tree);
-        try convInputForAttention(m, e, s, cache, v, base, rows, false, sm.is_tree);
         if (sm.is_tree) {
+            treeConvInputForAttention(m, e, s, cache, v, base, rows, true);
+            treeConvInputForAttention(m, e, s, cache, v, base, rows, false);
             attention.prepTree(&m.attention, e, rr, layer, prep, meta, .{ a(at(s.q_raw, base * state.query_width * 2)), a(at(s.k_conv, base * state.kv_width * 2)), a(at(s.v_conv, base * state.kv_width * 2)), a(at(s.rel_raw, base * state.rel_width * 2)) }, .{ a(r(m.weights.layers[v.layer].attn.q_scale)), a(r(m.weights.layers[v.layer].attn.rel_scale)) }, a(at(s.q_prep, base * state.query_width * 2)), a(at(s.rel_prep, base * state.rel_width * 2)), kv);
             attention.relTable(&m.attention, e, rr, a(at(s.rel_prep, base * state.rel_width * 2)), a(r(m.weights.layers[v.layer].attn.rel_projection)), a(at(s.rel_tab, base * 24 * ap.extent * 2)));
             try attention.attendTree(&m.attention, e, rr, layer, state.max_attention_stride, @intCast(start), meta, a(at(s.tree_paths, base * state.window_rows * 4)), a(at(s.tree_tail_o, base * 2 * 24 * ap.head_dim * 4)), a(at(s.tree_tail_ml, base * 24 * 16)), a(at(s.q_prep, base * state.query_width * 2)), kv, a(at(s.rel_tab, base * 24 * ap.extent * 2)), a(at(s.part_o, base * 24 * state.max_attention_stride * ap.head_dim * 4)), a(at(s.part_ml, base * 24 * state.max_attention_stride * 8)), a(at(s.sink, base * 24 * 2)), a(at(s.gate, base * state.query_width * 2)), a(at(s.att, base * state.query_width * 2)));
         } else {
+            convInputsForAttention(m, e, s, cache, v, base, rows);
             attention.prep(&m.attention, e, rr, layer, prep, meta, .{ a(at(s.q_raw, base * state.query_width * 2)), a(at(s.k_conv, base * state.kv_width * 2)), a(at(s.v_conv, base * state.kv_width * 2)), a(at(s.rel_raw, base * state.rel_width * 2)) }, .{ a(r(m.weights.layers[v.layer].attn.q_scale)), a(r(m.weights.layers[v.layer].attn.rel_scale)) }, a(at(s.q_prep, base * state.query_width * 2)), a(at(s.rel_prep, base * state.rel_width * 2)), kv);
             attention.relTable(&m.attention, e, rr, a(at(s.rel_prep, base * state.rel_width * 2)), a(r(m.weights.layers[v.layer].attn.rel_projection)), a(at(s.rel_tab, base * 24 * ap.extent * 2)));
             try attention.attend(&m.attention, e, rr, layer, state.max_attention_stride, 0, meta, a(at(s.q_prep, base * state.query_width * 2)), kv, a(at(s.rel_tab, base * 24 * ap.extent * 2)), a(at(s.part_o, base * 24 * state.max_attention_stride * ap.head_dim * 4)), a(at(s.part_ml, base * 24 * state.max_attention_stride * 8)), a(at(s.sink, base * 24 * 2)), a(at(s.gate, base * state.query_width * 2)), a(at(s.att, base * state.query_width * 2)));
@@ -242,24 +249,45 @@ fn attendSegments(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, v:
     }
 }
 
-fn convInputForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize, key: bool, is_tree: bool) !void {
+fn treeConvInputForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize, key: bool) void {
     const lp = m.weight_plan.at(v.layer);
     const w = &m.weights.layers[v.layer];
     const raw = if (key) at(s.k_conv, base * state.kv_width * 2) else at(s.v_conv, base * state.kv_width * 2);
-    const projected = if (key) at(s.k_raw, base * state.kv_width * 2) else at(s.v_raw, base * state.kv_width * 2);
+    const projected = if (key) at(s.k_raw, 0) else at(s.v_raw, 0);
     const normalized = if (key) at(s.k_norm, 0) else if (v.hasMessages() or lp.kind == .global) at(s.v_norm, 0) else at(s.q_norm, 0);
-    const taps = cache.staged(v.cache_slot, if (key) 0 else 1, 0);
-    copyBf16(m, e, cache.history(v.cache_slot, if (key) 0 else 1), taps, 3 * state.kv_width);
-    copyBf16(m, e, projected, cache.staged(v.cache_slot, if (key) 0 else 1, 3), rows * state.kv_width);
-    if (is_tree) {
-        const src = at(s.conv_src, base * 4 * 4);
-        switch (if (key) w.attn.k_conv else w.attn.v_conv) {
-            .static => |weight| tree.convStatic(&m.tree, e, taps, r(weight), src, raw, @intCast(rows), state.kv_width),
-            .dynamic => |d| tree.convDynamic(&m.tree, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), src, raw, @intCast(rows), state.kv_width),
-        }
-    } else switch (if (key) w.attn.k_conv else w.attn.v_conv) {
-        .static => |weight| glue.convStatic(&m.glue, e, taps, r(weight), raw, @intCast(rows), state.kv_width),
-        .dynamic => |d| glue.convDynamic(&m.glue, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), raw, @intCast(rows), state.kv_width),
+    const taps = stageConvInput(m, e, cache, v.cache_slot, if (key) 0 else 1, projected, base, rows);
+    const src = at(s.conv_src, base * 4 * 4);
+    switch (if (key) w.attn.k_conv else w.attn.v_conv) {
+        .static => |weight| tree.convStatic(&m.tree, e, taps, r(weight), src, raw, @intCast(rows), state.kv_width),
+        .dynamic => |d| tree.convDynamic(&m.tree, e, taps, at(normalized.buf, normalized.off + base * state.hidden * 2), r(d.static_w), r(d.projection), src, raw, @intCast(rows), state.kv_width),
+    }
+}
+
+fn convInputsForAttention(m: *const Model, e: mtl.ComputeEncoder, s: *state.Scratch, cache: *state.Cache, v: *const layer_plan.Visit, base: usize, rows: usize) void {
+    const lp = m.weight_plan.at(v.layer);
+    const w = &m.weights.layers[v.layer];
+    const k_taps = stageConvInput(m, e, cache, v.cache_slot, 0, at(s.k_raw, 0), base, rows);
+    const v_taps = stageConvInput(m, e, cache, v.cache_slot, 1, at(s.v_raw, 0), base, rows);
+    const k_out = at(s.k_conv, base * state.kv_width * 2);
+    const v_out = at(s.v_conv, base * state.kv_width * 2);
+    const k_in = at(s.k_norm, base * state.hidden * 2);
+    const v_norm = if (v.hasMessages() or lp.kind == .global) at(s.v_norm, 0) else at(s.q_norm, 0);
+    const v_in = at(v_norm.buf, v_norm.off + base * state.hidden * 2);
+    switch (w.attn.k_conv) {
+        .static => |kw| switch (w.attn.v_conv) {
+            .static => |vw| glue.convStaticKv(&m.glue, e, k_taps, r(kw), k_out, v_taps, r(vw), v_out, @intCast(rows), state.kv_width),
+            .dynamic => |vd| {
+                glue.convStatic(&m.glue, e, k_taps, r(kw), k_out, @intCast(rows), state.kv_width);
+                glue.convDynamic(&m.glue, e, v_taps, v_in, r(vd.static_w), r(vd.projection), v_out, @intCast(rows), state.kv_width);
+            },
+        },
+        .dynamic => |kd| switch (w.attn.v_conv) {
+            .dynamic => |vd| glue.convDynamicKv(&m.glue, e, k_taps, k_in, r(kd.static_w), r(kd.projection), k_out, v_taps, v_in, r(vd.static_w), r(vd.projection), v_out, @intCast(rows), state.kv_width),
+            .static => |vw| {
+                glue.convDynamic(&m.glue, e, k_taps, k_in, r(kd.static_w), r(kd.projection), k_out, @intCast(rows), state.kv_width);
+                glue.convStatic(&m.glue, e, v_taps, r(vw), v_out, @intCast(rows), state.kv_width);
+            },
+        },
     }
 }
 

Igor Lessio - AIFLOW LABS

@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Real Inkling 2 Mini Checkpoint & Multi-Architecture Receipt (c1a82fe5d1)

Tested c1a82fe5d1 (c1a82fe5d1b5d3b3c2e045e888293481eb4b2fd9) against the real Inkling 2 Mini checkpoint on Apple M5 Ultra 512 GiB and Apple M3 Ultra 512 GiB using an ephemeral scratch harness (test-inkling2-real-tree, cleaned up after the run; zero repo source changes pushed to PR #5011).

Checkpoint Identity

  • Model: Inkling-2-Mini-ed40e7da (model_type: inkling2_loop, 24 layers / 48 visits, hidden_size: 2304, 128 routed experts top-8, NVFP4 layers 0–19 / MXFP8 layers 20–23, sliding_window_size: 1024, unpadded_vocab_size: 200058)
  • File hashes (identical on both machines):
    • config.json (2,722 B): sha256 a7a349601f0984c4abf999c480ef775d8567d21f5f84b4e8a3e035b44f288dc2
    • model.safetensors.index.json (109,300 B): sha256 c1631065b7b00787993522dddc66a68b3abee869192977fb3dcb796e63bc5838
    • model-00001-of-00001.safetensors (19,526,019,168 B): sha256 65e60f51aa1284d4fb022584908c315270334d991828bb774af60584523539d1
    • mtp.safetensors (635,801,416 B): sha256 7c3b651317f01f73bcf4e1dceba66ef8b7e1a1eac6bc171e882e690a4b10a1d2

1. Apple M5 Ultra 512 GiB (applegpu_g17, tensor_units=true, Metal 4 path — unmodified c1a82fe5d1)

  • Synthetic 48-visit GPU + host suite (zig build test-inkling2-metal-host --summary all, no checkpoint env):
    • 5/5 steps succeeded; 111/118 tests passed (7 skipped) (22s MaxRSS:2G, total 36.051s), including 48-visit Inkling 2 Mini Metal verify tree matches sequential replay bit-for-bit and passes C2/C7.
  • Built-in real-checkpoint suite (TF_INKLING2_METAL_DIR=... zig build test-inkling2-metal-host --summary all):
    • 5/5 steps succeeded; 114/120 tests passed (6 skipped) (1m MaxRSS:19G, total 1:14.58), including Mini Metal serving matches the host reference token for token and Mini Metal verify tree matches serial target bit-for-bit across all branches.
  • Real-checkpoint tree receipt (TF_INKLING2_REAL_TREE=1 zig build test-inkling2-real-tree --summary all):
    • 5/5 steps succeeded; 8/8 tests passed (4m52.77s, MaxRSS:19G, 0 leaks).
    • Timings & memory:
      • Model.load: 642.3 ms; target.warm(): 2326.5 ms; selected_bytes = shard_bytes = 19,525,870,752 B (18.18 GiB)
      • Before load: resident = 7.63 MiB, footprint = 2.45 MiB, maxrss = 7.63 MiB
      • After Model.load: resident = 18647.20 MiB (18.21 GiB), footprint = 18645.72 MiB (18.21 GiB), maxrss = 18647.22 MiB, metal_alloc = 18.82 GiB
      • After Metal.init + warm(): resident = 18651.31 MiB (18.21 GiB), footprint = 19728.00 MiB (19.27 GiB), maxrss = 18651.31 MiB, metal_alloc = 18.82 GiB
      • After Tests 1–3: resident = 18660.95 MiB (18.22 GiB), footprint = 19727.83 MiB (19.27 GiB), peak_footprint = 20.73 GiB, maxrss = 18.23 GiB, metal_alloc = 18.82 GiB
    • Checks:
      • Test 1 (Short & wrap-around sliding window/ring branch/keep/rollback/replay, parents = {-1, 0, 0, 1, 2, 4}, all 5 paths including non-prefix {0, 2, 4, 5}, plus explicit verify + rollback of {-1, 0, 0, 1} + 2 subsequent decode tokens vs clean 1-token sequential replay, 0-ULP FP32 std.mem.eql(u8, ...) logits & feature taps):
        • prompt_len=68 (ring=1280): PASS (8868.4 ms)
        • prompt_len=1278 (ring=1280) (past 1024 window, straddles sliding_ring=1280 mid-tree [1278..1282]): PASS (109674.9 ms)
        • prompt_len=1296 (ring=1280) (strictly past 1024 window and 1280 ring): PASS (111748.6 ms)
      • Test 2 (Mixed linear + tree batch b.verify & b.keep, checking both chain and tree FP32 logits bit-for-bit + next decode token vs separate sequential streams):
        • prompt_len=24, tree_path={0, 2, 4, 5}: PASS (1786.8 ms)
        • prompt_len=1286, tree_path={0, 2} (past 1280 ring, last != rows - 1): PASS (49884.9 ms)
      • Test 3 (End-to-end lanes.Engine conformance + snapshot resume, fill_lanes=8, non-prefix winning branch {-1, -1, 0, 1, 3}):
        • PASS (2207.2 ms): plain == tree == resumed (12 tokens: 3033 1011 2022 4044 1011 2022 3033 1011 2022 4044 1011 2022), ts.drafted=24, ts.accepted=10, rs.drafted=24, rs.accepted=10, rs.cached=8, saw_non_prefix_rows=true.

2. Apple M3 Ultra 512 GiB (applegpu_g15, tensor_units=false, pre-M5 / Metal 3 shader path)

  • Disclosed local compile overlay for M3 Metal 3 strict address-space checking:
    • Unmodified c1a82fe5d1 failed to compile zig/kernels/metal/inkling2/prompt_attention.metal (prompt_attention_pre_m5) at ink_prompt_rh (line 11) and ink_fold (line 15) with error: reference type must have explicit address space qualifier (110/118 passed, 7 skipped, 1 failed).
    • Applied PR #4980's exact 2-line thread address-space qualifier diff locally in the ephemeral scratch copy of zig/kernels/metal/inkling2/prompt_attention.metal (const thread InkPromptSeg& s and thread float& mm, thread float& ll, ..., thread float& a, thread float& b). With that #4980 compile overlay, all builds and GPU tests compiled and ran cleanly.
  • Synthetic 48-visit GPU + host suite (zig build test-inkling2-metal-host --summary all, no checkpoint env, with #4980 overlay):
    • 5/5 steps succeeded; 111/118 tests passed (7 skipped) (20s MaxRSS:2G, total 28.218s).
  • Built-in real-checkpoint suite (TF_INKLING2_METAL_DIR=... zig build test-inkling2-metal-host --summary all, with #4980 overlay):
    • 5/5 steps succeeded; 114/120 tests passed (6 skipped) (51s MaxRSS:19G, total 59.191s).
  • Real-checkpoint tree receipt (TF_INKLING2_REAL_TREE=1 zig build test-inkling2-real-tree --summary all, with #4980 overlay):
    • 5/5 steps succeeded; 8/8 tests passed (1m30.83s, MaxRSS:19G, 0 leaks).
    • Timings & memory:
      • Model.load: 662.9 ms; target.warm(): 908.1 ms; selected_bytes = shard_bytes = 19,525,870,752 B (18.18 GiB)
      • Before load: resident = 7.50 MiB, footprint = 2.06 MiB, maxrss = 7.50 MiB
      • After Model.load: resident = 18648.08 MiB (18.21 GiB), footprint = 18644.67 MiB (18.21 GiB), maxrss = 18648.09 MiB, metal_alloc = 18.82 GiB
      • After Metal.init + warm(): resident = 18651.50 MiB (18.21 GiB), footprint = 19820.83 MiB (19.36 GiB), maxrss = 18651.50 MiB, metal_alloc = 18.82 GiB
      • After Tests 1–3: resident = 18660.84 MiB (18.22 GiB), footprint = 19821.51 MiB (19.36 GiB), peak_footprint = 20.81 GiB, maxrss = 18.23 GiB, metal_alloc = 18.82 GiB
    • Checks:
      • Test 1: prompt_len=68 PASS (5877.2 ms), prompt_len=1278 PASS (28977.0 ms), prompt_len=1296 PASS (30152.3 ms) — all bit-for-bit FP32 logits & feature taps identical to sequential replay.
      • Test 2: prompt_len=24, tree_path={0, 2, 4, 5} PASS (1537.7 ms), prompt_len=1286, tree_path={0, 2} PASS (13003.3 ms).
      • Test 3: PASS (3195.2 ms): plain == tree == resumed (12 tokens: 3033 1011 2022 4044 1011 2022 3033 1011 2022 4044 1011 2022, bit-identical to Apple M5 Ultra), ts.drafted=24, ts.accepted=10, rs.drafted=24, rs.accepted=10, rs.cached=8, saw_non_prefix_rows=true.

3. Per-Cache & Tree-State Memory Overhead (Both Architectures)

  • st.cacheBytes(256) = 388,232,680 B (370.25 MiB)
  • st.cacheBytes(2048) = 446,952,936 B (426.25 MiB)
  • st.scratchBytes(32) = 75,901,312 B (72.39 MiB); st.scratchBytes(256) = 601,596,160 B (573.73 MiB)
  • Tree-state overhead:
    • Per-cache staged conv taps (st.taps_bytes): 165,494,784 B (157.83 MiB/cache)
    • Per-cache rollback conv backup (st.conv_bytes): 1,916,928 B (1.83 MiB/cache)
    • Shared scratch tree buffers (batch_rows = 32: conv_src, tree_paths, tree_tail_o, tree_tail_ml): 801,280 B (782.50 KiB)
    • Tree compaction/parent metadata structs (pending_parents, KeepKvArgs, KeepConvArgs): 1,112 B
    • Feature capture buffers (st.captureBytes(32) + st.captureBytes(256) when prepare_features enabled): 5,308,416 B (5.06 MiB)

@gilby
gilby force-pushed the v4-3-verify-tree-rebased branch from c1a82fe to 7e8a1f2 Compare November 25, 2026 16:11
@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto origin/main (f3c0fa8c65) at head 7e8a1f29af:

  • Integrated #5000 (e64efd8213) fused on-the-fly relative-bias computation (removing tf_ink2_rel_table / rel_tab) into tf_ink2_attn_scalar_tree, tf_ink2_attn_prompt_tree_prefix, tf_ink2_attn_prompt_tree_tail, attention.zig, forward.zig, state.zig, and metal_inkling2_tree_attn.zig.
  • Switched metal_inkling2_tree.zig probe registration to contract.register (#5058) with matching errdefers.
  • Fixed keepFn in backend.zig to populate cache.logits whenever cache.logits_gen == self.verify_gen (matching origin/main after #4529 removed the unconditional verifyFn copy for last == rows - 1).

Fresh checks on 7e8a1f29af (alongside the Apple M5 Ultra 512 GiB + Apple M3 Ultra 512 GiB real-checkpoint TF_INKLING2_REAL_TREE=1 receipt in #issuecomment-7166583709):

  • python3 tools/pr_check.py --base origin/main --pr 5011: lean 164 vs 164, 0 new, 0 error(s) (31 changed files, max touched file 598 <= 600 lines); zig fmt --check build.zig zig and git diff --check origin/main..HEAD exit 0.
  • zig build -Dcpu=apple_m1 -Doptimize=ReleaseFast, compile-inkling2-native-host, compile-inkling2-native-host -Dtarget=x86_64-windows, compile-native-cuda-windows, tf-kernel-contract -Doptimize=ReleaseFast: all exit 0.
  • zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all: 5/5 steps succeeded; 118/125 tests passed (7 skipped) (0 failed; tree_gpu_test.zig 48-visit differential + C2/C7 + lanes.Engine conformance pass).
  • ./zig-out/bin/tf-kernel-contract --only "metal inkling2" on Apple M5 Max: SUMMARY 70 kernels: 70 pass gates 1-4, 0 fail, 0 known findings; 76 controls: 76 red as planted, 0 missed; 0 limit problems; gates 55909 ms, limits 626 ms (exit 0).
  • ./zig-out/bin/tf-kernel-contract --only "metal inkling2 tree" on Apple M5 Max: SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 4709 ms, limits 52 ms (exit 0).

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. The current head merges cleanly. It includes new relative-bias bindings, atomic probe registration and the kept final-row logits copy. The earlier green M5 result and disclosed M3 overlay receipt are retained for their tested trees.

Ready for controlled comparisons of this integration. Exact checkpoint tree replay and kept-row continuation still need coverage on the updated bias/cache path; the older receipt does not exercise those new bytes. The M3 cell also needs the reviewed address-space fix.

  • Synthena

@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed Real-Checkpoint Receipt on Rebased Head 7e8a1f29af

Re-ran the full synthetic, built-in real-checkpoint, and test-inkling2-real-tree suites on the rebased head 7e8a1f29af (7e8a1f29af29dc9f8ddf4edd86a662dd8157c635, rebased onto origin/main / #5000) across both Apple M5 Ultra 512 GiB and Apple M3 Ultra 512 GiB using an ephemeral scratch harness (cleaned up after the run; branch untouched).

Updated Path Coverage on 7e8a1f29af

  • Rebased #5000 fused on-the-fly relative-bias kernels (tf_ink2_attn_prompt, tf_ink2_attn_prompt_tree_prefix, tf_ink2_attn_prompt_tree_tail, tf_ink2_attn_scalar, tf_ink2_attn_scalar_tree): exercised on real checkpoint weights across short (prompt_len=24, 68), sliding-ring straddling (prompt_len=1278 crossing sliding_ring=1280 across [1278..1282]), and strictly wrapped (prompt_len=1286, 1296 > 1280 > 1024) sequences with rel_tab removed from state.Scratch.
  • Updated keepFn kept final-row logits copy & continuation: exercised for both last == rows - 1 (path={0, 2, 4, 5} in Test 1 and Test 2 prompt_len=24) and last != rows - 1 (paths {0}, {0,1}, {0,2}, {0,1,3} in Test 1; chain {0,1} and tree {0,2} in Test 2 prompt_len=1286), verifying cache.logits bit-for-bit (std.mem.eql(u8, ...) across all 200,058 FP32 unpadded vocab logits) immediately after b.keep(...) and across subsequent b.queue(...) decode tokens (including after explicit verify + rollback).
  • Checkpoint (Inkling-2-Mini-ed40e7da, identical on both machines): config.json (sha256 a7a349601f0984c4abf999c480ef775d8567d21f5f84b4e8a3e035b44f288dc2), model.safetensors.index.json (sha256 c1631065b7b00787993522dddc66a68b3abee869192977fb3dcb796e63bc5838), model-00001-of-00001.safetensors (19,526,019,168 B, sha256 65e60f51aa1284d4fb022584908c315270334d991828bb774af60584523539d1), mtp.safetensors (635,801,416 B, sha256 7c3b651317f01f73bcf4e1dceba66ef8b7e1a1eac6bc171e882e690a4b10a1d2).

1. Apple M5 Ultra 512 GiB (applegpu_g17, tensor_units=true — unmodified 7e8a1f29af)

  • zig build test-inkling2-metal-host --summary all:
    • 5/5 steps succeeded; 118/125 tests passed (7 skipped) (14s MaxRSS:2G, total 28.177s)
  • TF_INKLING2_METAL_DIR=... zig build test-inkling2-metal-host --summary all:
    • 5/5 steps succeeded; 120/125 tests passed (5 skipped) (39s MaxRSS:19G, total 45.563s)
  • TF_INKLING2_REAL_TREE=1 TF_INKLING2_METAL_DIR=... zig build test-inkling2-real-tree --summary all:
    • 5/5 steps succeeded; 9/9 tests passed (1m MaxRSS:19G, total 1:42.45, 0 leaks)
    • Timings & memory: load_ms=1626.4, warm_ms=2775.4, selected_bytes=shard_bytes=19525870752 (18.18 GiB); before load resident=7.64 MiB footprint=2.47 MiB maxrss=7.64 MiB -> after load resident=18647.16 MiB (18.21 GiB) footprint=18645.61 MiB (18.21 GiB) maxrss=18647.17 MiB metal_alloc=18.80 GiB -> after warm resident=18651.30 MiB (18.21 GiB) footprint=19711.03 MiB (19.25 GiB) maxrss=18651.30 MiB metal_alloc=18.80 GiB -> after tests resident=18660.72 MiB (18.22 GiB) footprint=19714.34 MiB (19.25 GiB) peak_footprint=20.71 GiB maxrss=18.23 GiB metal_alloc=18.81 GiB
    • Test 1 (Short & wrap-around branch/keep/rollback/replay, ring=1280): prompt_len=68 PASS (3591.3 ms), prompt_len=1278 PASS (33886.0 ms), prompt_len=1296 PASS (34757.1 ms)
    • Test 2 (Mixed linear + tree batch verify/keep/decode): prompt_len=24, tree_path_len=4 PASS (764.9 ms), prompt_len=1286, tree_path_len=2 PASS (15284.2 ms)
    • Test 3 (lanes.Engine conformance + snapshot resume): PASS (1172.3 ms): plain==tree==resumed (12 tokens: 3033 1011 2022 4044 1011 2022 3033 1011 2022 4044 1011 2022), ts.drafted=24 ts.accepted=10, rs.drafted=24 rs.accepted=10 rs.cached=8, saw_non_prefix_rows=true

2. Apple M3 Ultra 512 GiB (applegpu_g15, tensor_units=false — 7e8a1f29af + disclosed #4980 2-line compile overlay)

  • Compile overlay note: Applied PR #4980's exact 2-line thread address-space qualifier fix (const thread InkPromptSeg& s and thread float& mm, thread float& ll, ..., thread float& a, thread float& b) locally in the ephemeral scratch copy of zig/kernels/metal/inkling2/prompt_attention.metal only (PR #4980 still waiting to land/merge onto main). All synthetic and real-checkpoint tests compiled and passed cleanly on the pre-M5 / Metal 3 shader path with this overlay.
  • zig build test-inkling2-metal-host --summary all:
    • 5/5 steps succeeded; 118/125 tests passed (7 skipped) (16s MaxRSS:2G, total 33.513s)
  • TF_INKLING2_METAL_DIR=... zig build test-inkling2-metal-host --summary all:
    • 5/5 steps succeeded; 120/125 tests passed (5 skipped) (47s MaxRSS:19G, total 54.316s)
  • TF_INKLING2_REAL_TREE=1 TF_INKLING2_METAL_DIR=... zig build test-inkling2-real-tree --summary all:
    • 5/5 steps succeeded; 9/9 tests passed (1m MaxRSS:19G, total 1:28.84, 0 leaks)
    • Timings & memory: load_ms=2975.2, warm_ms=3465.1, selected_bytes=shard_bytes=19525870752 (18.18 GiB); before load resident=7.48 MiB footprint=2.06 MiB maxrss=7.48 MiB -> after load resident=18648.19 MiB (18.21 GiB) footprint=18644.75 MiB (18.21 GiB) maxrss=18648.20 MiB metal_alloc=18.80 GiB -> after warm resident=18651.81 MiB (18.21 GiB) footprint=19804.86 MiB (19.34 GiB) maxrss=18651.81 MiB metal_alloc=18.80 GiB -> after tests resident=18660.72 MiB (18.22 GiB) footprint=19807.94 MiB (19.34 GiB) peak_footprint=20.80 GiB maxrss=18.23 GiB metal_alloc=18.81 GiB
    • Test 1: prompt_len=68 PASS (3770.9 ms), prompt_len=1278 PASS (26321.7 ms), prompt_len=1296 PASS (27430.2 ms)
    • Test 2: prompt_len=24, tree_path_len=4 PASS (992.4 ms), prompt_len=1286, tree_path_len=2 PASS (11801.3 ms)
    • Test 3: PASS (1530.7 ms): plain==tree==resumed (12 tokens: 3033 1011 2022 4044 1011 2022 3033 1011 2022 4044 1011 2022, bit-identical to Apple M5 Ultra), ts.drafted=24 ts.accepted=10, rs.drafted=24 rs.accepted=10 rs.cached=8, saw_non_prefix_rows=true

3. Updated Memory & Scratch Overhead on 7e8a1f29af (Both Architectures)

  • st.cacheBytes(256) = 388,232,680 B (370.25 MiB), st.cacheBytes(2048) = 446,952,936 B (426.25 MiB)
  • st.scratchBytes(32) = 74,328,448 B (70.89 MiB), st.scratchBytes(256) = 589,013,248 B (561.73 MiB) (reduced vs c1a82fe5d1 after #5000 dropped rel_tab)
  • Tree-state overhead: taps_bytes = 165,494,784 B (157.83 MiB/cache), conv_backup_bytes = 1,916,928 B (1.83 MiB/cache), scratch_tree_bytes = 801,280 B (782.50 KiB), meta_structs_bytes = 1,112 B, feature_taps_capture(32+256) = 5,308,416 B (5.06 MiB)

This branch has not been deployed

No deployments
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.

3 participants