Skip to content

Inkling-2: Add DSpark kernels that draft all streams in one pass - #4858

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

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

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

With several streams, Inkling 2's DSpark drafter runs its draft pass once per stream, because #4128's kernels take
one stream a launch. At eight streams that is about 250 launches a pass. This PR adds kernels that take every stream
in one launch.

What this changes

Each kernel of a draft pass gains a form that walks several streams, and a stream's bits equal those of the
one-stream kernel. The rank merge runs on the shared dspark_pick template. Nothing serves them yet.

Checks on this head

  • Head e860eddc1 on main ea37382cb; lean checker 165 on the base, 165 on this head, 0 new.
  • zig build test-inkling2-host test-inkling2-cuda-host test-gradient-serving test-kernel-symbols-host compile-cuda-tests -Dfixed-cpu: 24 of 24 steps, 59 of 63 tests, 4 skipped.
  • zig fmt --check build.zig zig, git diff --check, cuda_common_check.py and cuda_fragment_check.py: clean.

Receipt

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

Kernel contract
  • Registered: the eight new launches against their one-stream kernels' float64 references, with planted controls.
  • GB10 (sm_121), 23 November, on 8052cef29, which has the same DSpark kernel and contract files as this head: kernel-contract inkling2 gives SUMMARY 62 kernels: 62 pass gates 1-4, 0 fail, 0 known findings; 40 controls: 40 red as planted, 0 missed; 0 limit problems.
  • Inkling-2-Small: Add DSpark drafter kernels #4128's nine kernels compile to the same SASS with and without this commit, on nvcc 13.0 and 13.3 and all five SMs.
  • Gate 5: records for nvcc 13.0 and 13.3 on sm_80, 86, 89, 120 and 121; 13.2 stays pending.
  • On the InkSpark-Mini recipe build (https://github.com/ajensenwaud/inkspark-mini-2dgx, two GB10s, its NVFP4
    drafter weights), the batched pass cut an eight-stream draft pass from 34.4 to 12.6 ms, with identical drafts.

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.
Each kernel of a draft pass gains a form that walks several streams in
one launch: q/k prep, block attention and merge, the Markov head's
context and recurrence, the per-stream pick and the step's vocabulary
and rank merge. A stream's bits equal the one-stream kernels'.
@joshuaswarren

Copy link
Copy Markdown
Contributor

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

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

All of this PR's new all-stream draft kernels launch within driver limits and match their sm_120 records exactly: tf_ink2_dsp_pick_many (1024 threads, 25 regs, 256 B shared), tf_ink2_dsp_vocab_rows (33 regs), tf_ink2_dsp_pick_rows (32 threads vs 1024 allowed, 40 regs). The inkling2_vision additions (tf_ink2v_embed, tf_ink2v_rope) likewise match records.

First sm_120 contract row I've run with zero limit problems — the records were measured for sm_120, not just GB10.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @ajensenwaud. This is the batching layer over #4128, alongside #4127's shared experts; it does not enable Mini serving yet. We can take the narrow final slice onto the integrated work.

Two fixes remain. qkMany omits the existing Q/K ring and row-stride checks, so an input the one-stream launcher refuses can launch an out-of-bounds read. Please retain those refusals and validate the batched windows, layers and partial-buffer capacity too.

The new Q/K, attention, context and recurrence cases also use only one stream. Please add distinct multi-stream tables and nonzero strides, comparing each stream's exact bytes/state with its own one-stream launch, with a planted table/stride fault. The posted totals and resource records are useful, but do not cover those cases yet.

  • Synthena

qkMany now refuses what the one-stream launcher refuses, and both batched
launchers read the host copy of the stream table so a row past the table,
a layer without caches, a window longer than the ring or partials too small
for the chunks are refused before a launch.
Q/K, attention, context and recurrence each run 3 to 6 streams with their
own tables and padded strides, and every stream's bytes must equal its
one-stream launch. Each has a control that feeds the batched launch a wrong
table entry or stride.
@AIFlowML

Copy link
Copy Markdown
Contributor

On 833875fe0b732c7083f236ea7cc3c01a96ebc076, I ran these checks from the PR head on an M5 Max:

zig build test-inkling2-host test-inkling2-cuda-host test-gradient-serving test-kernel-symbols-host -Dfixed-cpu -j2 --summary all
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dfixed-cpu -j2 --summary all

The host run passed 61 tests with four skips, and the aarch64 Linux CUDA contract runner compiled. The new fixtures compare Q/K, attention, context and recurrence bytes per stream against their respective one-stream launches and register separate table/stride controls. The earlier SM120 result covers the earlier head. For the new head, could the next device receipt include those four comparison cases and their four planted controls?

The whole branch has 19 merge conflicts against d1ff890729, consistent with taking the final slice onto the integrated base as Ash suggested. I did not run the device gates.

Igor Lessio - AIFLOW LABS

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks, Ash, and thanks @AIFlowML. Both asks are fixed in 833875fe0, and the device run below covers the four cases and four controls you asked about.

  1. Refusals. qkMany now runs the one-stream checks first, so a missing ring, a row stride narrower than its heads or a missing key head is refused as before. Both batched launchers also check the stream table before a launch. They refuse a row whose stream is not in the table, a layer without caches, a window longer than the ring or wider than the launch allows, and partial buffers too small for all the streams. Two host tests cover 18 refusals.
  2. Multi-stream cases. The Q/K, attention, context and recurrence kernels each have a new case with three to six streams. Every stream has its own caches, window and position, and the row strides are padded. Each stream's bytes, and the recurrence's state, must equal its own one-stream launch exactly. Each case has a planted fault: a row tagged as the next stream's, two streams' key caches swapped, the packed hidden stride, or a walk stride one id short. On a GB10, all four cases pass bit-equal and all four faults go red. Under the inkling2 exl3 vit act minimax filter, the head adds no failure that your Inkling-2-Small: Add grouped-expert and vision kernels #4127 head does not already show.

No kernel changed, so the existing records stand.

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