Repository navigation
Inkling 2: prefill kernels — tensor-core bias, per-head flash attention, fused norms, gates and gate_up epilogue (3/4, stacked on 2/4) - #432
Conversation
…(ATLAS_SKINNY_MMA) Inkling's verify rows keep the decode row's arithmetic so text with drafts is the text without. For the Spark NVFP4 projections and head that meant the scalar batch GEMV tiers, which repeat the one-row kernel's FMA chain and are issue-bound: at eight verify rows they read Inkling's [3072 x 2304] projections at about 90 GB/s, and they were about 14 ms of a 68 ms drafted step on one GB10. ATLAS_SKINNY_MMA's kernels compute a row the same way at every width, so decode and verify stay exact twins on the tensor cores: - skinny_mma.cu moves from the qwen3.6-27b overlay to gb10/common, so every GB10 target (Inkling 2 Mini's included) ships it; the lever stays off unless set. - Under the lever Inkling's one-row fused projection kernel (inkling2_proj_gemv_mixed, the scalar arithmetic) is not used, so a decode row takes the skinny kernels as a verify row does. - An exact verify's NVFP4 projections and the verify head go to the skinny kernels in one call (up to 128 rows) instead of 15- and 16-row passes that read the weight again. - skinny_mma_microtest covers Inkling's shapes and runs on its kernel set. Observed on one GB10, dev build, Spark weights, DFlash2 drafter, voice engines resident, preliminary, single runs: skinny_mma_microtest passes at Inkling's shapes (rows byte-identical at 1..128, error against FP64 no worse than w4a16_gemv). Greedy text for 8 prompts x 320 tokens with drafts at one, four and eight requests, and plain at eight, identical to drafts off one at a time. A drafted step at one request 68.5 -> 54.6 ms; RigMark short code C1/C2/C4/C8 aggregate 65.8 / 73.9 / 108.7 / 149.1 tok/s with the lever (release 0.5.0, voice suspended: 58.7 / 77.6 / 103.0 / 136.0). Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 19f3e27)
…move skinny_mma_microtest's shape table moves to skinny_mma_microtest_parts/ shapes.rs and GlueKernels::window_meta to glue/route.rs beside kv_write; code moved as is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-residual passes, ldmatrix W4A4 tile A 32K-token cold prefill on one GB10 (Spark weights, 4,096-token chunks, nsys, 2026-11-26, preliminary single runs): TTFT 9.56 s -> 7.79 s with ATLAS_BF16_GEMM_CUTLASS=1 (7.42 s at 8,192-token chunks). - inkling2_flash_prefill: the relative bias BF16(rel . rel_proj) is a rank-16 product of BF16 values, so per key tile a warp computes its 16 rows x 47 distances on the tensor cores (6 m16n8k16 MMAs), stages them in its shared memory and reads them back along the diagonals. The scalar sum (16 multiply-adds a score) held the sliding-window visits, biased in every tile, to ~14 TFLOPS against ~48 for the full ones: attention 2.40 s -> 1.53 s. Only the bias's summation order changes. The kernel also applies the output gate in its epilogue (inkling2_gate_mul's arithmetic) and no longer spills. - Message gates (prefill): inkling2_block_res_row writes each output row's sum of squares, so the fused gate reads its rows twice instead of three times, and each step's global loads now overlap the step before (one barrier a step): 1.08 s -> 0.73 s. - inkling2_block_res_row: 8 channels a thread (H / 8 threads), each state loaded once with 16-byte loads and held in registers for both passes: 0.78 s -> 0.58 s. - nvfp4_w4a4_tile.cuh (Inkling and Qwen3.8 Flash-Next experts): A and B fragments by ldmatrix.x4, one instruction for four 4-byte loads; same operands, bit-identical outputs; ~2% (the tile is still bound by its shared-memory pipe, 31% tensor utilization). - The per-head kernel's bias table is cut to the 63 rows it serves (it was sized for a whole chunk: 201 MB at 4,096 rows). Prefill numerics: prompt logprobs of 56 calibration documents and seven 8K-token prompts move against the previous build by as much as changing the chunk size moves them (8K prompts: KL(top-5) 0.002-0.008 for both); mean next-token NLL 1.1683 (previous, 4,096 chunks), 1.1676 (previous, 2,048), 1.1678 (this). Decode and verify rows keep their kernels. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit dd80b21)
- inkling2_block_res_row norms its outputs (inkling2_rmsnorm's formula) on a prefill chunk's visits no message gate rewrites: the attention inputs and the MLP input leave as BF16 normed rows and the fp32 mix is never written and read back. Decode and verify rows keep their kernels, so text with drafts is still the text without (greedy, 8/8 prompts at 1, 4, 8 requests). - The post-attention and post-MLP short convs add their BF16 output straight into the residual stream (inkling2_residual / inkling2_layer_out's arithmetic, bit-identical); those two kernels and their buffers are gone. Preliminary, single runs on one GB10 (Spark weights, CUTLASS BF16 GEMMs): 32K cold prefill TTFT (nsys) 7.79 -> 7.52 s at 4,096-token chunks, 7.12 s at 8,192. Prompt logprobs move against the previous build within the chunk-size noise floor (mean NLL 1.1659 vs 1.1676-1.1683). (cherry picked from commit 2212872; the ATLAS_PREFILL_BUSY_TOKENS chunk cap it also added is left out: the next change in this series makes it unnecessary and removed it.) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r BF16 states On a prefill chunk's gated visits the message block residual no longer writes its four fp32 message planes: inkling2_block_res_row stores each row's mix weights (p_out, 144 bytes a row) and the messages' sums of squares, and gb10's inkling2_msg_gate_fused rebuilds every message it needs from the message stack's BF16 states with those weights, in the mix's own operation order, so each value is the fp32 message bit for bit. All of a launch's gates now share one read of the states (and of h when they share it) a step; the kernel moves to dynamic shared memory (78.7 KB). The AMD WMMA port keeps reading the fp32 messages. The fused gate now runs on prefill chunks only (it also took plain decode batches of 16 rows or more, whose text then depended on the batch size). Preliminary, one GB10, 32K-token cold prefill at 4,096-token chunks (nsys): TTFT 7.52 -> 7.32 s (gates 726 -> 671 ms, block residuals 542 -> 414 ms). Prompt logprobs bit-identical to the previous build on 56K positions; greedy text with drafts equals text without at 1, 4 and 8 requests. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 3a1a6ba)
inkling2_flash_prefill took one KV head and 64 query rows per CTA: 12 warps for the group's 3 query heads, 32-key tiles, 168 registers, one CTA an SM. Sliding-window visits ran at about 31 TFLOP/s. The kernel now follows the layout of knapcio/Inkling-2-Mini-1x-DGX-Spark's inkling_attn (MIT), with our numerics and gated epilogue: - one query head a CTA, 4 warps, two CTAs an SM; heads fastest in the grid, so the group's query heads read a KV tile from L2; - 64-key tiles, newest first, K and V in single buffers that alternate (V loads under QK^T, the next K under PV), rows XOR-swizzled for ldmatrix.x4; - the bias tile staged as BF16, read two at a time from parity-shifted rows, added in one loop; masks in a second loop, only on tiles at the diagonal or the window's edge; - exp2.approx.ftz, -inf masks, scale plus bias as one fma; - keys located by shifts (block sizes are powers of two, now checked); - rel_proj on gb10 as BF16 lanes [extent + 1, 16], one 8-byte load per bias MMA fragment with a zero row past the extent (bias_lanes; AMD keeps the F32 table). Per-score branches had made the compiler copy the softmax per path; the loop is now about 1,600 SASS instructions with 242 registers. One GB10, 8,192 rows, kernel against kernel (preliminary): sliding window 3.09 -> 2.28 ms, a global visit after 24,576 keys 53.5 -> 41.3 ms; error against an FP64 reference no larger at any tested shape. Spark, 32,768-token cold prompt at 8,192-token chunks (nsys): attention 1.57 -> 1.18 s, TTFT 6.87 -> 6.48 s. Numerics: rounding moves with the tile order and size. Teacher-forced prompt logprobs on 56 1K-token and 7 8K-token documents: per-document median NLL unchanged (+0.0009), five categories flat; chat reasoning and tool calling means rose (one unstable document, and eight sharing a prefix), as earlier rounding changes moved them either way. The same code with 32-key tiles, oldest first and the old arithmetic reproduces the old kernel bit for bit. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 2b6c199)
Prefill's routed experts wrote gate_up as BF16 [slots, 2 I] (302 MB a visit at 8,192-row chunks) and read it back to apply the softcapped SwiGLU and quantize it for the down GEMM. Both now happen in the gate_up GEMM's epilogue, bit for bit as before: - NVFP4 (inkling2_moe_fused_gate_up_fp4): a row's outer scale needs its maximum over all I values, which the 18 column tiles of its row tile hold between them. Persistent CTAs take (row tile, column tile) items in order from a counter; each tile stages its SwiGLU values, publishes its rows' partial maxima, meets its row tile's other tiles at a counter, then quantizes its own blocks. Taken items are always a prefix, so a waiting tile's partners are running or will be taken by CTAs that are not waiting; at least one row tile's tiles must be resident at once (checked). Round-robin items were 25% slower: the CTAs drift apart and the experts' weights leave L2. - MXFP8 (inkling2_moe_fused_gate_up_mx8): a 32-value block is half a tile, so no tile waits. inkling2_situ_quant_fp4 / _mxfp8 are gone; on gb10 gu shrinks to the fused kernel's scratch (about 300 MB less arena at 8,192-row chunks). Both kernels read tiles[0] through a volatile load: through `const __restrict__` ptxas scheduled it ahead of the PDL wait (ACQBULK), so CTAs started early took the previous visit's count and the prefill hung. No other PDL kernel in the Inkling or common sets loads ahead of its wait (SASS scan). One GB10 (preliminary, single runs): gate_up + SwiGLU-quantize at 8,192 rows 6.93 -> 5.31 ms in a standalone bench (outputs byte-identical); a 32,768-token cold prompt at 8,192-token chunks 6.48 -> 6.35 s (nsys), the 63 prompts of the prompt-logprob check identical to the previous build's. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 4c1154a)
The fused gate_up kept its per-row partial maxima slot-major ([slots, N / 128]), so each tile's 128 stores and the 18 __ldcg reads per row were strided (L1 is bypassed). Back to the tile-major [row tiles, N / 128, 128] the bench measured: 6.37 -> 5.64 ms a call at 8K-token chunks (median over 176 calls, one 32K prefill on one GB10; the down GEMM beside it unchanged at 2.52 / 2.53 ms), 32K TTFT 6.35 -> 6.21 s (preliminary, single run). Prompt logprobs on the 63-prompt set byte-identical to the unfused build. The buffer grows by experts x 18 x 512 bytes (~1.2 MB). Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 859bcf0)
The PDL contract (pdl_target_kernels_wait_exactly_when_listed) wants atlas_pdl_enter() as a listed kernel's first statement; both fused kernels declared their shared memory before it. No change to the generated waits. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit a4dbba3)
The gb10 flash prefill now takes one query head a CTA and gates its output; the strix-hip wave32 WMMA port keeps the previous geometry and ungated output. Say so where the two bodies meet; attn_ops.rs launches each on its own platform. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Formatting only (cargo fmt --all). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A visit's k/v convs and per-head norms move to forward_heads.rs as kv_convs_and_head_norms; the code is moved as is, with the batch's positions passed in for the log-length scale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@data-angel Gated this as the tree One fix was needed: the strix-hip build. Bit-identical where nothing should move
Inkling prefill numerics move, as you describe (GB10, prompt logprobs, 19,952 tokens):
Your comparison holds for prompts long enough to chunk: on the 20K set, 4K vs 8K chunks moves mean|Δ| by 0.0099 and this PR by 0.0102. Prompts under 4K tokens don't move with chunk size, but do move under this PR (0.012), which is expected with the new attention rounding. Greedy text differs from the parent (0/8, near-ties). Quality (Spark + DFlash2, 0.5.1 spark draft env, prefix cache):
That's one ST-995 run per arm. The −0.70 sits inside the range Prefill (GB10, cold, unique prompts, client TTFT, 2 reps each)
Observed +38–43% on this box. Your 8K / 32K / 64K / 128K table (5,174 / 5,024 / 4,540 / 3,781) lines up with the right column. (The "—" cell is my harness's limit: that arm runs a 131K max seq.) Strix Halo (DevLab A/B run 46149003369, this PR + #434 vs the parent): build passes, 0 hipError lines, decode unchanged (Spark C1 42.7 → 43.1, Strict 28.8 → 29.0 tok/s), arithmetic 40/40, tools 21/21, needle 12/12, NLL 0.68952 → 0.68971 (PR lower on 18/32). One question: prompt logprobs moved on AMD too (mean|Δ| 0.007, max 0.80; greedy 0/8 in both modes). The description says the AMD paths keep their previous behaviour, and the AMD flash prefill body is unchanged, so something shared moved: the fused norms in I will merge once the AMD ST-995 is in. #433 is next, and its gate (sparky job 212) is running. sparky nightq 211 / 213 · parent 🤖 Generated with Claude Code |
AzeezIsh
left a comment
There was a problem hiding this comment.
AMD ST-995 on this merge commit (+ #434), Spark, start-script flags (DevLab run 46159546328): 79.30 / 79.59 (non_live 75.71, live 66.47, hallucination 96.59; n=995, 0 ERROR / hipError). main's last two AMD runs were 79.30 (#426) and 79.10 (#412). Merging. The question about which shared change moved AMD prompt logprobs stands, for a follow-up.
🤖 Generated with Claude Code
Change 3 of 4 porting the SparkInkling 0.5.1 engine to
main, stacked on #431 (ten commits past it: sevenfrom the fork, then three for this port).
What
Inkling 2 Mini's prefill kernels on gb10; decode and verify rows keep their kernels, so text with drafts is still
the text without.
inkling2_flash_prefill): the relative biasBF16(rel . rel_proj)is a rank-16 product of BF16values, so it runs on the tensor cores per key tile and is read back along the diagonals. Then the kernel takes
one query head a CTA (4 warps, two CTAs an SM, heads fastest in the grid so a group's query heads read a KV tile
from L2), 64-key tiles newest first with K and V alternating in single buffers, masks only on tiles at the
diagonal or the window's edge, and the output gate in its epilogue (
inkling2_gate_mul's arithmetic). The layoutfollows knapcio/Inkling-2-Mini-1x-DGX-Spark's
inkling_attn(MIT), with our numerics.rel_projis uploaded asBF16 lanes for it on gb10; AMD keeps the F32 table. The per-head kernel's bias table is cut to the 63 rows it
serves.
inkling2_block_res_rownorms its own outputs on visits no message gate rewrites, andthe post-attention and post-MLP short convs add their BF16 output straight into the residual stream
(bit-identical arithmetic;
inkling2_residual/inkling2_layer_outand their buffers are gone).rebuilds each message from the message stack's BF16 states in the mix's own operation order (each value the fp32
message bit for bit), one read of the states a step. The fused gate runs on prefill chunks only (it also took
plain decode batches of 16 rows or more, whose text then depended on the batch size). AMD keeps reading the fp32
messages.
(
inkling2_moe_fused_gate_up_{fp4,mx8}), bit for bit as the separate pass, about 300 MB less arena at 8,192-rowchunks;
nvfp4_w4a4_tile.cuhloads its A and B fragments byldmatrix.x4(bit-identical, also used by Qwen3.8Flash-Next's experts). The fused kernels read their tile counter after the PDL wait.
AMD (strix-hip).
inkling2_flash_prefill.cuis symlinked there, andmainhas the wave32 WMMA port of theprevious flash kernel (#413, #426). That body is kept as it is under its
#if, andattn_ops.rslaunches it asbefore under
cfg!(atlas_scale)(one CTA per KV head, block 384, output ungated for the caller's gate); only thegb10 body under
#elsechanges. The other shared kernels this PR edits (inkling2_block_res.cu,inkling2_sconv.cu,inkling2_misc.cu,inkling2_head_ops.cu) gain no PTX outside existing AMD guards, and the AMD-only paths(
cfg!(atlas_scale)inforward.rs,gate_ops.rs,moe_ops.rs,weights.rs) keep the previous behaviour; Icould not build or run strix-hip here.
Port commits:
keep the AMD flash prefill body(the resolution above, with comments),rustfmt(formatting only),and
forward.rs under the 500-line cap(a visit's k/v convs and head norms move as is toforward_heads.rs).The fork's
ATLAS_PREFILL_BUSY_TOKENSchunk cap, which one of these commits added there, is left out (#433).Observed (the fork's engine on one DGX Spark, SparkModelBench, medians). Cold prefill in SparkInkling 0.5.1's
default profile, which runs 8,192-token chunks (0.5.0 ran 4,096) and so needs #433 as well:
At 32K that is 1.53x 0.5.0's 3,282 tok/s (Spark) and 1.50x its 3,268 (Strict); 0.5.0 was measured with RigMark
1.1.0, whose cold-prefill lane measures a given depth the same way. The commit messages carry the preliminary
per-change dev numbers (nsys, single runs).
Exactness. On development builds of this engine: prompt logprobs of 63 prompts (1K-8K tokens) byte-identical
across the fused gate_up change and the row-maxima layout fix; drafted and plain greedy text identical at 1, 4 and 8
requests after each prefill change. The attention changes move prefill rounding (tile order and size, one fewer
rounding in scale plus bias); teacher-forced prompt logprobs moved by as much as changing the chunk size moves them
(details in the commits). On the 0.5.1 release candidate: greedy text with drafts equals text without at one, two
and four requests, 8/8 prompts in both modes; task probe 30/30 arithmetic and 10/10 tool calls; image input checked.
The series
The engine of SparkInkling 0.5.1
(
Enntity/atlasinkling2/rc-0.5.1-20261126ata4dbba378), ported ontomain(9f4fd773f) as one changeper PR, stacked linearly:
The DFlash2 drafter commits that 0.5.0 carried are already on
main. Two things are not in this series:the fork's
ATLAS_PREFILL_BUSY_TOKENSchunk cap (#4 here makes it unnecessary, and the fork removed it, so it isnot proposed and no PR adds an
ATLAS_*name) and the opt-in LoopCD (--loopcd), which is not proposed for now.After #4, the engine files these commits touch equal
a4dbba378's except formain's own changes underneaththem (
glue.rs'sroute/kv_writenow inglue/route.rs;weights.rs,serve_load.rs),rustfmt, code movedas is to keep files under the 500-line cap (#2, #3), and the AMD flash prefill kept beside the new gb10 kernel (#3).
Where the numbers come from. Every GPU number below was measured on the fork's engine on its older base
(before #413 and #426), not on these branches: SparkModelBench
293a44f(RigMark protocol 1.3.0, RigMark Qualityv0.0.2,
reasoning_effort: low) on one DGX Spark, SparkInkling 0.5.1's default profile, published with receipts inresults/2026-11-27-rc-0.5.1.
No GPU has run these rebased branches.
Test plan
-D warnings, spark-runtime / spark-model / spark-server,--tests),cargo test --releaseof those crates (spark-model 2,526, spark-runtime 608 and spark-server 3,258 passed; the same five spark-server tests fail onmainin this container (three need a.gitcheckout, two read the disk's free space)), the 500-line cap, SPDX and kernel-shadow checks; no newATLAS_*namea4dbba378except formain's own moves,rustfmt, theforward.rssplit and the kept AMD flash pathAuthorship
AI-authored: Claude (Opus 5.5) in Claude Code, directed and reviewed by a human; no hand-written code.
CLA
🤖 Generated with Claude Code