Repository navigation
feat(hip): Inkling 2 Mini's loop kernels (cross-pass message and message gate) under the kernel contract, bit-equal to loop_model - #5012
Draft
AbrahamCete wants to merge 11 commits into
Conversation
…32 tanh and exp Inkling 2 Mini's serial reference (families/inkling2/loop_model.zig) evaluates the routed experts' activation with Zig's f32 std.math.tanh and @exp, which compiler-rt's expf implements. The device's own tanhf and expf give other bits, so experts.hpp ports Zig 0.17's f32 tanh, expm1, exp and ldexp operation for operation, with the constants' exact bits. A new kernel group, inkling2_experts (strict: -O2 -fno-fast-math, IEEE denormals), starts with tf_ink2_act_factors. The contract (image inkling2_experts) holds both factors, softcap4(g) * sigmoid(g) and softcap25(u), to Zig's bits at all 65,536 bf16 inputs; its control runs the device's tanhf and expf and goes red at shapes. A host test shows loop_model's expertActivation is one fp32 product of the two factors rounded once to bf16, so the factors' bits fix every activation output. Records for gfx1030, gfx1100, gfx1151 and gfx1201; the launcher imports only hip, and a mock runtime checks its grid.
…l to loop_model tf_ink2_nvfp4_down and tf_ink2_mxfp8_down decode w2 in registers as loop_model's reference rows do: NVFP4 as bf16(E2M1 * E4M3 * (bf16(amax) / bf16(denominator))), MXFP8 as bf16(E4M3 * 2^(scale - 127)) through ldexp, so scale 255 is 2^128 and does not overflow the way CUDA's fp32 2^(scale - 127) does. Each output is one fp32 chain over the route's 1,152 activations in input order (contraction off), rounded once to bf16. A block holds 64 outputs of one route, its activation row staged in LDS; an id past the experts gives a NaN row instead of reading past the weights. The contract compares every output's bits with loop_model's nvfp4ReferenceRow, mxfp8ReferenceRow and expertProjection, at decode and prompt rows, edges of 1, 63, 64 and 65 outputs and 32 and 64 inputs. Two one-hot cells cover every MXFP8 (code, scale) pair and every NVFP4 pair at eight amax values; the MXFP8 cells route to Mini's last experts through a weight base that many experts early. Gate 4's stress rows sum exactly in fp32 in any order, overflow fp16 and miss by over 100x in bf16, which a host test checks. The control reads each row's scales one group late and goes red at shapes. The launcher refuses a reduction past 2,304 or not of whole scale groups, misaligned codes, an NVFP4 call without amax or denominator, and more than 65,535 routes.
…ed SwiGLU bit-equal to loop_model tf_ink2_nvfp4_gu and tf_ink2_mxfp8_gu run w13's gate row 2j and up row 2j + 1 against a token's 2,304 inputs, each one fp32 chain in input order over weights decoded in registers, rounded to bf16, then bf16(softcap4(g) * sigmoid(g) * softcap25(u)) left to right in fp32 through the ported Zig tanh and exp. A block holds 64 outputs of one route; its token's row is staged in LDS. The contract compares every output's bits with loop_model's expertProjection and expertActivation at decode and prompt rows and the same edges as down; the MXFP8 cell routes to experts 120-127. Gate 4's stress rows give g = u = 1 exactly in fp32, where fp16 sums are not finite and bf16 sums miss by over 100x after the activation. Two controls go red at shapes: w13 given as gate rows then up rows (not interleaved), and one input a bf16 step up.
…to loop_model tf_ink2_combine sums a token's routes from fp32 zero in ascending (expert id, slot) order, each term the fp32 route weight times the bf16 down output, then rounds once to bf16, as loop_model's combineExperts does; ids outside the 128 experts are skipped. A block holds 64 outputs of one token. The contract compares every output's bits with combineExperts at 1, 16 and 2,048 tokens. Gate 4's terms (2^20, 3, 5, 7, 9, 11, -2^20 and 1 by ascending id) are exact in fp32, overflow fp16 and lose their residual in bf16; a host test shows route order would give other bits. The control rounds the fp32 route weights to bf16 and goes red at shapes. docs/kernel-contract.md describes the inkling2_experts image: the kernels, their rounding points, the factor proof, the decode cells, gate 4's rows, the NaN rule, the five controls and the refusals.
…once in LDS, bits unchanged The gate/up and down kernels ran one thread an output, each thread reading its own weight rows and decoding every weight in registers, with few waves resident at decode rows. Now a block of 256 threads holds 64 outputs of one expert and serves up to eight of that expert's routes in a launch (the block of its first route does; the others return). Each 64-input tile of the block's rows is loaded with 16-byte loads, one tile ahead, and decoded once into bf16 in LDS by all 256 threads: NVFP4 through a per-expert table of every E4M3 scale and E2M1 magnitude (the sign flips the bf16 bits, since (-a) * b * phi is -(a * b * phi) exactly), MXFP8 through a table of E4M3 values and the same ldexp. Each output's chain then runs from LDS, acc = acc + w * x in input order, gate and up interleaved; the sum order, the rounding points and every output bit stay as before. The decode loops index their registers with constants only, so no kernel uses scratch. The contract adds four cells whose 4 and 8 tokens give every route its own expert (the most weight traffic a launch can need); with the existing cells, 12 kernels pass gates 1-4 bit for bit and the 5 controls stay red. gate/up and down launch 256 threads a block; the records and the launcher's tests follow.
… flight, bits unchanged On the previous head, NVFP4 gate/up and down took as long as MXFP8 for the same tile count while reading half the bytes: every tile paid a whole memory latency. The next tile's prefetch was waited for at once, for three reasons. The scale bytes were packed into one register as they arrived, under a branch. The x values used 16-bit loads into half registers. And __syncthreads() fences global memory, so it waited for every outstanding load. Now every tile load is unconditional, from an address that is always valid (a run past the tile reads its row's start, a row past the block's its last row), with each scale byte and x value in its own register. The barriers fence LDS only, so later tiles' loads stay in flight across them. A tile's registers decode into LDS and then load the tile two ahead, so two tiles are in flight with no register copy. NVFP4's 16-byte and 8-byte row paths are two instantiations sharing one LDS block. The decode, each output's chain order and every output bit are unchanged: the contract's 12 kernels pass bit for bit and its 5 controls stay red. No kernel spills or uses scratch, and the VGPRs keep 16 waves a SIMD.
The loop kernels need the same f32 tanh and exp that the routed experts use, ported from Zig 0.17 operation for operation, and the same bf16 rounding. Those functions move from experts.hpp into inkling2/zmath.hpp, which experts.hpp includes; the build lists the new header so an edit to it rebuilds the groups. On all four chips every inkling2 and inkling2_experts kernel's code is identical to the previous head (hip-code-object-gate). The only changes are in tiles/dot2.hip's affine_dot2_block, which this does not touch and which changes between builds of the same tree. `image inkling2_experts` smoke and full: 12 kernels pass gates 1-4 and the 5 controls are red as planted.
…to Zig's bits The loop kernels (the cross-pass message and the message gate) must match loop_model.zig bit for bit, and loop_model runs Zig 0.17's f32 std.math.tanh, @exp and `1 / @sqrt`. This adds the inkling2_loop kernel group, built with the strict flags, and its first launch: tf_ink2_loop_math, a probe that runs the kernels' tanh and exp (the ports in zmath.hpp) and their inverse square root (a correctly rounded sqrt, then a division) over given inputs. The contract checks the probe against Zig at every branch edge of the ported functions, all 65,536 bf16 patterns and 262,144 random f32: on gfx1151 every output has Zig's bits. A control runs the device's own tanhf, expf and rsqrtf instead and goes red at `shapes` (58,315 of 986,721 outputs differ). Outside the contract, the probe matches Zig on all 2^32 f32 inputs for each of the three functions. The group plumbing (build group, kernels.zig, contract entry, record families, a host step `test-inkling2-loop-hip-host`) follows the inkling2_experts group's.
tf_ink2_loop_messages computes loop_model.crossPassMessage for every row, core layer and role (q, k, v, mlp): rho of the bf16 banks B_12 and P_18, each query's dot with both, the two-way softmax, and the weighted sum. Its output is f32 [message][rows][2,304], CUDA's layout, so each role's rows are one plane a gate can read. A block of 256 threads holds four rows of one message in LDS; one lane per (row, bank) runs the sum of squares and then the dot, each as a single fp32 chain from +0 in input order. Where CUDA and Metal round otherwise, this follows loop_model: 1 / sqrt as a correctly rounded sqrt and a division (not rsqrt), unfused query dots in input order, Zig's f32 exp, and the output's sum from +0, so a column where both shares are -0 gives +0 (CUDA and Metal give -0). The contract compares every output's bits with loop_model's at 1, 4 and 8 rows for one and all 12 core layers, the row group's edges, and prompt calls of 16, 64 and 2,048 rows. Gate 4's banks of +-1 and three-term queries keep every fp32 sum exact in any order; fp16 sums would miss by 42,505x and bf16 by 252,578x. Three controls go red at `shapes`: rsqrt for 1 / sqrt, fused query dots, and the sum without its +0 start.
tf_ink2_loop_gate_down and tf_ink2_loop_gate_up compute loop_model.messageGate for one to three gates a launch, so the q, k and v gates of a visit can share one. Down: a 256-thread block a row and 8 ranks finds rho of h and m, rounds the joined norm to bf16, and runs 8 zeta chains of 4,608 from +0 in input order, each rounded to bf16. Up: a thread a column runs the forget and gain chains of 64 in rank order through Zig's f32 tanh (ported in zmath.hpp), then (1 - F) * h + G * m as four fp32 steps. A gate may write over its own h, as the engine's gates do. A dependent fp32 add costs about 2.1 ns on gfx1151 from registers and 2.6 ns from LDS, but 5-7 ns when the same lane also converts and multiplies its operands. So every thread computes the chains' f32 products into LDS (each product loop_model's, exact or rounded once), and the chain lanes only load and add, two blocks ahead. The weights of the next three 256-column tiles stay in flight in registers across LDS-only barriers. The contract compares every output's bits with loop_model's at 1, 4 and 8 rows for one and three gates (the second and third in place), an up block's row edges, and prompt calls of 16, 64 and 2,048 rows. Gate 4's h and m of +-1 with three +-256 keep every fp32 sum exact in any order; fp16 sums would miss by 6e8x and bf16 by 3.7e6x. Two controls go red at `shapes`: the device's own tanhf, and the last two steps fused into one fma.
…ts unchanged Each message and gate is bounded by its serial fp32 chains (loop_model fixes their order): 4,608 dependent adds for a message, 6,976 for a gate. On gfx1151 a dependent add costs about 2.1 ns from registers, but these ran at 3.5 ns or more: the chain lanes converted and multiplied their own operands, and the compiler waited on each LDS load four adds after issuing it. - Messages: one row a block (18.7 KB of LDS, so all 48 messages of a row are resident), every thread writes its columns' squares and then query products into LDS, and lanes 0 and 1 only add them. - Chains read 32 floats ahead, with __builtin_amdgcn_sched_barrier between blocks of 8 so each load stays 24 adds ahead (2.9 ns a step). - Gate down: waves 1-6 compute each tile's products two tiles ahead into three slots, so the 8 chain lanes run on into the next tile without a pause; the joined norm is kept as bf16 over the squares (29.6 KB of LDS, four blocks a WGP). - Gate up: a block of 64 columns by 4 rows, one row a thread row. - The messages' fma control now fuses the second share of the sum. rocprofv3 medians on gfx1151, cold weights rotating over 48 controllers, launches queued (c4a9d22/be58440fb -> this): messages, 1 row: 4 messages 21.4 -> 14.8 us, 48 messages 49.4 -> 15.6 messages, 8 rows: 4 messages 24.0 -> 15.0 us, 48 messages 73.6 -> 66.6 messages, 2,048 rows, 4 messages: 1,503 -> 1,228 us gate down, 1 row: 1 gate 28.0 -> 22.8 us, 3 gates 29.8 -> 23.6 gate down, 8 rows, 1 gate: 55.8 -> 25.8 us; 2,048 rows: 8,225 -> 5,091 gate up, 1 gate: 1 row 3.7 -> 4.2 us, 8 rows 17.9 -> 5.6 us `image inkling2_loop` smoke and full: 3 kernels pass gates 1-4 with the same bits, 6 controls red. No spills or scratch on any chip.
3 of 4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
TensorFold has no HIP kernels for Inkling 2 Mini's loop: the cross-pass message and the message gate. This adds them as
a new
inkling2_loopHIP kernel group with its launcher and a kernel-contract entry at Mini's shapes:tf_ink2_loop_messages, and the gate's two halvestf_ink2_loop_gate_downandtf_ink2_loop_gate_up. It is HIP4 ofthe HIP column on #4274, after ashhart's go (issuecomment-7132785932). Kernels only: no engine, glue or attention
residual.
As in #4994, every registration compares each output's bits with
families/inkling2/loop_model.zig(
crossPassMessageandmessageGate). No float64 bound is used.Where they sit. In passes 2 and 3 of the core layers (visits 18 to 41), a layer's messages come from the previous
pass's banks: B_12 and P_18, bf16, copied at the end of passes 1 and 2. The q, k and v gates mix each role's raw
attention-residual output with its message. After the MLP's attention residual, the mlp gate does the same. A token
has 96 messages and 96 gates. CUDA's engine computes a visit's 4 messages before its gates, and Metal computes all 48
at the pass reset;
tf_ink2_loop_messagestakes 1 to 12 core layers a call, so either works. One gate launch takes 1to 3 gates, so a visit's q, k and v gates can share one. A gate may write over its own h, as CUDA's engine does.
Arithmetic, as
loop_model.zighas it:the inverse is
1 / sqrt(mean + eps): a correctly rounded square root, then a correctly rounded division, not rsqrt.eps is loop_model's float64 1e-6 narrowed to f32. Each normalized value is one fp32 product.
is that dot times binary32(1/48), which the launcher computes as
residualScaledoes. The softmax takes the maxfrom -inf, Zig's f32
@expof each difference and the sum from +0. Each output sums its two shares w * b from +0, soa column where both shares are -0 gives +0. Output is f32 [message][rows][2,304], CUDA's layout, so each role's rows
are one contiguous plane.
zeta is one fp32 chain of 4,608 bf16 products from +0 in input order, rounded once to bf16. Each forget and gain is a
chain of 64 from +0 in rank order through Zig's f32
std.math.tanh. The output is (1 - F) * h + G * m as four fp32steps: keep, left, right, sum. Output is f32.
change only those products. The message dots and the f32 squares round every product, so contraction is off.
The header move. HIP4 needs the same f32 tanh and exp that #4994 ported from Zig 0.17. The first commit moves
zexp,zexpm1,ztanh,zldexpand the bf16 helpers fromexperts.hppintoinkling2/zmath.hpp, whichexperts.hppincludes. On all four chips everyinkling2andinkling2_expertskernel's code is identical to262b048's (hip-code-object-gate).
image inkling2_expertssmoke and full pass on that commit and on this head(SUMMARY lines below).
Proofs of the f32 math, over all 2^32 inputs.
tf_ink2_loop_mathis a probe that runs the kernels' tanh, exp and1 / sqrt. A small host harness ran this head's code object over every f32 bit pattern and piped the outputs to a Zig
0.17 checker, built once with libc and once without:
ztanh,zexpand1 / sqrtfeach give Zig's bits on all 4,294,967,296 inputs, NaN payloads included, with andwithout libc. This covers all f32 inputs, wider than the f32 <= 0 that the softmax's exp needs.
sqrtf,1 / xandx / 2304, and forx / ywith a pseudo-random divisor y derived from each x.expf on 41,203,423 and rsqrtf from
1 / @sqrton 597,936,208 (beyond NaN payloads).v_sqrt_f32followed by the correctly rounded correctionsequence, and the division is
v_div_scale/v_div_fmas/v_div_fixup. Nov_rsq_f32appears outside the rsqrtcontrol and the probe's device op.
Design.
their query products, into LDS (18.7 KB), and lanes 0 and 1 add each bank's terms in order. At 18.7 KB, six
blocks fit a WGP, so all 48 messages of a row run at once.
4,608-long products into one of three LDS slots, two tiles ahead of the chains. Lanes 0 to 7 add them in order,
reading on into the next slot. Each producer keeps three tiles of weights in flight in registers across LDS-only
barriers. The joined norm sits as bf16 over the squares (29.6 KB of LDS, four blocks a WGP).
converted and multiplied its own operands, the 1-row, one-gate gate down took 28.0 us. With other threads writing
the exact f32 products and
__builtin_amdgcn_sched_barrierkeeping each load 24 adds ahead, it takes 21.9 us here.That is one queued run of each object, with no base-against-base run. Who computes a product changes nothing in its
bits or in the order of any sum.
-O2 -fno-fast-math -fdenormal-fp-math=ieee,-ffp-contract=off) forgfx1030, gfx1100, gfx1151 and gfx1201, with no chip-specific path.
hip. Before any launch it refuses no rows or more than 2,048, no or more than 12 corelayers, no or more than three gates, and tensors not 16-byte aligned.
Speed, measured on gfx1151. A small harness loads this group's code object, as the build makes it, and launches it
as the launcher does. Each gate launch reads a different controller from the launch before it: three-gate launches
rotate over all 48 (56 MB), one-gate launches over 16 (18.9 MB). Whether any of these reads hit a cache was not
measured. Launches were queued back to back. Times are rocprofv3 kernel-trace medians of 30 launches, from the code
object whose gfx1151 sha256 prefix is 7e7e0409. A second run of the same object matched within 0.5 us at the decode
shapes and 3.5% at the prompt shapes; there is no base-against-base run and no mirrored order.
tf_ink2_loop_messagestf_ink2_loop_messagestf_ink2_loop_messagestf_ink2_loop_messagestf_ink2_loop_messagestf_ink2_loop_messagestf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_gate_downtf_ink2_loop_gate_upPer decode token, from the table, with the q, k and v gates in one launch and the 48 messages at each of the two
resets:
1.52 ms. With 4 messages a visit instead, as CUDA's engine does, it is 1.84 ms. With each of the 96 gates its own
launch, the gates alone take 2.51 ms.
A token's gates read 96 x 1,179,648 bytes of controller weights, about 113 MB; the queries add 0.9 MB. At 240 GB/s (a
1 GiB read kernel, median of 20, from #4994's runs) that is 0.47 ms, so the 1-row total is 3.2x the bandwidth bound.
The serial order sets its own floor: a gate's critical path is 6,976 dependent adds (2,304 for rho, then 4,608 for
zeta, then 64), and a message's is 4,608, so one token's 48 gate launches and 2 message launches hold 344,064
dependent adds (48 x 6,976 + 2 x 4,608). I kept no measurement of a dependent add's latency here, so I give no time for
that floor. The llama.cpp Vulkan baseline on this machine (21.9 tok/s, posted on #4274) leaves 45.7 ms for a whole
token; 1.52 ms is 3.3% of it.
The before/after in 9c61b6e's message is one queued run of each object, with no base-against-base run and no
mirrored order, and its "after" column comes from a build that differs from this head only in comments. In it, the
gate up at 1 row and one gate is 0.5 us slower (3.7 -> 4.2 us), while that row's gate pair, down plus up, is faster.
Where CUDA, Metal and loop_model differ. This follows loop_model everywhere:
The inverse square root: CUDA's
rsqrtf, Metal'sprecise::rsqrt, loop_model's1 / @sqrt.rho's sum of squares: CUDA runs 256 lane chains strided with FMA and a tree; Metal runs strided unfused lane sums,
simd_sum, then 8 partials in order; loop_model runs one ascending chain, unfused.The message dot (f32 products): CUDA uses FMA and a tree, Metal strided unfused lanes and
simd_sum, loop_model oneascending chain, unfused.
zeta: CUDA sums with a tree; Metal and loop_model sum in input order. The forget and gain dots are ascending
everywhere.
exp and tanh: CUDA's
expfandtanhf, Metal'sprecise::expandprecise::tanh, loop_model's Zig f32@expandstd.math.tanh.The message output: CUDA and Metal write m0 + m1, which is -0 where both shares are -0; loop_model starts from +0
and gives +0 there. A contract control holds that difference.
Issue: Refs docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274 (the HIP column's HIP4) and Refs Inkling 2 Mini on HIP (gfx1151): serve the looped 26.4B checkpoint natively #4265 (the HIP issue). HIP2 (glue), HIP5 (engine) and the rest of
the column remain.
Stacked on: feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994 at 262b048. feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994's branch lives in my fork, so this targets
mainand its diff also showsfeat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994's six commits. This pull request's own commits are these five:
Size: +1,878/-160 in 17 files against 262b048. The messages and gates commits are 653 and 668 lines, each one
behavior with its tests and records.
atc overlap --json(ATC 0.9.6, 2026-11-25 08:04Z, againstmain, so feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994's files count too): 16 overlaps. Fourreport a conflict in one file each: idol: BiRefNet background removal and preprocessing on Metal, so tf-idol-generate takes a raw photo (stacked on #1780) #1787, hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490, ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522 and ricursive: speed up Ripple-65B on two GB10s #2523, the same four as feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994's run. This group appends
to the same shared lists as feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994's group, and whichever lands second rebases. Six merge clean, and six report unknown because the run is incomplete (limits on
pull requests, their files and time).
Questions for you; say which you want changed:
adds, so these kernels are latency-bound, at 3.2x the bandwidth bound. A reference-defined parallel order might
bring them near the bandwidth bound (not built or measured).
here), or 4 a visit, as CUDA does (0.35 ms)? And may HIP5 pass a visit's q, k and v gates in one launch, as the
launcher allows?
weight tile across rows could cut that (not built or timed). Do you want it here, or with HIP5's prompt path?
tf_ink2_loop_mathand the six control kernels ship in theinkling2_loopimage, astf_ink2_act_factorsdoes in feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994 (its fourth question). The served kernels contain no switch; each control isits own compile-time instantiation.
by other threads into LDS, so a fused dot no longer exists as such. Is that control enough for this kernel?
Checks on this head
main3795e60).python3 tools/zig/lean_check.py, on the base and on this head: 165 and 165, 0 new. The base ismain3795e60.python3 tools/pr_check.py --base 3795e6054: 0 errors, 1 advisory warning ("pass --pr NUMBER tocheck its Unreleased line"; the changelog line is yours).
zig build test-inkling2-loop-hip-host -Dhip=true: 12 of 12 passed. On a mock runtime they cover the launcher'sgrids and refusals and the query scale and eps. On the host they cover the gate-4 simulations, which equal
loop_model bit for bit in fp32 order, the -0 case and the stress rows' margins.
test-inkling2-experts-hip-host:11 of 11 passed.
zig build teston a clean tree of this head: 13,494 of 13,588 passed, 93 skipped, 1 failed. The failure isstage_hip_test"every staged call on HIP memory equals the reference, whole and in parts", the failure feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994reports on
main3795e60 too.zig build test -Dhip=trueon the same tree: 1,493 of the 1,515 tests it ran passed, 21 skipped, and the samestage_hip_testfailed.zig fmt --check build.zig zigandgit diff --check: clean.affine_dot2_block<DotBF16, N>instantiations intiles/dot2.hip, which this branch doesnot touch: 4 on gfx1151 (N = 2, 3, 6 and 8) and gfx1201, 1 on gfx1100, none on gfx1030. feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994 found two
builds of
mainalone differing in four instantiations of the same function (N = 2, 3, 5 and 6).inkling2_expertskernels are identical on the four chips.contract went red:
11651 of 986721 outputs differ; first tanh at 0x3e82c577: 0x3e7ffffe where Zig gives 0x3e7fffff;message 0 row 0 column 0 is 0xc18bcc74 where loop_model gives 0xc18bcc75,and at
shapes,0xbf6a24ae where loop_model gives 0xbf6a24af;gate 0 row 0 column 2 is 0x3d79d48a where loop_model gives 0x3d79d488, and37.1x over its exact-sum bound at k 4608.objects.
temperature,
/dev/kfdholders) was recorded beside it.not kept, so no figure for either is given here.
affine_dot2_blockN = 8 changing: the build nondeterminism above is shownfor N = 2, 3, 5 and 6 only.
Receipt
n/a: these kernels do not reach inference yet; no engine or server calls them. The kernel contract below is the
evidence, and the timing above is a kernel-level measurement, not a served receipt.
Kernel contract, only when a GPU kernel is new or changed
Kernels registered with the contract (
tf-hip-kernel-contract image inkling2_loop); none replaces another kernel.Each output's bits are compared with loop_model's (or Zig's, for the probe), NaN as a class:
tf_ink2_loop_math: tanh, exp and 1 / sqrt at 328,907 inputs, 986,721 outputs. The inputs are every branch edge ofthe ported tanhf, expf and expm1f one ulp either side and both signs (expm1's at half its argument too), zeros,
infinities, NaNs, subnormals, the largest finite, exp's subnormal outputs from -87.25 to -104.5 every 1/64, all
65,536 bf16 patterns and 262,144 random f32.
tf_ink2_loop_messages: 1 row at one and all 12 core layers; 4 and 8 rows at 12 layers; prompt calls of 16 rowsat one layer, 64 at 12, and 2,048 at one; 7 shapes. Both banks hold -0 at two columns a row, so the +0 start is
checked at every shape. One-layer cells use the last core layer's query rows; 12-layer cells use all 24.
tf_ink2_loop_gate_downwithtf_ink2_loop_gate_up: 1 row with one and three gates; 4 and 8 rows with three;prompt calls of 16 rows with one, 64 with three, and 2,048 with one; the up block's row edges at 3, 4 and 5; 10
shapes. The second and third gates of each call write over their own h.
infinite m, an infinite forget weight and a NaN gain weight (gates). Both NaN and finite outputs must occur.
three small integer weights a row (gates). Every fp32 sum is exact in any order. fp16 sums would miss by 42,505x
(messages) and 605,453,945x (gates), and bf16 by 252,578x and 3,671,421x.
A planted control for each new kernel, each its own kernel, red at
shapes:58315 of 986721 outputs differ;0xc0407054 where loop_model gives 0xc0407053;0xbf9f3bf3 where loop_model gives 0xbf9f3bf4;column 11 is 0x80000000 where loop_model gives 0x00000000;0x3fd8cd82 where loop_model gives 0x3fd8cd84;0x3f202abf where loop_model gives 0x3f202abe.Each backend's
SUMMARYline (gfx1151, ROCm 10.1's hipcc, HIP 7.16); the logs keep no exit status:SUMMARY inkling2_loop HIP full: 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 801 ms, limits 4 msSUMMARY inkling2_loop HIP smoke: 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 459 ms, limits 5 msimage inkling2_experts, which this branch changes only by the header move:SUMMARY inkling2_experts HIP full: 12 kernels: 12 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 11790 ms, limits 4 msSUMMARY inkling2_experts HIP smoke: 12 kernels: 12 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 10511 ms, limits 4 mszig build hip-kernel-contract-limits: all 36inkling2_loopand 24inkling2_expertsrecords PASS on the fourchips. The step exits 1 with 11 problems, the same 11 as feat(hip): Inkling 2 Mini's routed experts under the kernel contract, bit-equal to loop_model #4994 reports on
main3795e60 with this hipcc, all inother groups:
tf_moe_combine_gate(gfx1030, gfx1100, gfx1151),tf_vl_resize(all four chips), and the 6- and8-bit relu2 stream tiles 2x8 and 4x4 on gfx1100.
Records (
hip_records_inkling2_loop.zig), VGPRs on gfx1030 / gfx1100 / gfx1151 / gfx1201; no scratch on any chip:tf_ink2_loop_messagestf_ink2_loop_gate_downtf_ink2_loop_gate_uptf_ink2_loop_mathtf_ink2_loop_ctl_rsqrttf_ink2_loop_ctl_fmatf_ink2_loop_ctl_signed_zerotf_ink2_loop_ctl_tanhftf_ink2_loop_ctl_gate_fmaChips I could not run: gfx1030, gfx1100 and gfx1201 (limits only), and every CUDA SM and Metal chip.
Checklist
registrations failed before their kernels were right, as shown above. The launcher's host tests were written with
the launcher and not run without it.)
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no engine)--drafter, no slower than without it, greedy and sampled. (n/a: no engine)