Skip to content

inkling2 metal: opt-in draft-only 4-bit/64 lm_head copy - #5020

Open
gilby wants to merge 3 commits into
ashhart:mainfrom
gilby:v4-10-draft-head-q4-rebased
Open

gilby wants to merge 3 commits into
ashhart:mainfrom
gilby:v4-10-draft-head-q4-rebased

Conversation

@gilby

@gilby gilby commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: on main, Inkling 2 Mini Metal's DSpark drafter reads the target's full BF16 unembedding weights (~893 MiB for lm_head across ~202k vocab rows x hidden=2304) on every draft pass via tf_ink2_dspark_logits / tf_ink2_dspark_base, leaving smaller-bandwidth GPUs memory-traffic-bound during speculative drafting while target verification remains BF16.

After: adds an opt-in draft-only 4-bit/group-64 affine copy (TF_INKLING2_DRAFT_HEAD_Q4=1, default 0/off) in zig/src/families/inkling2/metal/draft_head_q4.zig and kernel tf_ink2_dspark_logits_q4 in zig/kernels/metal/inkling2/dspark.metal (with [[max_total_threads_per_threadgroup(256)]]). When enabled and spare GPU memory accommodates the ~247 MiB copy (layout(n, k) aligned to 256-byte words/scales/biases) via d.weights.enableDraftHeadQ4 (leaving dspark.Drafter.init intact and dspark.zig at 597 lines), load-time quantization builds the Q4 copy without touching the BF16 target weights, and DSpark dispatches dspark_kernels.baseOrQ4 (logitsQ4 with softcap=false on DSpark base, softcap=true optional) while target verification continues on unmodified BF16 weights. Rebased cleanly onto origin/main (a992d0da99, resolving #5041): dspark_kernels.Kind.requiredThreads() and dspark_kernels_test.expectedWidth() retain #5041's width guards and live pipeline test with .logits_q4 => 256. Also adds transactional probe registration controls.registerProbe in zig/tests/contract/metal_inkling2_dspark_controls.zig (reserving capacity in both probes and kernels before appending via appendAssumeCapacity, used by metal_inkling2_draft_head_q4.zig:Suite.add and metal_inkling2_dspark.zig:Suite.add) plus a std.testing.FailingAllocator unit test verifying zero dangling probe / double-free / leak on OutOfMemory, registers TF_INKLING2_DRAFT_HEAD_Q4 in zig/src/platform/environment.zig + docs/environment.md, and adds metal_inkling2_draft_head_q4.zig kernel contract gates and controls.

Checks on this head

  • Head commit: 2b22da8c44
  • Lean checker, python3 tools/pr_check.py --base origin/main --pr 5020 (python3 tools/zig/lean_check.py): lean 164 vs 164, 0 new, 0 error(s) (19 changed files, max touched .zig file 600 lines in zig/src/platform/environment_test.zig; dspark.zig stays 597 lines, metal_inkling2_dspark.zig is 596 lines, dspark.metal is 594 lines); zig fmt --check build.zig zig and git diff --check origin/main..HEAD pass with exit 0.
  • Tests run on 2b22da8c44, with the command and pass, fail and skip counts:
    • zig build -Dcpu=apple_m1 -Doptimize=ReleaseFast (exit 0), zig build compile-native-cuda-windows (exit 0), zig build compile-inkling2-native-host (exit 0), and zig build compile-inkling2-native-host -Dtarget=x86_64-windows (exit 0).
    • zig build test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all: 46 passed; 4 skipped; 0 failed (5/5 steps; skipped: optional local checkpoint/tokenizer env tests).
    • zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all (--seed=0x31108503): 117 passed; 6 skipped; 0 failed (5/5 steps, including the live DSpark pipeline threadgroup-width test).
    • zig build test-inkling2-controls-host --summary all: 25/25 tests passed (5/5 steps, including the FailingAllocator registerProbe rollback test); zig build test-environment-host test-inkling2-controls-host test-metal-launch-map-host --summary all: 11/11 steps succeeded, 8/8 launch map tests passed (1313 launches, 2 controls, 0 missing), 0 failed.
    • zig build test-kernel-contract --summary all: 45/45 steps succeeded; 255/255 tests passed.
    • zig build tf-kernel-contract -Doptimize=ReleaseFast (exit 0) and ./zig-out/bin/tf-kernel-contract --only "metal inkling2" on Apple M5 Max (applegpu_g17, --seed 0x6b63): SUMMARY 62 kernels: 62 pass gates 1-4, 0 fail, 0 known findings; 68 controls: 68 red as planted, 0 missed; 0 limit problems; gates 12471 ms, limits 224 ms (exit 0).
  • CI: Force-pushed rebased head 2b22da8c44; CI checks pending after push.
  • Not run, and why: Apple M1/M2/M3/M4 served A/Bs not run for this slice; Apple M5 Pro and Apple M5 Ultra A-B-B-A runs from 688c39cc53 (unchanged kernel/runtime paths) cover default-off (TF_INKLING2_DRAFT_HEAD_Q4 unset on Apple M5 Pro) and opt-in TF_INKLING2_DRAFT_HEAD_Q4=1 self-drafted DSpark decode across c=1,4 and T=0.0,1.0.

Receipt

  • Main against branch: A-B-B-A served runs on 688c39cc53 (tools/bench_concurrent.py --tokens 128 --reps 2, --drafter {TARGET} --parallel 4 --context 8192, 0 cross-leg token_sha256 mismatches across all cells on both machines):
    • Apple M5 Pro 64 GiB (main vs branch, 19.09 -> 19.33 GiB weights / 27170 -> 26923 MiB spare = +247 MiB opt-in):
      • Default off (TF_INKLING2_DRAFT_HEAD_Q4 unset, T=0.0): 0.0% delta across all 4/4 cells (code c=1: 13.80 -> 13.80, c=4: 10.30 -> 10.30, chat c=1: 11.55 -> 11.55, c=4: 7.20 -> 7.20 tok/s).
      • Opt-in (TF_INKLING2_DRAFT_HEAD_Q4=1, 8/8 cells win):
        • c=1: code T=0.0: 13.80 -> 15.10 tok/s (+9.42%, TTFT 0.560s -> 0.552s, -1.34%); chat T=0.0: 11.60 -> 13.90 tok/s (+19.83%, TTFT 1.337s -> 1.280s, -4.26%); code T=1.0: 10.80 -> 13.50 tok/s (+25.00%, TTFT 0.560s -> 0.536s, -4.29%); chat T=1.0: 11.05 -> 13.40 tok/s (+21.27%, TTFT 1.373s -> 1.296s, -5.54%).
        • c=4: code T=0.0: 10.30 -> 11.00 tok/s (+6.80%, TTFT 1.345s -> 1.280s, -4.83%); chat T=0.0: 7.15 -> 8.00 tok/s (+11.89%, TTFT 5.139s -> 4.928s, -4.12%); code T=1.0: 8.45 -> 9.10 tok/s (+7.69%, TTFT 1.360s -> 1.285s, -5.48%); chat T=1.0: 7.10 -> 7.60 tok/s (+7.04%, TTFT 5.285s -> 5.070s, -4.08%).
    • Apple M5 Ultra 512 GiB (main vs branch, TF_INKLING2_DRAFT_HEAD_Q4=1, 19.09 -> 19.33 GiB weights / 371234 -> 370987 MiB spare = +247 MiB opt-in, 7/8 cells win):
      • c=1: code T=0.0: 26.00 -> 25.30 tok/s (-2.69%, TTFT 0.224s -> 0.216s, -3.35%); chat T=0.0: 21.10 -> 23.10 tok/s (+9.48%, TTFT +5.04%); code T=1.0: 19.40 -> 21.50 tok/s (+10.82%, TTFT +6.53%); chat T=1.0: 20.50 -> 22.30 tok/s (+8.78%, TTFT +4.70%).
      • c=4: code T=0.0: 28.10 -> 29.00 tok/s (+3.20%, TTFT -2.15%); chat T=0.0: 19.45 -> 21.00 tok/s (+7.97%, TTFT -2.84%); code T=1.0: 22.95 -> 24.30 tok/s (+5.88%, TTFT -7.93%); chat T=1.0: 19.80 -> 20.70 tok/s (+4.55%, TTFT -2.87%).
  • Boxes it reaches: draft_head_q4.zig, dspark.zig, dspark_kernels.zig, dspark_kernels_test.zig, dspark_weights.zig, dspark.metal, dspark_sources.zig, host_test.zig, inkling2_dspark_metal_records.zig, native/inkling2.zig, platform/environment.zig, platform/environment_test.zig, tensorfold.zig, docs/environment.md, metal_inkling2_draft_head_q4.zig, metal_inkling2_dspark.zig, metal_inkling2_dspark_controls.zig, metal_inkling2_main.zig, metal_mapping_test.zig.
  • New switch? Yes: TF_INKLING2_DRAFT_HEAD_Q4 (0 or 1, default 0/off), documented in docs/environment.md and registered in zig/src/platform/environment.zig.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Head commit 2b22da8c44 stacked on origin/main (a992d0da99), Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max (applegpu_g17); served A-B-B-A numbers from 688c39cc53 on Apple M5 Pro 64 GiB and Apple M5 Ultra 512 GiB; checkpoint Inkling-2-Mini.
  • Paths and platforms the change reaches, which I ran and which I could not: Inkling 2 Mini Metal DSpark opt-in draft head path across Apple Silicon Metal GPUs; Apple M1/M2/M3/M4 not directly run on this slice.
  • Exactness: 0 cross-leg token_sha256 mismatches across all --serial A-B-B-A legs on both Apple M5 Pro (default-off + TF_INKLING2_DRAFT_HEAD_Q4=1) and Apple M5 Ultra (TF_INKLING2_DRAFT_HEAD_Q4=1), proving identical target token output because target verification keeps unmodified BF16 lm_head.
  • Decode speed before and after: With TF_INKLING2_DRAFT_HEAD_Q4 unset, 0.0% delta; with TF_INKLING2_DRAFT_HEAD_Q4=1, 8/8 wins (+6.80%..+25.00%) on Apple M5 Pro and 7/8 wins (+3.20%..+10.82%, code T=0 c=1 -2.69%) on Apple M5 Ultra.
  • Prompt speed before and after: -1.34%..-5.54% TTFT across all 8/8 cells on Apple M5 Pro; -2.15%..-7.93% TTFT on c=4 (+4.70%..+6.53% on c=1 0.5s / 0.2s prompts) on Apple M5 Ultra.
  • 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 opt-in tf_ink2_dspark_logits_q4 (256 threads) in zig/kernels/metal/inkling2/dspark.metal and inkling2_dspark_metal_records.zig as the opt-in draft-head counterpart to tf_ink2_dspark_logits / tf_ink2_dspark_base when TF_INKLING2_DRAFT_HEAD_Q4=1.
  • A planted control for each new kernel, and each one fails as planted: All 68/68 controls on Apple M5 Max (2b22da8c44) and 56/56 controls on Apple M5 Pro (pre-rebase 92d78f5924) fail red as planted (0 missed), including TF_INKLING2_DRAFT_HEAD_Q4 / logits_q4 contracts and controls in metal_inkling2_draft_head_q4.zig and metal_inkling2_dspark_controls.zig.
  • Each backend's SUMMARY line and exit status:
    • Apple M5 Max (2b22da8c44): SUMMARY 62 kernels: 62 pass gates 1-4, 0 fail, 0 known findings; 68 controls: 68 red as planted, 0 missed; 0 limit problems; gates 12471 ms, limits 224 ms (exit 0).
    • Apple M5 Pro (pre-rebase 92d78f5924): SUMMARY 49 kernels: 49 pass gates 1-4, 0 fail, 0 known findings; 56 controls: 56 red as planted, 0 missed; 0 limit problems; gates 9085 ms, limits 7 ms (exit 0).
  • Chips I could not run: Apple M1/M2/M3/M4 not directly available on this slice.

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

On M5 Max I tested e19d1f700a combined with #5011 a7ba0336b2 on base ef4d6429fc. The focused checkpoint fixture passed with Q4 enabled and disabled, using thinkingmachines/Inkling-2-Mini@c9d028302cd0f035fdf8e7e91f089a4ce94d2195 for both the target model and mtp.safetensors.

TF_INKLING2_METAL_DIR=/path/to/target TF_INKLING2_DSPARK_DIR=/path/to/drafter \
TF_INKLING2_DRAFT_HEAD_Q4=1 zig build test-inkling2-metal-host -Dfixed-cpu -j2 --summary all

I filtered the Metal test artifact to Mini Metal opt-in DSpark drafting and forced it to rerun for each setting. Both runs passed 7/7, with accepted drafts, unchanged target tokens, rollback and the warm-cache replay. A third run passed with an extra assertion that the opted-in drafter actually allocated the Q4 head. The broader combined run passed 198 tests with 11 skipped. All 12 DSpark Metal kernels passed and all 12 planted controls were caught via tf-kernel-contract --only 'metal inkling2 dspark'.

This is a parity and activation check on M5 Max. I did not measure throughput or run older Apple GPUs. #5020 by itself also trial-merges cleanly after #4981 at b5df430692.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

The current-main integration of e19d1f700a on 47a605aa12 merges cleanly, but the DSpark shader reservation test now fails. It expects the reservation from the launch record and can't find it before tf_ink2_dspark_logits_q4. The shader, records and assertion are byte-identical in the standalone trial merge and in my trial with #5023, so #5023 doesn't introduce the failure.

Adding [[max_total_threads_per_threadgroup(256)]] immediately above the new entry restores the #4981 invariant without removing the check. The combined rerun passed all 118 executed Metal host tests with seven skipped, and the Metal contract passed all 12 DSpark kernels, caught all 12 controls and found zero limit problems.

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

This retest covers current-main integration and launch bounds. The checkpoint parity and activation receipt above is from the earlier base.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. The Q4 copy stays on the draft side, and target verification keeps the original weights.

Two fixes remain before landing. The new shader entry needs its declared 256-thread reservation to satisfy current main's assertion. Also, if the kernel-list append fails after the probe is stored, cleanup frees it while the owner list still holds it; make that ownership transfer safe on allocation failure. The earlier parity and activation results are recorded.

  • Synthena

@gilby
gilby force-pushed the v4-10-draft-head-q4-rebased branch from e19d1f7 to 688c39c Compare November 25, 2026 12:42
@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 688c39cc53 and #5023 d6e6286493 together on 9961ca492. The combined tree passed 170 tests with 11 skipped. On M5 Max, the Inkling contract loaded successfully, passed all 62 kernels, caught all 68 planted controls and reported zero launch-limit failures. That verifies both the new Q4 shader reservation and the existing DSpark loader correction for 64-thread kappa and 768-thread attention on this combination.

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

The allocation rollback finding still reproduces on 688c39cc53. I reserved one probe slot, left the kernel list empty, and used FailingAllocator to fail its first allocation after the probe is created. Suite.add returned OutOfMemory with one probe still published. Reserving capacity in both lists before the two appendAssumeCapacity calls made the same fixture pass, with both lists empty on failure.

The loader correction also fixes the standalone main failure reported on #4699. If Q4 needs another revision, that correction can land on its own. Checkpoint timing was outside this run.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. The Q4 shader now has its declared thread reservation, and the loader correction is present. The copy remains draft-only, with the original target weights used for verification.

The registration cleanup issue remains: if the kernel-list append fails after the owner append, local cleanup frees a probe still held by the suite. Please make the transfer atomic and cover that allocation failure. The earlier parity and activation results remain credited.

  • Synthena

@gilby
gilby force-pushed the v4-10-draft-head-q4-rebased branch from 688c39c to 2b22da8 Compare November 25, 2026 15:22
@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main (a992d0da99, resolving #5041 with .logits_q4 => 256 in dspark_kernels.Kind.requiredThreads / dspark_kernels_test.expectedWidth and keeping the live pipeline threadgroup-width test) and fixed the registration cleanup finding on head 2b22da8c44:

  • Added transactional controls.registerProbe in zig/tests/contract/metal_inkling2_dspark_controls.zig (ensureUnusedCapacity on both probes and kernels before appendAssumeCapacity) and wired metal_inkling2_draft_head_q4.zig:Suite.add and metal_inkling2_dspark.zig:Suite.add through it so an OutOfMemory on kernel-list growth leaves no dangling probe in the owner list.
  • Added a std.testing.FailingAllocator unit test in zig/tests/contract/metal_inkling2_dspark_controls.zig (registerProbe keeps existing owner list intact when kernel growth hits OutOfMemory) pre-populating 1 probe, failing kernels.ensureUnusedCapacity after probes.ensureUnusedCapacity succeeds, and verifying OutOfMemory, single cleanup of the failed probe, preserved owner list at len 1, and leak-free suite teardown under std.testing.allocator.
  • Re-verified on 2b22da8c44: python3 tools/pr_check.py --base origin/main --pr 5020 (lean 164 vs 164, 0 new, 0 errors), zig fmt --check build.zig zig, zig build test-inkling2-controls-host (25/25), zig build test-kernel-contract (45/45 steps, 255/255 tests), zig build test-inkling2-host (46 passed; 4 skipped; 0 failed), zig build test-inkling2-metal-host (117 passed; 6 skipped; 0 failed), and ./zig-out/bin/tf-kernel-contract --only "metal inkling2" on Apple M5 Max (SUMMARY 62 kernels: 62 pass gates 1-4, 0 fail, 0 known findings; 68 controls: 68 red as planted, 0 missed; 0 limit problems; gates 12471 ms, limits 224 ms, exit 0).

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

@gilby, about the probe-registration cleanup our review asked for: the same two-append pattern was on main in 85 places, and #5058 (now merged) fixes it there with one helper, contract.register. It reserves room in both lists before publishing, so a failed append can no longer free a probe the suite still holds:

errdefer p.deinit(); // with errdefer s.a.destroy(p) after create, as the suite's teardown frees it
try ct.register(s.a, &s.probes, &s.kernels, p, p.kernel());

Using it for this PR's new suites closes that item. zig/src/core/contract/register_test.zig shows the failure cases it covers.

  • Synthena

@gilby

gilby commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated #5020 (5803648c32, rebased cleanly onto origin/main 0102f73721) to address the shared contract.register cleanup (#5058):

  • Removed the local registerProbe wrapper in zig/tests/contract/metal_inkling2_dspark_controls.zig and switched metal_inkling2_draft_head_q4.zig, metal_inkling2_dspark.zig, and the OOM host test directly to contract.register.
  • Resolved the rebase conflict in zig/src/platform/environment_test.zig / environment_valid_cases.zig cleanly.

Verification on 5803648c32 (Apple M5 Max 48 GiB):

  • zig fmt --check build.zig zig & git diff --check: clean
  • python3 tools/pr_check.py --base origin/main --pr 5020: 0 errors (20 files, 0 new lean, 0 new import cycle edges)
  • zig build test-inkling2-controls-host -Dcpu=apple_m1: 27/27 passed
  • zig build test-inkling2-metal-host test-inkling2-launch-map-host compile-inkling2-native-host tf-kernel-contract -Dcpu=apple_m1: 53/53 steps succeeded (131 pass, 7 skip metal host, 2/2 launch map), zig test zig/src/platform/environment_test.zig: 36/36 passed
  • tf-kernel-contract --only "metal inkling2 dspark" on Apple M5 Max: 12/12 kernels pass gates 1-4 (0 fail), 12/12 planted controls red, 0 limit problems.

@gilby
gilby force-pushed the v4-10-draft-head-q4-rebased branch from 2b22da8 to 5803648 Compare November 26, 2026 09:43
@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby, this is close. The earlier asks are all closed, and with the switch off, nothing changes. The target always verifies against the BF16 unembed, so only draft proposals are affected. We found two overflow cases in the opt-in Q4 head:

  1. zig/src/families/inkling2/metal/draft_head_q4.zig:198: for a group holding BF16 0xff7f, 0x7f7f and 0x7f00, quantization picks b = -255·2^120, s = 34·2^120. The middle value should get code round((128+255)/34) = 11, but the FP32 v - b overflows to +Inf and is clamped to 15. Computing that ratio in f64 on the host fixes it. A test with exactly these three values (code 11 for the middle one, 15 for the maximum) would pin it.
  2. zig/kernels/metal/inkling2/dspark.metal:580: with the same scale and bias, code 15 stands for 255·2^120, the largest finite BF16. With contraction off, s * 15 overflows to +Inf before the negative bias is added. Please evaluate s*q + b as an explicit fma (or any form proven not to overflow when the result is finite), and add a shader contract case on that metadata that requires the finite maximum back.

Once both pass, we'll run the Mac device cells (default-off and opt-in, M3 and M5) ourselves.

  • Synthena

@gilby

gilby commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated #5020 (86fd596778) to fix both BF16-max overflow cases in the opt-in Q4 draft head:

  1. Host Q4 quantization (zig/src/families/inkling2/metal/draft_head_q4.zig):
    • quantizeGroups now computes (@as(f64, v) - @as(f64, b)) / @as(f64, s) and rounds/clamps in f64 instead of FP32.
    • Added unit test "quantizeGroups avoids FP32 overflow on full-span BF16 group (0xff7f, 0x7f7f, 0x7f00)" asserting b = -255·2^120 (0xff7f), s = 34·2^120 (0x7e08), codes 0 (0xff7f), 11 (0x7f00), and 15 (0x7f7f), plus finite @mulAdd dequant values.
  2. Metal Q4 dequant & shader contract (zig/kernels/metal/inkling2/dspark.metal, zig/tests/contract/metal_inkling2_draft_head_q4.zig, metal_inkling2_dspark_controls.zig):
    • Replaced s * float(...) + b in tf_ink2_dspark_logits_q4 with explicit fma(s, float((word >> (4u * e)) & 0xfu), b) (keeping dspark.metal at 594 lines <= 600 and updating the planted control anchor).
    • Added the full-span BF16 contract case (b = -255·2^120, s = 34·2^120, x[0] = 1.0, x[1..64] = 0) requiring exact finite 255·2^120 (0x7f7f) back for q = 15 (and negative-verified that without fma, the contract fails with +Inf).

Verification (Apple M5 Max 48 GiB)

  • python3 tools/pr_check.py --base origin/main: 0 errors
  • zig build test-inkling2-metal-host test-inkling2-controls-host test-kernel-contract: PASS (310/310 kernel-contract host tests passed)
  • ./zig-out/bin/tf-kernel-contract --only "metal inkling2 dspark": 12/12 kernels pass gates 1–4 (logits_q4: 14 shapes pass, worst 0.986 of bound), 12/12 controls red as planted, 0 limit problems.

@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thank you for fixing both full-span BF16 overflow cases. The latest head merges cleanly with current main.

The host now computes the quantization ratio in binary64, and the shader uses an explicit fused multiply-add. The new tests pin the 0/11/15 codes and the finite maximum case. The earlier thread reservation and shared probe-registration asks also remain closed. We found no new static correctness, ownership, fallback, or provenance blocker.

The remaining step is the promised M3 and M5 device coverage. Both default-off and opt-in runs need the DSpark kernel contract and checkpoint activation checks. Serving must compare current main with this head across greedy and sampled code/chat at one and four streams, with exact target tokens, positive accepted drafts when enabled, rollback and warm-cache replay. The off case should also confirm that pipeline loading and serving remain unchanged.

Thank you for the careful overflow reproductions and focused fixes.

  • Synthena

gilby and others added 3 commits November 27, 2026 02:44
Compute (v - b) / s in FP64 during host Q4 group quantization and evaluate s * q + b via fma(s, float(q), b) in tf_ink2_dspark_logits_q4 so full-span finite BF16 groups (b = -255 * 2^120, s = 34 * 2^120) do not overflow intermediate FP32 arithmetic.

Add a host unit test for BF16 {0xff7f, 0x7f7f, 0x7f00} and a Metal contract case exercising q = 15, 11, and 0 under the full-span metadata.
@ashhart
ashhart force-pushed the v4-10-draft-head-q4-rebased branch from 86fd596 to 3cdf72f Compare November 27, 2026 02:47

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