Skip to content

inkling2 metal: enable DSpark prompt cache, widen prefill chunks to 1024, and warm verify window costs - #4459

Closed
gilby wants to merge 15 commits into
ashhart:mainfrom
gilby:inkling2-metal-dspark-cache-4337
Closed

gilby wants to merge 15 commits into
ashhart:mainfrom
gilby:inkling2-metal-dspark-cache-4337

Conversation

@gilby

@gilby gilby commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What this changes

Before: on #4337 (8d54cafcd4), --prompt-cache-gib > 0 was refused whenever DSpark drafting was enabled, max_rows was capped at 512 (limiting average tokens/expert during grouped MoE prefill), and Target.facts() left window_costs empty (causing lanes/depth to bypass bestRows() and lock chat draft depth to 1). After: adds LaneSnapshot save/restore in metal_draft_core.zig / metal_draft.zig so --prompt-cache-gib works bit-identically with DSpark enabled, widens max_rows to 1024, adds Target.warm() (inkling2_warm.zig) to populate real Metal verify costs for widths 1..window_rows, and includes the fixed_draft_block lone-stream cost fix from #4457.

Checks on this head

Receipt

  • Main against branch (vs Metal: experimental Inkling 2 Mini text, vision and bundled DSpark #4337 8d54cafcd4 on thinkingmachines/Inkling-2-Mini ed40e7da625f594fc9c4990f5f66be24873c22d7, T=0.0):
    • Warm 8K prompt-cache hit with DSpark ON (--prompt-cache-gib 16, Apple M5 Ultra 512 GiB):
      • cold_8k: TTFT 3,773.6 ms (token_sha256 = ef3c3025356dc777, len=163)
      • warm_8k: TTFT 1,140.4 ms (3.31x faster TTFT, token_sha256 = ef3c3025356dc777, 100% bit-identical)
      • warm_8k_new (shared 8K prefix + new question): TTFT 1,165.1 ms (3.24x faster TTFT)
    • 20.8K cold prefill (max_rows = 1024, --prompt-cache-gib 0):
      • Apple M5 Ultra 512 GiB: 2,575.4 tok/s (up from 387 tok/s baseline and 1,880 tok/s at max_rows = 512)
      • Apple M5 Pro 64 GiB: 840.7 tok/s (up from 101 tok/s baseline and 615.6 tok/s at max_rows = 512)
      • Apple M3 Ultra 512 GiB: 1,257.5 tok/s (10.4K) / 1,222.5 tok/s (20.5K)
    • DSpark c=1 decode with Target.warm() window_costs:
      • Apple M5 Ultra 512 GiB: fibonacci-raw 52.3 → 80.15 tok/s (tpc=2.84), gpu-chat 46.4 → 54.93 tok/s (tpc=2.10), prefill-continuation 93.1–108.7 tok/s
      • Apple M5 Pro 64 GiB: fibonacci-raw 24.1 → 40.30 tok/s, gpu-chat 24.1 → 29.89 tok/s
      • Apple M3 Ultra 512 GiB: fibonacci-raw 58.41 tok/s, gpu-chat 41.73 tok/s
  • Boxes it reaches: inkling2 native Metal backend, DSpark lane snapshot/restore, Target.warm(), and lanes/depth.zig.
  • New switch? No (unlocks existing --prompt-cache-gib with DSpark enabled).
  • Environment: Base #4458 (8b29cbedfb), head bf46d5b75b, Zig 0.17.0, Xcode Metal 4.0 toolchain, Apple M5 Ultra 512 GiB / M5 Pro 64 GiB (macOS 27.2.1) & M3 Ultra 512 GiB (macOS 26.6.2), thinkingmachines/Inkling-2-Mini ed40e7da625f594fc9c4990f5f66be24873c22d7 with bundled mtp.safetensors.
  • Paths and platforms the change reaches: Metal inkling2 native serving (plain, DSpark, and DSpark + prompt cache) across M5 Ultra, M5 Pro, and M3 Ultra; M1/M2/M4 not run on hardware.
  • Exactness (T=0.0, token_sha256 on Apple M5 Ultra 512 GiB):
    • p15: plain = a5077f27220d93ba == dspark = a5077f27220d93ba == dspark_pc = a5077f27220d93ba
    • p33: plain = 114eb7bb615a3609 == dspark = 114eb7bb615a3609 == dspark_pc = 114eb7bb615a3609
    • p184: plain = da48844b05981221 == dspark = da48844b05981221 == dspark_pc = da48844b05981221 == p184_warm = da48844b05981221
    • cold_8k == warm_8k (--prompt-cache-gib 16, DSpark ON): ef3c3025356dc777 == ef3c3025356dc777
  • Main against this branch: Same-machine numbers posted above.
  • Decode speed before and after: Posted above from tools/bench_openai.py (--tokens 256 --reps 3 --temperatures 0).
  • Prompt speed before and after: Cold unique-salt sweep (512/2048/8192/16384, --prompt-cache-gib 0) and cold vs warm 8K prompt-cache TTFT posted above.
  • 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.

BlivionIaG and others added 15 commits November 21, 2026 09:49
- Preserve the original release NVFP4 and MXFP8 expert weights and execute the looped text backbone on one Metal device.
- Keep the bundled DSpark head and plain prompt-cache reuse in the native lane backend.
- Refs ashhart#4274. Local M4 Pro evaluation, separate from the upstream full port.
- Keep the original vision tower, PNG/JPEG preparation, and the separate device and operator checks on the full integration branch.
- The padded-image real-weight accuracy gate remains open. This commit is not part of the text-only review branch.
- Match pinned Transformers eager QK and scaling boundaries before FP32 softmax.
- Keep the trained padded-image projector bound unchanged.
- Keep original NVFP4/MXFP8 checkpoint bytes and decode weights in registers, using BF16 activations and FP32 sums.
- Match pinned Transformers conversion and SwiGLU/route precision, with packed-weight and zero-scale controls.
- Refs ashhart#4274. Local original-weight M4 Pro qualification; not an upstream submission.
- Keep the shader and probe comments within the repository lean rules; no arithmetic changes.
- The rebase dropped the alias main uses for slide refusal, so the native server did not compile.
…-ups

- Comments are one line each again (339 runs collapsed, 40 shortened) and no `/*` text remains, so lean_check.py adds nothing to the base's 168 problems.
- TF_INKLING2_MINI_SMOKE reads through platform/environment.zig: a .metal/.path row, a docs row and a valid case in environment_test.zig.
- The load check sums every model*.safetensors shard, as core/checkpoint.zig lists them, plus mtp.safetensors when drafted.
- The state-bytes test covers Mini's looped shape: 24 physical layers as 48 visits, 8 global, visit 41 at physical 17.
- A new contract control isolates the experts' down projections; --loops and --policy refusals have a test that names them.
- The cacheBudget doc comment and the CHANGELOG state the DSpark prompt-cache limit: kept states need --no-drafts.
- The Inkling 2 contract suites move to metal_inkling2_main.zig, holding their probes for the run, which keeps metal_main.zig under 600 lines.
- The NVFP4 outer factor stays the unrounded quotient, pending the maintainer's F1 decision.
…ites

- `zig fmt --check build.zig zig` (what the Zig format workflow runs) is clean; the new suites and loaders had drifted.
- Layout and `@intFromEnum` -> `@backingInt` only: the contract, native, vision, forward and environment checks are rerun green on this tree.
…w projections

- Score GEMMs are a full fp32 dot, off the tensor-unit operand cut, so an M5 matches the product measured on earlier chips.
- One-row projections that share an input use one launch of the existing matvec lane chains. Same checkpoint token hash, about 2 ms off a 57 ms decode token.
- zig fmt on the forward layer, and the score-GEMM note is one line so lean check stays at the base count.
- Drop the blank lines zig fmt --check rejected on the projection fuse.
- f32_nt and f32_nn were filled from bf16 dyadics, so a 10-bit operand cut still matched the float64 product.
- Wide inputs now set the low fraction bits. On this M4 Pro the gates pass at 0.337 and 0.354 of the bound.
- Gate-down walked all 64 ranks in one threadgroup. Eight ranks a group, each rank's sum order unchanged.
- Decode on this M4 Pro is 23.2 tok/s, from 16.9, hash 57519a5a167f unchanged.
- Prefill chunks are 512 rows. A 1056-token prompt prefilled at 81 tok/s.
@gilby

gilby commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing as obsolete (#4337-based branch targeting main): its prompt-cache, 1,024-row prefill, and DSpark window-cost goals are already covered on lead/inkling2-mini by #4542/#4607, #4644, #4465, and #4699.

@gilby gilby closed this Nov 23, 2026
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.

Inkling 2 Mini Metal (#4337): prefill/decode kernel speedups, DSpark prompt cache, and fixed-block depth costing

2 participants