Skip to content

inkling2: enable SuffixLookup prompt copy drafting and DSpark copy_first - #5023

Open
gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:v4-4-suffix-lookup-rebased
Open

gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:v4-4-suffix-lookup-rebased

Conversation

@gilby

@gilby gilby commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: on main, lanes.Model already defaults .copy_drafts = true (with .copy_match = 8) and dspark.Drafter.factsFn() already sets .copy_first = true; however, backend.Metal.facts() did not wire the CLI --drafts / --no-drafts switch through backend.Options or lower the plain threshold to .copy_match = 4, and dspark.Drafter.factsFn() kept the default match threshold rather than explicitly setting .copy_match = 12.

After:

  • zig/src/families/inkling2/metal/backend.zig: Plumbs drafts: bool = true through Options, wiring .copy_drafts = self.options.drafts to the drafts switch and setting plain .copy_match = if (self.options.drafts) 4 else 8 in Metal.facts().

  • zig/src/families/inkling2/metal/dspark.zig: Sets .copy_match = 12 alongside the existing .copy_first = true in dspark.Drafter.factsFn() so DSpark skips draft-model hold() calls when a >= 12-token prompt suffix match is available and falls back cleanly to DSpark otherwise while still absorbing target rows.

  • zig/src/native/inkling2.zig: Passes .drafts = o.drafts to backend.Metal.init(...) and adds a startup unit test checking draft_sources.copies under --drafts / --no-drafts across 1 and 2 lanes and DSpark copy_first / copy_match = 12 reporting.

  • zig/src/native/inkling2_copy_fixture.zig, zig/src/native/inkling2_copy_test.zig, zig/src/native/inkling2_serving_test.zig, zig/src/inkling2_metal_host_test.zig: Add deterministic multi-stream (N=2), threshold (3/4/6/12), warm prompt-cache reuse, cancellation rollback, SuffixLookup.proposeAfter graft parity, DSpark copy_first hold-skip/fallback, and real-checkpoint copy-draft parity host tests.

  • Issue: Refs Inkling 2 Mini Metal V4: exact-serial scaling, GPU sampling, DFlash 2 acceleration, and kernel fusions #4961

  • Stacked on: main (9961ca4920, git merge-tree --write-tree clean: 7f89cff548935fafe4bbd9882ec1b54573f0e899)

Checks on this head

  • Head commit: d6e6286493
  • Lean checker, python3 tools/pr_check.py --base origin/main --pr 5023 (python3 tools/zig/lean_check.py): lean 164 vs 164, 0 new, 0 error(s) (7 changed files, max touched file 597 lines); zig fmt --check build.zig zig and git diff --check origin/main..HEAD exit 0.
  • Tests and build checks run:
    • zig build compile-inkling2-native-host: exit 0.
    • zig build compile-inkling2-native-host -Dtarget=x86_64-windows: exit 0.
    • zig build test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast: 45 pass, 4 skip (49 total) (0 failed; skipped: 4 optional env-gated checkpoint/tokenizer tests).
    • zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast test binary (--seed=0xcc8ea13f): 117 passed; 7 skipped; 0 failed (skipped: env-gated checkpoint/alloc tests and 2 JPEG tests pending matching libjpeg-turbo).
    • zig build tf-kernel-contract -Doptimize=ReleaseFast on Apple M5 Max (applegpu_g17, no .metal kernel modified); all 8 non-DSpark metal inkling2 suites exit 0:
      • metal inkling2 attention: SUMMARY 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 2668 ms, limits 76 ms
      • metal inkling2 prompt: SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems; gates 1363 ms, limits 62 ms
      • metal inkling2 glue: SUMMARY 10 kernels: 10 pass gates 1-4, 0 fail, 0 known findings; 13 controls: 13 red as planted, 0 missed; 0 limit problems; gates 392 ms, limits 601 ms
      • metal inkling2 experts: SUMMARY 12 kernels: 12 pass gates 1-4, 0 fail, 0 known findings; 17 controls: 17 red as planted, 0 missed; 0 limit problems; gates 4402 ms, limits 547 ms
      • metal inkling2 mma: SUMMARY 0 kernels: 0 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 0 ms, limits 63 ms
      • metal inkling2 loop: SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 158 ms, limits 62 ms
      • metal inkling2 runtime: SUMMARY 6 kernels: 6 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 38 ms, limits 26 ms
      • metal inkling2 vision: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 10 controls: 10 red as planted, 0 missed; 0 limit problems; gates 972 ms, limits 541 ms
      • Note on metal inkling2 dspark: on base 9961ca4920, --only "metal inkling2" hit the pre-existing dspark_kernels.zig:122-125 error: DsparkThreads bug (untouched here); that thread-guard fix (inkling2 metal dspark: match maxThreads guard to kappa (64) and attention (768) #5041) is now merged on main.
  • CI: Rebased on origin/main (9961ca4920); CI checks pending after force-push.
  • Not run, and why: Apple M1/M2/M4/M5 Pro served A/Bs were not run on this slice; 2-Mac served A-B-B-A receipts cover Apple M5 Ultra 512 GiB and Apple M3 Ultra 512 GiB across edit/copy-heavy workloads (plain and DSpark) and non-copy regression guards.

Receipt

  • Main against branch: A-B-B-A served runs (0 cross-leg token_sha256 mismatches across every cell on both machines; .copy_match = 12 for DSpark copy_first and .copy_match = 4 for plain copy drafting):
    • Apple M5 Ultra 512 GiB (main vs branch):
      • Edit/copy-heavy, plain (no DSpark):
        • distinct c=1: 68.75 -> 75.05 tok/s (+9.16%, TTFT +0.15%)
        • distinct c=4: 9.10 -> 8.60 agg tok/s (-5.49% due to first-prompt TTFT variance 39.7->45.3s over a 42.5s window), while steady decode throughput (decode_tps) improved 4.517 -> 4.820 tok/s (+6.7%).
      • Edit/copy-heavy, DSpark (--drafter {TARGET}, copy_match = 12):
        • distinct c=1: 66.20 -> 68.15 tok/s (+2.95%)
        • distinct c=4: 8.55 -> 9.50 tok/s (+11.11%, decode_tps 3.562 -> 4.782 tok/s, +34.2%)
      • Non-copy guard, DSpark (dspark_guard):
        • code c=1: 26.30 -> 26.10 (-0.76%, TTFT 0.315 -> 0.227s, -27.98%)
        • code c=4: 28.00 -> 28.05 (+0.18%, TTFT -2.79%)
        • chat c=1: 21.20 -> 21.70 (+2.36%, TTFT -2.12%)
        • chat c=4: 19.45 -> 19.45 (0.00%, TTFT -1.62%)
    • Apple M3 Ultra 512 GiB (main vs branch):
      • Edit/copy-heavy, plain (no DSpark):
        • distinct c=1: 35.35 -> 37.45 tok/s (+5.94%, TTFT -11.20%)
        • distinct c=4: 3.70 -> 3.80 tok/s (+2.70%, decode_tps 1.717 -> 1.741)
      • Edit/copy-heavy, DSpark (--drafter {TARGET}, copy_match = 12):
        • distinct c=1: 35.30 -> 36.00 tok/s (+1.98%, TTFT +2.90%)
        • distinct c=4: 3.75 -> 3.95 tok/s (+5.33%, decode_tps 1.502 -> 1.869 tok/s, +24.4%)
      • Non-copy guard, DSpark (dspark_guard, copy_match = 12):
        • code c=1: 17.15 -> 17.15 (0.00%)
        • code c=4: 14.90 -> 14.90 (0.00%, TTFT -3.95%)
        • chat c=1: 15.25 -> 15.70 (+2.95%)
        • chat c=4: 10.30 -> 10.30 (0.00%)
  • Boxes it reaches: backend.zig, dspark.zig, native/inkling2.zig, native/inkling2_copy_fixture.zig, native/inkling2_copy_test.zig, native/inkling2_serving_test.zig, inkling2_metal_host_test.zig.
  • New switch? No (--drafts / --no-drafts already exists; this wires drafts to backend.Metal alongside Model's existing .copy_drafts = true default and DSpark's existing .copy_first = true, updating plain .copy_match (4/8) and DSpark .copy_match = 12).
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Commit d6e6286493 on main (9961ca4920), Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max (applegpu_g17), Apple M5 Ultra 512 GiB, Apple M3 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 serving behind lanes (SuffixLookup prompt copies and DSpark hybrid drafting); verified locally and served across Apple M5 Ultra and Apple M3 Ultra; Apple M1/M2/M4/M5 Pro served A/Bs not directly run on this slice.
  • Exactness: 0 cross-leg token_sha256 mismatches across all plain, DSpark edit, and DSpark non-copy guard cells on both Apple M5 Ultra and Apple M3 Ultra; host tests prove token/logprob parity vs --no-drafts.
  • Decode speed before and after: See A-B-B-A tables above (edit workloads up to +9.16% plain / +11.11% DSpark on M5 Ultra, +5.94% plain / +5.33% DSpark on M3 Ultra; non-copy DSpark guard -0.76%..+2.36% M5 Ultra and 0.00%..+2.95% M3 Ultra).
  • Prompt speed before and after: Host-side prompt matching adds zero GPU prompt work and preserves or improves TTFT on non-copy guards (-1.62%..-27.98% M5 Ultra, 0.00%..-3.95% M3 Ultra).
  • Licence of any new weights or drafter: n/a.

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 independently trial-merged 2926de502e cleanly into 47a605aa12 on M5 Max. The four targets below passed 159 tests with 11 skips, covering the two-lane suffix-copy fixture, warm reuse, cancellation rollback and the DSpark hold/fallback cases.

zig build test-inkling2-host test-inkling2-metal-host test-inkling2-launch-map-host \
  compile-inkling2-native-host -Dfixed-cpu -j2 --summary all

The #5020 Q4 change also fits with this head once its new shader keeps the 256-thread reservation. I posted that independent current-main finding on #5020. I ran the host fixtures here. The optional checkpoint-backed cells and served throughput were outside this run.

Igor Lessio - AIFLOW LABS

@gilby
gilby force-pushed the v4-4-suffix-lookup-rebased branch from 2926de5 to d6e6286 Compare November 25, 2026 12:39
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The target forward, verification, sampling and cache operations stay unchanged in source, and copied tokens still pass through target verification. This looks ready for a controlled comparison, including positive copy activity, plain/drafted equality and warm-cache checks.

Please correct the baseline description: Model already defaults copy_drafts to true, and DSpark already sets copy_first. This head explicitly wires the drafts switch and changes the plain and DSpark match thresholds. The separate DSpark thread-guard fix is needed for its current load path.

  • Synthena

@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR description to reflect the main baseline accurately: lanes.Model already defaults .copy_drafts = true and DSpark already sets .copy_first = true; this change wires drafts through backend.Metal / Options and adjusts the plain (.copy_match = 4 / 8) and DSpark (.copy_match = 12) thresholds. Also noted that #5041 (DSpark thread-guard fix) is now merged on main.

  • Kevin

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