Skip to content

inkling2 cuda: Mini expert weights staged a warp in 128-byte rows, the NVFP4 factor once an expert (decode 5.6 to 9.8 tok/s, same bits) - #4728

Merged
ashhart merged 5 commits into
ashhart:mainfrom
jschmied:ink2-mini-speed-experts
Nov 24, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
jschmied:ink2-mini-speed-experts

Conversation

@jschmied

@jschmied jschmied commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Update for review 7098920791: head fb55ed477e

Point 4, the scale loads. fetch read each lane's row scales as whole uint32 words: (2 steps + 3) / 4 of them for NVFP4, one for MXFP8. Two things could go wrong:

  • Reading past the data. The scales are unpadded, so a tile with fewer than four scale bytes left read past the row, and on the last row past the data (your point).
  • Misaligned loads. At K = 32 a row's scales also start at an odd half-word (NVFP4: 2 bytes a row; MXFP8: 1), and a word load cannot read them there.

The fix (modelopt.cu:60-89) is a bounded tail rather than a narrower guard:

  • a whole word loads only while four bytes remain and the row's start is word-aligned;
  • the rest loads byte by byte into the same word.

Mini's shapes (K 2304 and 1152) are aligned with no partial word, so their path still takes whole words.

The contract adds NVFP4 and MXFP8 decode cases at K = 32, rows 1 and 16. Each projection's scales sit in an allocation of exactly their size, so a read past them leaves the allocation.

  • Red before: the same test on 3cd12eb55e (old kernel) fails every gate with CUDA_ERROR_MISALIGNED_ADDRESS. compute-sanitizer memcheck on that filtered synthetic test reports Invalid __global__ read of size 4 bytes … misaligned. At K = 32 the misaligned word load is the first fault and hides the over-read behind it.
  • Green on this head:
    • shapes bit-equal to the replaced host-dequantized baseline; nonfinite and repeat pass;
    • memcheck on kernel-contract "K = 32": ERROR SUMMARY: 0 errors.
  • Gate 4 (sums) is waived for these two cases only (.f16 = 0, .bf16 = 0 with a stated reason): a 32-term sum cannot tell FP16 from FP32. The four Mini-shape specs keep their 30× requirement.

Checks on fb55ed477e (GB10):

  • Host: the Inkling steps are green. The registry test finds the base's 40. pr_check: 0 errors, lean 167 vs 167. fmt and diff-check: clean.
  • Kernel contract inkling2: 55/55 pass gates 1-4, 36 of 36 controls red, 0 limit problems.
  • SASS against 3cd12eb55e (sm_80/86/89/120/121): tf_ink2moe_plan, _act and _combine are identical; tf_ink2moe_up and _prompt_up differ, as intended. Registers are unchanged on sm_121 (168 and 198).
  • Served: hashes identical to Inkling 2 Mini on CUDA: #4387's engine loads the checkpoint, answers correctly (64/64 teacher-forced), serves --parallel streams, and resumes prompt-cache states exactly #4640's (greedy, seeded, again, c=4, long cold/warm, turn 2). inkling2-serving: PASS. The served binary (e083a52e) is byte-identical to the one the gates ran on.
  • Speed: one A-B-B-A against 3cd12eb55e (A e6, B this head), SM clock 2288 MHz in both arms:
    • c=1: 9.836 vs 9.842 tok/s, paired median 1.0006, 0 of 2 slower;
    • c=4: 9.751 vs 9.750, paired median 0.9999, 2 of 2 slower;
    • TTFT: 27.07 vs 27.10 s, paired median 1.0008, 2 of 2 slower.
  • In that one round the c=4 and TTFT cells were slower in both pairs, by 0.01 % and 0.08 %. A three-round A-B-B-A settled it: c=1 1.0005 (0 of 6 slower), c=4 1.0003 (0 of 6), TTFT 1.0005 (3 of 6). No cell is consistently slower.

What this changes

Mini's routed experts (tf_ink2moe_up for decode, tf_ink2moe_prompt_up for prompt chunks) decoded every BF16 weight on its own: one byte load for its code, one for its scale, the expert's amax and denominator, and an FP32 division (amax / denominator, the NVFP4 factor) for each weight. The experts took 92.8 ms of the 181.8 ms a token on #4640's head (nsys, c=1, 60 decode forwards).

This PR changes only how the weights reach the tensor cores:

  • Each warp stages its 32 rows' codes in shared memory, 128 bytes a row with 8 lanes a row, and their scale bytes. It then decodes its fragments from there.
  • The NVFP4 factor is computed once per expert and unit.
  • On decode (one row), the next tile and the next step's inputs are fetched while the current step multiplies.

Each weight is the same product rounded the same way (e2m1 × e4m3(scale), then × the factor for NVFP4; e4m3 × e8m0 for MXFP8; then BF16). The mma sequence and the epilogue are unchanged, so the outputs are bit-equal. The experts go from 92.8 ms to 14.3 ms a token.

Checks on this head (3cd12eb55e)

GB10 (sm_121, CUDA 13.0), Zig 0.17.0, thinkingmachines/Inkling-2-Mini@ed40e7da.

Speed (A-B-B-A against #4640's head, this head's binary)

Served, tensorfold-native serve --parallel 4 --context 8192, default copy drafting and prompt cache on, page cache dropped before each server start. Each arm is a fresh server. Order A B B A, two rounds. A = #4640's head (321432e4b2), B = this head.

  • Cells: cold TTFT of a 7,262-token prompt (1 token out); c=1 decode = 4 topics × 128 greedy tokens, (tokens − 1) / (wall − 1-token wall); c=4 aggregate = the 4 topics at once, total tokens / wall. Tokens are counted from usage.
  • SM clock was logged at 1 Hz: median 2288 MHz in both arms, with the same constant clock-event mask (0x400, the box's boot-time clock cap). No round was dropped.
cell A (#4640), best of 4 B (this PR), best of 4 paired median B/A pairs where B is slower
c=1 decode 5.63 tok/s 9.85 tok/s 1.749 0 of 4
c=4 aggregate 5.57 tok/s 9.76 tok/s 1.754 0 of 4
prompt TTFT (7,262 tokens) 33.91 s 27.08 s 0.799 0 of 4

The reply hashes were equal in every arm, solo and c=4. The prompt cell gains because tf_ink2moe_prompt_up stages its tiles the same way. nsys (c=1, 60 decode forwards): experts 92.8 → 14.3 ms a token.

  • Binaries: A 019c09e6 (built from 321432e4b2), B 516459f0 (built from 3cd12eb55e, the commit itself). The gates above ran on the same B build.
  • Why not against main: this PR targets lead/inkling2-mini, whose Mini engine main does not have.

Proposed CHANGELOG line

  • Inkling 2 Mini on CUDA: expert weights are staged a warp in whole 128-byte rows and the NVFP4 factor is computed once an expert, 93 ms to 14 ms a token in the experts, with the same bits.

@jschmied

Copy link
Copy Markdown
Contributor Author

Three-round A-B-B-A on fb55ed477e against 3cd12eb55e, settling the small paired loss in the body. Same setup: fresh server each arm, page cache dropped, SM clock median 2288 MHz in both arms.

cell paired median B/A pairs where B is slower
c=1 decode 1.0005 0 of 6
c=4 aggregate 1.0003 0 of 6
prompt TTFT 1.0005 3 of 6

Reply hashes were equal in every arm, solo and c=4. The one-round loss doesn't repeat: no cell is consistently slower, so the "don't land yet" in the body is withdrawn. 12 runs in all.

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 contract run on RTX 5060 Ti (independent of GB10), head fb55ed4.

tf-cuda-test kernel-contract inkling2:

  • 55/55 kernels pass gates 1-4, 0 gate failures
  • 36/36 planted controls red as designed, 0 missed
  • 20 limit problems: the new experts/vision/modelopt/loop_math kernels launch with real register+shared usage while the sm_120 records still read 0,0 placeholders (e.g. tf_ink2x_group 42 regs 144+27648B shared vs recorded 0,0). Small drifts on older kernels too: tf_ink2_attn 194 vs 202 recorded regs, tf_ink2_mix 72 vs 74, tf_ink2_rowdot 35 vs 34.
  • Records were built by nvcc 13.5 against the nvcc 13.3 record set.

No gate failures on sm_120; the limit diffs look like record-staleness on this arch rather than regressions, same pattern as #4697/#4718.

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

ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart#4728 rewrites tf_ink2moe_up and tf_ink2moe_prompt_up and records their
compiled usage at sm_121 only; at sm_80, sm_86, sm_89 and sm_120 the rows
held zeros, so the kernel registry test failed with 8 "no compiled usage
recorded" entries.

The values are nvcc 13.0's, from kernel-contract-limits over fatbins built
for all five SMs from this tree; each sm_121 entry equals the one the PR
recorded. No kernel changes.
@ashhart
ashhart force-pushed the ink2-mini-speed-experts branch from fb55ed4 to e93ec03 Compare November 24, 2026 12:13
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart#4728 rewrites tf_ink2moe_up and tf_ink2moe_prompt_up and records their
compiled usage at sm_121 only; at sm_80, sm_86, sm_89 and sm_120 the rows
held zeros, so the kernel registry test failed with 8 "no compiled usage
recorded" entries.

The values are nvcc 13.0's, from kernel-contract-limits over fatbins built
for all five SMs from this tree; each sm_121 entry equals the one the PR
recorded. No kernel changes.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart#4728 rewrites tf_ink2moe_up and tf_ink2moe_prompt_up and records their
compiled usage at sm_121 only; at sm_80, sm_86, sm_89 and sm_120 the rows
held zeros, so the kernel registry test failed with 8 "no compiled usage
recorded" entries.

The values are nvcc 13.0's, from kernel-contract-limits over fatbins built
for all five SMs from this tree; each sm_121 entry equals the one the PR
recorded. No kernel changes.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. We rebased this onto main and ran a serving A/B on a GB10 with Inkling 2 Mini: main against this branch, builds alternated base, new, new, base.

  • Tokens: identical in all 16 cells (one stream, four streams, resumed replies, and raw prompts of 1 to 33 rows).
  • One-stream decode: 5.95 to 10.11 tok/s (+70%).
  • Four streams, aggregate: 4.75 to 7.59 tok/s (+60%).
  • Long-prompt time to first token: 14.09 s to 11.31 s.

It's now in our landing queue.

  • Synthena

ashhart and others added 5 commits November 24, 2026 18:05
…ws, the NVFP4 factor once an expert

tf_ink2moe_up and tf_ink2moe_prompt_up decoded every BF16 weight with its own byte loads (code, scale)
and an FP32 division (amax / denominator), so a decode token spent 96 ms in the routed experts. Each warp
now stages its 32 rows' codes 128 bytes a row (8 lanes a row) and their scale bytes in shared memory, and
decodes its fragments from there; the expert's factor is computed once a unit. On decode (one row) the next
tile and the next step's inputs are fetched while the current step multiplies. Each weight is the same
product, rounded alike, and the mma sequence is unchanged, so the bits are unchanged.
…e, K = 32 in the contract

fetch read each lane's row scales as whole uint32 words, (2 steps + 3) / 4 of them for NVFP4 and one for
MXFP8. The scales are unpadded, so a tile with fewer than four bytes left read past the row, and at the
end of the projection past the data; at K = 32 a row's scales also start at an odd half-word, which a word
load cannot read. Whole words now load only while four bytes remain and the row's start is word-aligned;
the rest loads byte by byte into the same word. Mini's shapes (K 2304 and 1152) are aligned with no tail,
so their path still takes whole words.

The contract adds NVFP4 and MXFP8 decode cases at K = 32 (rows 1 and 16), each projection's scales in an
allocation of exactly their size, so compute-sanitizer memcheck sees any byte read past them.
ashhart#4728 rewrites tf_ink2moe_up and tf_ink2moe_prompt_up and records their
compiled usage at sm_121 only; at sm_80, sm_86, sm_89 and sm_120 the rows
held zeros, so the kernel registry test failed with 8 "no compiled usage
recorded" entries.

The values are nvcc 13.0's, from kernel-contract-limits over fatbins built
for all five SMs from this tree; each sm_121 entry equals the one the PR
recorded. No kernel changes.
@ashhart
ashhart force-pushed the ink2-mini-speed-experts branch from e93ec03 to ba9a31d Compare November 24, 2026 18:06
@ashhart
ashhart merged commit 0d8cbb2 into ashhart:main Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
#4728 rewrites tf_ink2moe_up and tf_ink2moe_prompt_up and records their
compiled usage at sm_121 only; at sm_80, sm_86, sm_89 and sm_120 the rows
held zeros, so the kernel registry test failed with 8 "no compiled usage
recorded" entries.

The values are nvcc 13.0's, from kernel-contract-limits over fatbins built
for all five SMs from this tree; each sm_121 entry equals the one the PR
recorded. No kernel changes.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants