Skip to content

inkling2 metal dspark: 2-bit screened head, 4-bit NAX draft layers, and single-CB GPU sampling - #4748

Open
cwschroeder wants to merge 32 commits into
ashhart:mainfrom
cwschroeder:pr/inkling2-dspark-q2-screen
Open

cwschroeder wants to merge 32 commits into
ashhart:mainfrom
cwschroeder:pr/inkling2-dspark-q2-screen

Conversation

@cwschroeder

@cwschroeder cwschroeder commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Stacked on #4699 (04da51f7d, over lead/inkling2-mini 3e0e9bcb8). Keeps target verification 100% lossless (all target token IDs and hashes unchanged, greedy and sampled):

  1. 2-bit NAX screened unembed + exact BF16 candidate refinement (tf_ink2_dspark_q2_pack, tf_ink2_dspark_q2_proj, tf_ink2_dspark_q2_proj_units, tf_ink2_dspark_q2_screen, tf_ink2_dspark_q2_refine, tf_ink2_dspark_q2_pick):
    • Packs the 200,058-row unembed matrix to 2-bit per-64 affine codes once at load, screens all 200,058 tokens via M5 NAX tensor units (half2 IEEE-754 mantissa-bias 0x6400 unpack, 8 KiB TG scratch), and refines the top-256 candidates against exact BF16 weights.
  2. 4-bit NAX DSpark draft layers (tf_ink2_dspark_q4_pack, tf_ink2_dspark_q4_units) + bit-exact dense2/dense3 fusion:
    • Packs the 3 DSpark draft transformer layers from 495 MB BF16 to 139 MB 4-bit per-64 affine weights at load and evaluates 8-row QKV / Gate+Up / O / Down projections via M5 NAX tensor units (half2 mantissa-bias unpack, 1/2/3-way fused output split, 8 KiB TG scratch), cutting draft layer time 3.16x while preserving acceptance.
    • Fuses BF16 fallback dense2/dense3 projections via dense_units.encode6 (21 -> 12 dispatches).
  3. Single-CB GPU sampling for temperature > 0 (tf_ink2_dspark_q2_sample, 15.6 us/step):
    • Runs SplitMix64 Gumbel-Max bitonic sort with exact top_k / top_p / min_p filtering over the 256 refined BF16 candidates directly on GPU, so all streams <= 16 (both greedy and temperature > 0) execute in a single Metal command buffer (dspark_hold = 1.70 ms at temp=1.0).
  4. Full Gates 1-4 contract probes, red controls, and Metal launch records (metal_inkling2_dspark_screen.zig, metal_inkling2_dspark_screen_controls.zig, inkling2_dspark_chain_metal_records.zig, inkling2_units_metal_records.zig, inkling2_dspark_metal_records.zig, dspark_kernels_test.zig).

Checks on this head (6125120ed)

  • zig fmt --check build.zig zig: PASS (Zig 0.17.0)
  • tools/zig/lean_check.py vs 04da51f7d: 167 vs 167, 0 new (all modified/added files <= 600 lines)
  • tools/pr_check.py --base origin/lead/inkling2-mini: 0 errors (1 advisory warning for --pr NUMBER)
  • zig build native -Doptimize=Debug: PASS
  • zig build test-inkling2-controls-host test-inkling2-metal-host test-metal-launch-map-host test-inkling2-launch-map-host: PASS (1237 registered launches, 2 controls, 0 missing)
  • GPU contract suite on Apple M5 Max (applegpu_g17, tensor units true):
    • tf-kernel-contract --only "inkling2 dspark": 20/20 kernels pass Gates 1-4, 20/20 controls red as planted, 0 limit problems
    • tf-kernel-contract --only "inkling2 units": 6/6 kernels pass Gates 1-4, 6/6 controls red as planted, 0 limit problems

Receipt

@cwschroeder cwschroeder changed the title inkling2 metal dspark: 2-bit NAX screened greedy head with exact BF16 candidate refinement inkling2 metal dspark: 2-bit screened head, 4-bit NAX draft layers, and single-CB GPU sampling Nov 23, 2026
@cwschroeder
cwschroeder marked this pull request as ready for review November 23, 2026 16:53
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @cwschroeder. I found one bug in the Q2 screen and two gaps in its tests.

The shortlist starts each slot at -inf with ID 0, so a candidate scored -inf or NaN can never take a slot. If a partition holding IDs 4 to 7 scores [0, -inf, -inf, -inf], the screen returns [4, 0] instead of [4, 5]. Starting the IDs at an invalid value in both reductions would fix it, as long as every slot still ends up with a real ID.

Seven of the non-finite probes (q2_pack, q4_pack, q2_proj, q2_proj_units, q4_units, q2_screen, q2_refine) still run on finite inputs, so that gate passes without testing them. Could you plant NaN and both infinities in each? The Q2 screen check also reads 256 candidates but only asserts four. Please check every partition against a reference, with a control that breaks the Phi term.

The conflicts with main, the duplicate loader commit and the missing changelog credit all come from the base branch, so those are on us and you do not need to touch them. This review covers only these defects and is not a decision on the low-bit draft head, which is still open.

  • Synthena

@ashhart
ashhart force-pushed the lead/inkling2-mini branch 4 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

@cwschroeder
cwschroeder force-pushed the pr/inkling2-dspark-q2-screen branch 2 times, most recently from eaab893 to 7f311b9 Compare November 24, 2026 10:16
sethforprivacy and others added 14 commits November 24, 2026 12:06
…t attention, and use mv_mma for prompt dense projections
Replace the scalar stride-2304 tf_inkling2_logits kernel with a 256-thread (8-simdgroup) batched implementation where each simdgroup computes one vocab row across up to 8 token rows, sharing coalesced bfloat4 unembed loads and preserving width-invariant FP32 reduction and BF16 softcap rounding. Update glue dispatch, contract limits record, host check, and 8x8 tile/interval contract tests.
gilby and others added 18 commits November 24, 2026 12:06
…size prompt part_o by capacity, and widen glue/loop scratch to 512
…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
…nd launch records for Q2/Q4 screen and sample kernels
@cwschroeder
cwschroeder force-pushed the pr/inkling2-dspark-q2-screen branch from 7f311b9 to c3dcf8e Compare November 24, 2026 11:06
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for rebasing this onto main, @cwschroeder. We went through the new head commit by commit.

It still carries the earlier Inkling Metal stack underneath your work, including commits that change the order FP32 dot products are summed in (the lane-strided sum and the simdgroup router, loop-gate and grouped-expert dots). TensorFold keeps every output bit equal to the serial reference, by default and behind a switch, so those commits cannot land, and the PR is held until the stack is rebuilt without them. Where your own commits reshape a reduction, the same applies; where they only reorder work, scheduling or launches, they can be reviewed once they sit on a base without those changes.

An exact version of the faster router and gate dots, one thread per output in the original summation order, is something we are looking at on our side. Nothing is needed from you right now; we will follow up here.

  • Synthena

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.

4 participants