Skip to content

Inkling-2-Small: Add DSpark drafter kernels - #4128

Open
ajensenwaud wants to merge 29 commits into
ashhart:mainfrom
ajensenwaud:ink-k-dspark
Open

ajensenwaud wants to merge 29 commits into
ashhart:mainfrom
ajensenwaud:ink-k-dspark

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds the kernels of the DSpark drafter that ships with Inkling 2 Small, their launcher, and their registration with the kernel contract. The pick kernel is now one template shared with MiniMax M3, SiLU runs on a new mode of core's tf_swiglu_rows, and main's common-helper check now catches camelCase copies. Nothing serves them until the family PR at the top of the stack.

Checks on this head

  • Head 4227682b6; lean checker 165 on the base, 165 on this head, 0 new.
  • zig build test-cuda-host test-inkling2-cuda-host test-inkling2-host test-gradient-serving compile-cuda-tests test-exl3-cuda-host test-minimax-cuda-host test-omni-video-host test-qwen27-equality-host test-qwen27-plans-host test-glm-exl3-prompt-host -Dfixed-cpu: 9,077 of 9,128 tests, 51 skipped, on 4227682b6 (main 141d6995a), every run step from a fresh cache. Two timing tests outside this PR (pull_proxy's stall resumes, pdf_worker's crash report) failed once while another build shared the host and passed on rerun.
  • zig fmt --check build.zig zig and git diff --check: clean. CI: pending.

Receipt

n/a: no served path reaches these kernels yet.

Kernel contract
  • Registered: the nine kernels in dspark.cu and core's tf_swiglu_rows_expf. MiniMax M3's pick kernel and the existing act_rows kernels compile to the same SASS on nvcc 13.0 and 13.3.
  • GB10 (sm_121), 24 November, on this head: kernel-contract inkling2 gives SUMMARY 53 kernels: 53 pass gates 1-4, 0 fail, 0 known findings; 32 controls: 32 red as planted, 0 missed; 0 limit problems.
  • The shared kernels this stack changes pass under their own filters too. exl3, act, vit and minimax show the same limit problems on the head as on main, and no failure that main does not show.
  • Gate 5: records for nvcc 13.0 and 13.3 on sm_80, 86, 89, 120 and 121; 13.2 stays pending.

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

@ajensenwaud @ashhart I checked the DSpark stage at 54a82f8ae, with the exact #4127 head as its parent. On Linux x86-64, Zig 0.17.0, zig build test-inkling2-cuda-host test-gradient-serving compile-cuda-tests -Dfixed-cpu --summary all passed 18 build steps and all 21 tests. That is the smaller rerun to record next to this head.

The conflicts against 1ece6e6db are in the changelog and the same kernel-source checksum row as #4127. The pin changes again at this stage. With main's changelog and the regenerated checksum (d64559b51e3ee4eadcdefb7dcc5811f69c5d449fbe16a57fcd677c41660c27eb), the two host targets passed all 21 tests on M5 Max. The compiled test binary still needs the DSpark device run.

On the rebased head e7d4e4452, the trial merge into 37fa51d23 was clean. On M5 Max with Zig 0.17.0, zig build test-inkling2-cuda-host test-gradient-serving -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all passed all 21 host tests, including the new checksum fixture. The stacked expert and vision stage has the same source tree as the current #4127 head.

Igor Lessio - AIFLOW LABS

ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 21, 2026
@ajensenwaud ajensenwaud changed the title Inkling 2's DSpark drafter kernels under the contract Inkling-2-Small: Add DSpark drafter kernels Nov 21, 2026
@jschmied

Copy link
Copy Markdown
Contributor

Shared-core review of what this PR adds over #4127, at e7d4e44529 against main fa13df5dd1. I read code only, no build and no GPU. Mini's drafter slice (C5 in #4274) builds on these kernels.

Copies of core code

  1. Reduction helpers: kernels/cuda/inkling2/dspark.cu:19 warpSum, :25 blockSum and :13-17 bf/tobf/bfr repeat common/reduce.cuh:12,25 (warp_sum, block_sum_tree) and common/glue_math.cuh:11-12 in the same order.
    • The camelCase names slip past tools/zig/cuda_common_check.py:14, whose regex matches only warp_sum and block_sum\w*. So the check passes, but this file doesn't use the common helpers yet.
    • Fix: include the two headers and widen the regex.
  2. Pick merge: dspark.cu:314 tf_ink2_dsp_pick is MiniMax M3's tf_mm3_pick_merge (kernels/cuda/minimax_m3.cu:359): the same rank merge into walk[j+1], lowest id on a tie, 16-byte stride.
    • Fix: one shared DSpark glue kernel used by both families. Metal (M6) can then share the host side too.
  3. SiLU: dspark.cu:233 tf_ink2_dsp_silu is a new SwiGLU. act_rows.cu:25 tf_swiglu_rows uses g·sigmoid(g), which gives different bits. glue_math.cuh:59 tf_silu has this form but uses tf_exp.
    • Fix: a tf_silu mode on tf_swiglu_rows, or one line saying why expf is required.
  4. Add-norm: dspark.cu:60 tf_ink2_dsp_addnorm sits beside minimax_m3.cu:34 and norms.cu:202,279,511. The numerics differ: a bf16 residual and a norm of the unrounded sum. A header line saying why core's version doesn't fit would do.

Correctness

  • Unchecked sizes: the launchers in src/families/inkling2/dspark_ops.zig (rnn :162, vocab :173, ctx :154, qk :114) pass the Markov rank, rows and head_dim unchecked. config.zig parses markov_rank, block_size and head_dim without bounds.
    • A rank above 256 writes past in[512] and raw[768] in shared memory (dspark.cu:273-274).
    • Rank ≠ 256, rows > 8 or head_dim ≠ 128 give wrong results without an error.
    • Fix: refuse these by name (Inkling2DraftShape) in the launchers or in parseMtp, with expectError tests. Inkling2DraftShape (:129) has no test today.
  • Ring aliasing: attend (:125) doesn't check that hi − lo + 1 ≤ ring, so keys could alias in the ring. That is my inference from reading the code; I didn't run it.

Good for Mini: the kernels take gathered tap rows, not layer numbers, so the loop's visit-based taps stay host work in H4/C5. The contract records cover Small at TP=2. C5 adds 4 taps × 2304 at one rank. Every kernel has a planted control.

Nit: five test comment lines in the contract_inkling2_dspark_* files run 122-128 columns.

@jschmied

Copy link
Copy Markdown
Contributor

Device run on a GB10 (sm_121, cc 12.1, driver 615.71.09, nvcc 13.0, -Dsm=121) at e7d4e44529, with main dcc29d9d62 run the same way for comparison. The run confirms the body's numbers on this chip.

Step This head main
test-inkling2-cuda-host test-inkling2-host test-gradient-serving compile-cuda-tests -Dfixed-cpu 21/21 steps, 45 pass, 4 skip 21/21 steps, 35 pass, 4 skip (the same 4)
install -Dnvcc -Dsm=121 210/210 207/207
tf-cuda-test kernel-contract inkling2 SUMMARY 55 kernels: 55 pass gates 1-4, 0 fail, 0 known findings; 35 controls: 35 red as planted, 0 missed; 0 limit problems 36 kernels pass, 18/18 controls red
  • New controls: all 17 this stack adds (7 for experts and vision, 10 for DSpark) go red.
  • Bit equality: tf_ink2x_group, _rows and _wide are bit-equal to the EXL3 kernels they stand in for on 9, 21 and 13 shapes. The five-run repeats are byte-identical.
  • sm_121: no inkling2 compile warnings, and no shared-memory or limit issues.

The shared-core points above still stand; this run only covers correctness on sm_121.

@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks @ajensenwaud for putting together the Inkling 2 Small DSpark drafter kernels and full kernel-contract coverage!

Everything in the DSpark slice reads clean and solid: all ten kernels in dspark.cu, the launcher in dspark_ops.zig, the Gate 5 records, and the 12 registrations with 10 planted controls match their float64 references and bounds, stay well within the 600-line file limit and 48 KiB shared-memory budget, and leave target serving untouched. Semantically this PR does not depend on #4127 beyond shared list context, and we will handle the rebase onto current main (including re-pinning zig/src/cuda/kernels.zig in gradient-serving.tsv) ourselves.

Next step on our side is to rebase and run the host checks plus tf-cuda-test kernel-contract inkling2 (Gates 1–5) on our GB10 (sm_121) and RTX 5090 (sm_120).

A few small things to keep in mind (either in a follow-up or while the top-of-stack family PR comes together):

  • Shared CUDA helpers: echoing @jschmied's note, warpSum/blockSum and bf/tobf/bfr in dspark.cu can use common/reduce.cuh and common/glue_math.cuh, and tf_ink2_dsp_pick can be shared with MiniMax M3's rank pick merge (keeping your cleaner 0x7fffffff tie-break initializer).

  • Launcher guards: dspark_ops.ctx and dspark_ops.rnn could validate rows <= 8 and r <= 256 (multiple of 32) to match the hardcoded kMaxRows = 8 and __shared__ sizes in dspark.cu.

  • nvcc 13.2 pending flag: inkling2_dspark_records.zig omits .later_pending = true, so usageFor(..., 13.2) falls back to the 13.0 numbers rather than staying pending like #4127's records.

  • 8-row block vs 7 drafting rows: the walk kernels (walk[j] -> walk[j + 1] with walk[0] as anchor) match DSpark's per-step convention, while the tests pair an 8-row block with 7 Markov rows (block_size = 8 vs 7 drafts); we will double-check the exact row slice (hidden[1..8] vs hidden[0..7]) and pos0 alignment when the family PR wires these kernels up.

  • Synthena

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks, Ash, and thanks @jschmied. Both reviews are answered in 4e3149d49, rebased onto main cc645a54b with kernels.zig re-pinned, so that step is done.

  • Reduction helpers. The DSpark kernels use common's warp_sum. Common's block_sum_tree and the glue bf16 helpers compile to different SASS, so those local forms stay. The check's regex now catches camelCase names, with a test, and the allowlist names each remaining copy with its reason.
  • Pick merge. One shared dspark_pick template in common/ serves both families, keeping Inkling's 0x7fffffff start. Its only parameter is that start id. MiniMax's tf_mm3_pick_merge compiles to the same SASS as before.
  • SiLU. tf_swiglu_rows gained an expf mode, and the family kernel is gone. The existing kernel's SASS is unchanged, and the new mode matches the old kernel instruction for instruction.
  • Add-norm. It stays in the family. Its header now says why: it keeps a bf16 residual and takes the norm of the unrounded sum.
  • Launcher guards. The launchers refuse a Markov rank other than 256, more than 8 rows, a head size other than 128 and a key window longer than the ring, all with Inkling2DraftShape. Each case has an expectError test.
  • Records. Every DSpark record now carries later_pending, with its nvcc 13.3 values in pending_133.zig, so 13.2 stays pending as Inkling-2-Small: Add grouped-expert and vision kernels #4127's records do.
  • Drafting rows. Agreed that the 8-row block against 7 drafted rows belongs to the family PR. I'll check the row slice and pos0 there.
  • Line length. The five test comments are now within 120 columns.

A GB10 run (sm_121) on 430c8f708, whose kernels compile to the same SASS as this head, gives kernel-contract inkling2: 53 kernels pass gates 1-4, 32 controls red as planted, 0 limit problems. The exl3, act, vit and minimax filters show no failure that main lacks.

@jschmied

Copy link
Copy Markdown
Contributor

@ajensenwaud, I checked 4e3149d49 on a GB10 (sm_121, driver 615.71.09, nvcc 13.0, -Dsm=121), with main cc645a54b run the same way. Your numbers hold on this head, and our points are settled.

tf-cuda-test kernel-contract this head main
inkling2 SUMMARY 53 kernels: 53 pass gates 1-4, 0 fail, 0 known findings; 32 controls: 32 red as planted, 0 missed; 0 limit problems 36 pass, 18/18 red
exl3 22 pass, 13/13 red, 7 limit problems 20 pass, 11/11 red, the same 7
act 55 pass, 48/48 red, 2 limit problems 54 pass, the same 2
vit / minimax 21 pass, 1/1 red / 26 pass 19 / 26 pass
  • DSpark coverage: all ten launches are covered, in 12 entries: mix, addnorm ×2, qk ×2, attn + merge, merge, ctx, rnn, vocab, pick_merge and tf_swiglu_rows_expf.
  • 55 → 53 since e7d4e4452: the family's group/rows/wide, attention, scale_add, silu and tf_ink2_gateup are gone. In their place come core's grouped_wide_2, gateup_capped, vision_kernel<64, 8>, pointwise_gamma and swiglu_rows_expf.
  • Host: the same four steps pass 21/21, 53 of 57 tests with 4 skipped, and the install builds 218/218. cuda_common_check.py reports 0 violations, and its unit tests pass (10).
  • SASS (sm_121, the build's flags):
    • Against main, minimax_m3 is 17/17 identical, so tf_mm3_pick_merge is unchanged, and act_rows is 11/11.
    • tf_swiglu_rows_expf runs the same per-element chain as the old tf_ink2_dsp_silu. The kernels differ in shape: 8 columns a thread, plus the row sums.
    • The other eight DSpark kernels compile the same as at e7d4e4452.
  • One note for the family PR:
    • checkHead (dspark_ops.zig:17) is the only refusal of head_dim and block_size, and only its test calls it.
    • config.zig:292-297 still parses those fields without bounds.
    • Calling checkHead at load closes that. Rank and rows are already refused in the launchers.

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 4e3149d49 into main 1eed88bb0. It applies cleanly and already includes #4127 at 85539e278. The Inkling family, CUDA host and serving-pin targets passed 53 tests with four skips.

I then added the Inkling reply parser #4124 at c8f1556b1. Its only conflict was in THIRD_PARTY_NOTICES.md. Keeping the kernel and parser attribution sections resolved it. The combined tree passed the server CPU suite with 1,817 tests and 15 skips, and the Linux x86-64 CUDA test runner compiled. The three smaller host targets also passed on the combined tree.

zig build test-server-cpu test-inkling2-host test-inkling2-cuda-host \
  test-gradient-serving -Dcpu=apple_m1 -j4 --summary all
zig build compile-cuda-tests -Dtarget=x86_64-linux -j4 --summary all

These were host and build checks on M5 Max with Zig 0.17.0. The GB10 kernel results already on the PR cover device execution.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

The new a5a75d69 head trial-merges cleanly into main 25586070b with no local edits. The two new commits have the same patches as the updates in #4127 at d8095191: the Qwen image-row exports and the dense serving pin. The DSpark branch already contains those updates.

On M5 Max with Zig 0.17.0, the Inkling and pin checks passed 53 tests with four skips. The Qwen, serving-pin and residency check passed 275 tests with five skips, covering the roots changed by this rebase. The native CUDA target and Linux ARM64 CUDA runner compiled.

zig build test-inkling2-host test-inkling2-cuda-host test-gradient-serving check-native-cuda-host -Dcpu=apple_m1 -j4 --summary all
zig build test-qwen-serving-host test-metal-residency-owners-host test-qwen27 -Dcpu=apple_m1 -j4 --summary all
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dcpu=baseline -Doptimize=ReleaseSafe -j3 --summary all

The new commits touch four host test or module-root files. The kernel sources are unchanged from the previously checked device head.

Igor Lessio - AIFLOW LABS

plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
… bar to the drafter chain (cards 215, 219)
The family's attention was a copy of prefill_attention.cu's
vision_kernel, so the tower now calls vit.Attention.full at head dim 64,
the instance and record Qwen3-ASR already brought to main.
grouped_body takes the member tiles a program as a template parameter.
tf_exl3_grouped_wide_2 runs 32 members by 64 columns for prompt chunks;
the existing instantiations compile to the same SASS on every SM.
nvcc 13.3 changed tf_exl3_grouped_2's sm_120 and sm_121 SASS when the
wide instance followed it; defined first, every existing kernel compiles
as before under 13.0 and 13.3.
The item plan was limited to mcg and slot rows written to ey. It now
takes every codebook, writes scratch y when ey is 0, picks the wide
kernel for 32-member items and the capped epilogue for act_mode 3.
The family's grouper and grouped projections were copies of core's.
Inkling now runs exl3_experts.runWith on grouped.Router's item plan,
16-member items below 512 rows and the wide kernel from there; outputs
are bit-equal to the kernels this replaces. Expert widths up to 8 bits
are admitted, as core decodes them.
tf_ink2_gateup duplicated core's gate/up epilogue apart from the
softcaps, which core now runs as act_mode 3. Its registration moves to
tf_exl3_gateup_capped, with the swapped-caps control kept.
RADIO, MiniMax M3, Qwen 27 and Inkling 2 each kept their own copy of
the placeholder span and the cut that maps a prompt pass onto it. They
now share core.image_rows, started from RADIO's copy, and each family
keeps only its own splice.

The cut now works in usize and takes the offset before adding the
buffer row, as RADIO's did. MiniMax M3 and Inkling 2 already cut in
usize, so their results are unchanged. RADIO and Qwen 27 no longer
overflow u32 on a span that ends past 2^32; nothing else changes.
Inkling 2's tf_ink2v_scale_add was a layer-scaled residual add, which
is tf_vit_pointwise with a per-column scale between the activation and
the add. vit.cu now has tf_vit_pointwise_gamma for that, and the tower
calls it through vit.Kernels.pointwiseGamma. Its fp32 multiply, bf16
rounding and add are the same round-to-nearest steps the family kernel
took, so the tower's results are unchanged.

Every existing function in vit.cu and inkling2/vision.cu compiles to
the same SASS on sm_80, 86, 89, 120 and 121 under nvcc 13.0 and 13.3.
The contract now registers the core kernel, with the late-gamma control
retargeted to it; its records come from cuobjdump -res-usage, and 13.2
stays pending.
The Metal and residency builds give qwen27 its own core roots, which
lacked image_rows after the shared module moved into core.
Core builds exl3_experts.cu with contraction on, so the soft-capped
SwiGLU's products and sum fused into FMAs, and Inkling 2 Small's tokens
no longer matched the build it was validated on. Explicitly rounded
operations give the SASS the old text has at the glue kernels' flags.
Inkling 2's DSpark SiLU was its own kernel for torch's g / (1 + expf(-g)).
tf_swiglu_rows now takes that form as a template mode, exported as
tf_swiglu_rows_expf, and the drafter calls it. Each element runs the same
instructions as the family kernel did, and tf_swiglu_rows' SASS is
unchanged.
The common-helper check matched only warp_sum and block_sum*, so local
warpSum and blockSum copies passed unseen. It now matches either spelling.
The four Inkling 2 copies it finds are listed with their reasons.
Inkling's pick was MiniMax's merge with a different fallback id, so
both now instantiate one body in common/dspark_pick.cuh. MiniMax's
tf_mm3_pick_merge compiles to the same SASS on every SM under nvcc
13.0 and 13.3. Inkling keeps 0x7fffffff when no value beats -Inf, and
its compare and select chain is unchanged.
Without later_pending a 13.2 build read the DSpark launches against
13.0's numbers. The 13.3 receipts move to pending_133.zig, as the
expert and vision records already do.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks, @ajensenwaud. The launcher guards, shared pick/SiLU operations and pending 13.2 records address the review points. This head contains the reviewed expert/vision stage plus eleven DSpark commits. The load-time head-shape check and the eight-row/seven-draft alignment remain part of the later serving integration.

The kernel slice looks ready for comparison once we've combined the shared changes with current main on our side, after #4127. The remaining evidence is the resolved tree's focused contracts and unchanged arithmetic for existing shared-kernel users. The reported kernel passes do not yet qualify Small serving or replace Mini's separate arithmetic.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

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

Clean pass: 12/12 kernels pass gates 1–4, 10/10 planted controls red, 0 missed, 0 limit problems.

All nine DSpark drafter kernels launch within driver limits and match their sm_120 records exactly: tf_ink2_dsp_attn (256 threads, 46 regs, 48192 B static shared), tf_ink2_dsp_mix/addnorm (512×40), qk (64×24), merge (33), ctx (47), rnn (40 + 5120 B), vocab (15), pick_merge (32 threads vs 1024 allowed, 40 regs). Second sm_120 row this week with zero limit problems — the records carry real sm_120/nvcc-13.0 measurements, not placeholders.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @ajensenwaud. The launcher guards, shared helpers and pending compiler records remain addressed. The exact-head DSpark result on sm_120 adds useful evidence: twelve entries passed, all ten controls were caught, and no limit problems were reported.

The kernel slice is ready for comparison after we combine its DSpark changes with the updated expert and vision stage on current main. The remaining checks cover that resolved tree and unchanged arithmetic for existing shared users. Load-time head validation, tap alignment and final-token verification still belong to the later serving integration.

  • 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.

5 participants