Skip to content

inkling2: rebase DSpark overhaul onto #4465 - #4699

Open
gilby wants to merge 11 commits into
ashhart:mainfrom
gilby:inkling2-lead-dspark-batched-gqa
Open

gilby wants to merge 11 commits into
ashhart:mainfrom
gilby:inkling2-lead-dspark-batched-gqa

Conversation

@gilby

@gilby gilby commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rebases the DSpark kernel overhaul, batched multi-stream speculative drafting, softmax chances, and two-pass GPU top-k sampling onto integrated main while preserving zero-ULP parity across plain and drafted paths.

What this changes

Transposes DSpark phi ([256, 201024]) and RNN weights (packRnn), replaces the score-scratch attention and sequential chain kernels with zero-score-scratch online-softmax tf_ink2_dspark_attention (768 threads, 20736 B TG, plus TF_SIMD_FRAGS=1 pre-M5 fallback), tiled tf_ink2_dspark_base, coalesced kappa/recurrent, and two-stage tf_ink2_dspark_logits, removes obsolete single-stream chain kernels (inkling2_dspark_chain_metal_records.zig), enables batched holdFn/absorbFn/chancesFn + fastTopKDraw two-pass GPU sampling, and guards non-macOS clock_gettime and DSpark Metal host tests so host/CI builds pass on all targets.

Checks on this head

  • Head commit: 6e6d858682 (on origin/main 3795e6054c)
  • Lean checker, tools/pr_check.py --pr 4699: lean 165 vs 165, 0 new, 18 changed files, 0 error(s).
  • Tests run on 6e6d858682 (Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max):
    • zig fmt --check build.zig zig and git diff --check origin/main..HEAD — exit 0.
    • zig build test-inkling2-host test-inkling2-controls-host test-inkling2-metal-host test-metal-launch-map-host compile-inkling2-native-host — 59/59 steps succeeded; 177/187 tests passed (10 skipped) (test-inkling2-host 45/4, test-inkling2-controls-host 19/0, test-inkling2-metal-host 105/6, test-metal-launch-map-host 8/0 over 1302 launches, compile-inkling2-native-host pass).
    • ./zig-out/bin/tf-kernel-contract --only "metal inkling2" — SUMMARY 61 kernels: 61 pass gates 1-4, 0 fail, 0 known findings; 65 controls: 65 red as planted, 0 missed; 0 limit problems (gates 10400 ms, limits 23 ms).
  • Real-checkpoint test-inkling2-metal-host (Inkling-2-Mini, 0652b7907b -> 8e1661e8c3):
    • Apple M5 Ultra 512 GiB: All 85 tests passed. (0 skipped, 0 failed); 46/46 kernels / 51/51 red controls / 0 limits (10243 ms).
    • Apple M5 Pro 64 GiB: All 85 tests passed. (0 skipped, 0 failed); 46/46 kernels / 51/51 red controls / 0 limits (9995 ms).
    • Apple M3 Ultra 512 GiB (Metal 3 TF_SIMD_FRAGS=1, evaluated with symmetric 2-line thread qualifier overlay on pre-existing prompt_attention.metal lines 11 and 15): All 85 tests passed. (0 skipped, 0 failed); 46/46 kernels / 51/51 red controls / 0 limits (12619 ms).
  • CI: Pending GitHub Actions on rebased head 6e6d858682.
  • Not run, and why: Non-Apple GPU backends (Metal-only change); Apple M5 Max, M5 Ultra, M5 Pro, and M3 Ultra all ran on real hardware.

Receipt

  • Integrated main (0652b7907b) against rebased #4699 (8e1661e8c3), Inkling-2-Mini (ed40e7da625f594fc9c4990f5f66be24873c22d7), --parallel 4 --context 8192, tools/bench_concurrent.py --alone --serial --levels 1,4 --tokens 256 --seed 1234 --temperatures 0,1.0 (--reps 3 on Ultra tiers, --reps 2 on Pro tier), alternating A1_base / B1_4699 / B2_4699 / A2_base with --drafter, plus plain_base / plain_4699 (--no-drafts):
    • Apple M5 Ultra 512 GiB (plain / A_base -> B_4699 aggregate tok/s):
      • code T=0.0 S=1: 16.2 / 22.9 -> 27.05 (1.18x vs base drafted, 1.67x vs plain)
      • code T=0.0 S=4: 28.95 / 19.55 -> 28.80 (1.47x vs base drafted, 0.99x vs plain)
      • chat T=0.0 S=1: 16.15 / 20.5 -> 23.60 (1.15x vs base drafted, 1.46x vs plain)
      • chat T=0.0 S=4: 29.35 / 15.15 -> 30.70 (2.03x vs base drafted, 1.05x vs plain)
      • code T=1.0 S=1: 16.2 / 17.6 -> 19.30 (1.10x vs base drafted, 1.19x vs plain)
      • code T=1.0 S=4: 28.65 / 15.2 -> 28.40 (1.87x vs base drafted, 0.99x vs plain)
      • chat T=1.0 S=1: 16.2 / 20.5 -> 15.90 (0.78x vs base drafted, 0.98x vs plain — repr seed=1234 throttles speculative depth via chances after early misses (24/52, 15.8 tok/s); serial seeds 1235/1236/1237 run 19.7/21.0/21.5 tok/s (98/172, 111/178, 114/173) vs base 17.8/19.8/19.6 tok/s)
      • chat T=1.0 S=4: 29.15 / 14.3 -> 29.30 (2.05x vs base drafted, 1.01x vs plain)
      • Accepted drafts (A1/B1/B2/A2): 10643/34220 (1301.78s, RSS 20.631 GB) vs 3405/5260 (939.54s, RSS 20.626 GB) / 3222/4945 (907.32s).
    • Apple M3 Ultra 512 GiB (TF_SIMD_FRAGS=1 Metal 3 with symmetric prompt_attention.metal thread overlay on both base and branch):
      • code T=0.0 S=1: 12.0 / 15.8 -> 18.10 (1.15x vs base drafted, 1.51x vs plain)
      • code T=0.0 S=4: 19.5 / 11.65 -> 19.50 (1.67x vs base drafted, 1.00x vs plain)
      • chat T=0.0 S=1: 11.95 / 15.0 -> 16.35 (1.09x vs base drafted, 1.37x vs plain)
      • chat T=0.0 S=4: 19.9 / 9.35 -> 20.15 (2.16x vs base drafted, 1.01x vs plain)
      • code T=1.0 S=1: 12.0 / 13.6 -> 12.10 (0.89x vs base drafted, 1.01x vs plain)
      • code T=1.0 S=4: 19.5 / 9.50 -> 19.55 (2.06x vs base drafted, 1.00x vs plain)
      • chat T=1.0 S=1: 11.95 / 13.5 -> 11.70 (0.87x vs base drafted, 0.98x vs plain)
      • chat T=1.0 S=4: 19.95 / 8.20 -> 20.00 (2.44x vs base drafted, 1.00x vs plain)
    • Apple M5 Pro 64 GiB:
      • code T=0.0 S=1: 13.1 / 13.3 -> 16.80 (1.26x vs base drafted, 1.28x vs plain)
      • code T=0.0 S=4: 19.75 / 10.0 -> 19.60 (1.96x vs base drafted, 0.99x vs plain)
      • chat T=0.0 S=1: 13.15 / 11.9 -> 15.30 (1.29x vs base drafted, 1.16x vs plain)
      • chat T=0.0 S=4: 20.35 / 7.7 -> 20.30 (2.64x vs base drafted, 1.00x vs plain)
      • code T=1.0 S=1: 13.05 / 10.35 -> 11.80 (1.14x vs base drafted, 0.90x vs plain)
      • code T=1.0 S=4: 19.6 / 7.75 -> 19.60 (2.53x vs base drafted, 1.00x vs plain)
      • chat T=1.0 S=1: 13.15 / 11.8 -> 12.10 (1.03x vs base drafted, 0.92x vs plain)
      • chat T=1.0 S=4: 20.3 / 7.2 -> 20.30 (2.82x vs base drafted, 1.00x vs plain)
  • Warm multi-turn /v1/chat/completions prompt cache (prompt_tokens=544/542, cold_cached=0, warm_cached=512, branch_cached=512): warm_equals_cold_tokens=True and warm_equals_cold_output=True on all 3 Macs (M5 Ultra accepted=59/95 cold, 49/98 warm, 55/98 branch; M3 Ultra 61/102, 55/110, 51/96; M5 Pro 55/79, 47/72, 51/81). Note /v1/completions bench_cache.py keeps 0 states on main (grid=64, tail=false, repeat_min=0).
  • Note on the \u70d2×24 report on the earlier overlay: origin/main uses prompt_rows = 64 in zig/src/families/inkling2/metal/state.zig (prompt(64, 3)), whereas that earlier overlay changed prompt_rows to 256 (prompt(256, 3)). On integrated main, All 85 tests passed across M5 Ultra, M5 Pro, and M3 Ultra (m3ov).
  • Boxes it reaches: Apple Silicon Metal (M5 Max, M5 Ultra, M5 Pro, and M3 Ultra Metal 3 TF_SIMD_FRAGS=1 verified).
  • New switch? None (TF_SIMD_FRAGS=1 pre-M5 shader path auto-selected at pipeline load when !device.tensorUnits()).
  • Environment: Rebased head 6e6d858682 on main 3795e6054c; 3-Mac full A-B-B-A on 8e1661e8c3 (0652b7907b), Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, macOS 27.2.1 / 27.0.1 / 26.6.2, Inkling-2-Mini ed40e7da.
  • Paths and platforms the change reaches: DSpark speculative draft/verify/absorb kernels (dspark.metal), softmax chances(), and two-pass GPU top-k sampling (draw.zig, dspark_sample.zig) on Apple Silicon Metal.
  • Exactness: 60/60 token_sha256 + 60/60 output_sha256 parity on M5 Ultra, 60/60 on M3 Ultra (m3ov), 40/40 on M5 Pro across all 6 server variants (plain_base, plain_4699, A1, B1, B2, A2) vs plain_base; conc == alone and conc == serial 100% (failed=0, unequal=0 in every cell); warm == cold 100%.
  • Decode speed before and after: Reported in Main against branch across all 3 Macs (eliminates S=4 7.2–19.6 tok/s regression while accelerating greedy S=1 +9–29% over base drafted / +16–67% over plain).
  • Prompt speed before and after: Unchanged on cold prefill; multi-turn warm /v1/chat/completions TTFT 7.165s–16.46s -> 0.59s–0.64s on M5 Ultra with 100% exact parity.
  • 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 replacements:
    • Updated DSpark kernels (tf_ink2_dspark_fuse_taps 48 B TG, tf_ink2_dspark_attention 768 threads / 20736 B TG online softmax with scoreBytes=0, tf_ink2_dspark_residual_norm 32 B TG, tf_ink2_dspark_kappa 64 threads, tf_ink2_dspark_recurrent 1024 B TG, tiled tf_ink2_dspark_base 5120 B TG, two-stage tf_ink2_dspark_logits 4224 B TG).
    • Removed obsolete single-stream chain kernels tf_ink2_dspark_chain_step and tf_ink2_dspark_chain_pick (inkling2_dspark_chain_metal_records.zig deleted).
    • Exported dspark_pre_m5 (#define TF_SIMD_FRAGS 1) alongside M5 dspark.
  • Planted controls and status: All DSpark controls fail red as planted on M5 Max, M5 Ultra, M5 Pro, and M3 Ultra (Metal 3).
  • Backend SUMMARY lines and exit status:
    • M5 Max (6e6d858682, all metal inkling2): SUMMARY 61 kernels: 61 pass gates 1-4, 0 fail, 0 known findings; 65 controls: 65 red as planted, 0 missed; 0 limit problems; gates 10400 ms, limits 23 ms (exit 0).
    • M5 Ultra (8e1661e8c3): SUMMARY 46 kernels: 46 pass gates 1-4, 0 fail, 0 known findings; 51 controls: 51 red as planted, 0 missed; 0 limit problems; gates 10243 ms, limits 391 ms (exit 0).
    • M5 Pro (8e1661e8c3): SUMMARY 46 kernels: 46 pass gates 1-4, 0 fail, 0 known findings; 51 controls: 51 red as planted, 0 missed; 0 limit problems; gates 9995 ms, limits 386 ms (exit 0).
    • M3 Ultra (8e1661e8c3 + symmetric thread overlay): SUMMARY 46 kernels: 46 pass gates 1-4, 0 fail, 0 known findings; 51 controls: 51 red as planted, 0 missed; 0 limit problems; gates 12619 ms, limits 100 ms (exit 0).
  • Chips I could not run: Apple M1/M2/M4 not available directly (M3 Ultra covers pre-M5 Metal 3 TF_SIMD_FRAGS=1 path).

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. If the bits change, the description says which sums change and why.
  • 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.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
Integrate PR ashhart#4699's DSpark kernel, weight-packing, online-softmax multi-stream
attention, batched GPU chain sampling, host SIMD draw, and shared depth pricing
optimizations cleanly onto ashhart#4465 (03bb79e):
- Transpose folded phi ([256, 201024]) and load-time split/transposed RNN
  weights (rnn_kappa, rnn_rec) for coalesced GPU loads.
- Replace score-buffer DSpark attention with zero-scratch 768-thread online
  softmax with M5 tensor-unit and TF_SIMD_FRAGS=1 pre-M5 paths, plus tiled
  base and two-stage group softmax/argmax logits.
- Wire batched multi-stream absorb/hold, chances with softmax reach, two-pass
  GPU top-k sampling, host SIMD top-k/greedy draws, and shared-batch target
  pricing while preserving ashhart#4465 invariants (DSP_SCALE, FP32 kappa,
  plain_guard = false, dspark.warm/measure, and firstLogprobRow).

Refs ashhart#4652
@gilby
gilby force-pushed the inkling2-lead-dspark-batched-gqa branch from 8d3589f to 54da692 Compare November 23, 2026 06:15
@gilby gilby changed the title inkling2: optimize DSpark kernels, two-pass sampling, and priced warm depths inkling2: rebase DSpark overhaul onto #4465 Nov 23, 2026
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 3 times, most recently from aefb063 to c41911e Compare November 24, 2026 09:43
@ashhart
ashhart deleted the branch ashhart:lead/inkling2-mini November 24, 2026 09:43
@ashhart ashhart closed this Nov 24, 2026
@ashhart ashhart reopened this Nov 24, 2026
@ashhart
ashhart changed the base branch from lead/inkling2-mini to main November 24, 2026 09:48
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Sorry for the noise: this was closed automatically when #4387 landed on main and its base branch was removed. It is reopened and now targets main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

5060 Ti (sm_120) kernel-contract inkling2 on head 7e100f9 — built off-card on aarch64 Spark (nvcc 13.0, zig baseline aarch64).

  • 53/53 kernels pass gates 1–4
  • 36/36 planted controls red, 0 missed
  • 11 limit problems, all the same class: this PR's new inkling2_loop_math kernels (tf_ink2_loop_ar, tf_ink2_loop_messages, tf_ink2_loop_gate, tf_ink2_loop_project_qkv, tf_ink2_loop_round_bf16, et al.) launch within driver limits but their sm_120 records read 0,0 placeholders (e.g. tf_ink2_loop_project_qkv: 42 regs, 2048 B shared vs recorded 0, 0)

rc=1 is the limit-problem exit; no gate or control failures on sm_120.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. All eleven chain changes are included; two earlier drafter fixes are already on main. The remaining overhaul keeps proposals behind target verification, replaces the growing scratch pool with charged fixed buffers, and removes the chain probes with unstable addresses.

This is ready for exact comparison on an integrated tree using the pinned Mini checkpoint, on M3 Ultra and M5 Ultra. The reported longer-prompt failure concerns acceptance coverage on a different overlay; please distinguish that from token parity and retain meaningful accepted-draft, rollback and cache checks. The overlay speed results do not yet qualify this change against current main.

  • Synthena

sethforprivacy and others added 11 commits November 25, 2026 02:27
…s; contract pins for the base and attention kernels
…s streams, and one in all when they are greedy
…window costs and a hold timed at load, up to the whole block
…e step against the recurrent kernel and the pick against a scan
Integrate PR ashhart#4699's DSpark kernel, weight-packing, online-softmax multi-stream
attention, batched GPU chain sampling, host SIMD draw, and shared depth pricing
optimizations cleanly onto ashhart#4465 (03bb79e):
- Transpose folded phi ([256, 201024]) and load-time split/transposed RNN
  weights (rnn_kappa, rnn_rec) for coalesced GPU loads.
- Replace score-buffer DSpark attention with zero-scratch 768-thread online
  softmax with M5 tensor-unit and TF_SIMD_FRAGS=1 pre-M5 paths, plus tiled
  base and two-stage group softmax/argmax logits.
- Wire batched multi-stream absorb/hold, chances with softmax reach, two-pass
  GPU top-k sampling, host SIMD top-k/greedy draws, and shared-batch target
  pricing while preserving ashhart#4465 invariants (DSP_SCALE, FP32 kappa,
  plain_guard = false, dspark.warm/measure, and firstLogprobRow).

Refs ashhart#4652
@gilby
gilby force-pushed the inkling2-lead-dspark-batched-gqa branch from 7e100f9 to 6e6d858 Compare November 25, 2026 01:33
@gilby

gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current main (3795e6054c -> 6e6d858682, 18 files, 0 errors in tools/pr_check.py --pr 4699, lean 165 vs 165, 0 new) with the full integrated 3-Mac receipt updated in the PR description.

Summary of key points addressing the review feedback:

  • \u70d2×24 report on the earlier overlay: main uses prompt_rows = 64 in zig/src/families/inkling2/metal/state.zig (prompt(64, 3)), whereas that earlier overlay changed prompt_rows to 256. On integrated main, real-checkpoint test-inkling2-metal-host passes 85/85 (0 skipped, 0 failed) on M5 Ultra, M5 Pro, and M3 Ultra (with 6e6d858682 also passing 177/187 host/M5 Max tests and 61/61 contract kernels / 65/65 red controls / 0 limits).
  • Exact parity across all 3 Macs (A1/B1/B2/A2 + plain_base/plain_4699, Inkling-2-Mini ed40e7da): 60/60 exact token_sha256 + output_sha256 on M5 Ultra, 60/60 on M3 Ultra (evaluated with a symmetric 2-line thread qualifier overlay on pre-existing prompt_attention.metal lines 11 and 15 for Metal 3), and 40/40 on M5 Pro; conc == alone (0 failed/unequal), conc == serial (0 unequal), and multi-turn warm /v1/chat/completions (512/544 cached tokens) equals cold 100% across all 3 Macs with positive accepted drafts.
  • Integrated A-B-B-A throughput highlights (tok/s aggregate, B=(B1+B2)/2 vs A=(A1+A2)/2 base drafted and plain):
    • M5 Ultra 512 GiB: code T=0 c=1 27.05 vs 22.9 / 16.2 (1.18x / 1.67x); chat T=0 c=1 23.60 vs 20.5 / 16.15 (1.15x / 1.46x); c=4 28.40–30.70 vs 14.3–19.55 (1.47x–2.05x over base drafted, matching plain 28.65–29.35). On chat T=1.0 c=1, repr seed=1234 throttled speculative depth via chances after early misses (15.90 avg, 24/52), while serial seeds 1235/1236/1237 ran 19.7/21.0/21.5 tok/s (98/172, 111/178, 114/173) vs base 17.8/19.8/19.6 tok/s.
    • M3 Ultra 512 GiB (Metal 3, TF_SIMD_FRAGS=1): code T=0 c=1 18.10 vs 15.8 / 12.0 (1.15x / 1.51x); chat T=0 c=1 16.35 vs 15.0 / 11.95 (1.09x / 1.37x); c=4 19.50–20.15 vs 8.20–11.65 (1.67x–2.44x over base drafted, matching plain 19.5–19.95).
    • M5 Pro 64 GiB: code T=0 c=1 16.80 vs 13.3 / 13.1 (1.26x / 1.28x); chat T=0 c=1 15.30 vs 11.9 / 13.15 (1.29x / 1.16x); c=4 19.60–20.30 vs 7.20–10.00 (1.96x–2.82x over base drafted, matching plain 19.6–20.35).

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked 6e6d858682 on a clean trial merge into 4c79cfe346. The first stop was tf-kernel-contract: there is an extra closing brace immediately after the specialized DSpark block in zig/tests/contract/metal_limits.zig, present in the PR head as well. The compiler reports expected type expression, found '{' on the following generic Inkling branch.

The unchanged host/capability suites passed 151 tests with ten skips. Removing just the extra brace in scratch let all 74 build steps succeed. On M5 Max the device filter then passed all 61 kernels, caught all 65 planted controls, and reported zero limit problems.

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

Igor Lessio - AIFLOW LABS

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.

5 participants