Skip to content

inkling2: Inkling 2 Mini served on CUDA at one rank (H2 + C4), stacked on #4364 and #4365 - #4441

Closed
jschmied wants to merge 11 commits into
ashhart:mainfrom
jschmied:inkling2-mini-c4
Closed

jschmied wants to merge 11 commits into
ashhart:mainfrom
jschmied:inkling2-mini-c4

Conversation

@jschmied

@jschmied jschmied commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Proposal for review (draft). Inkling 2 Mini served on CUDA at one rank, text only: slices H2 and C4 from #4274. It is the engine behind the numbers in my comments on #4387. Head 7912af56d0, rebased onto main 14951bc65d on the user's request (was dc2ca8a178 on main 1587c8caee).

Stacked. This branch merges the two drafts unchanged: #4364 (C1, aeb9cb06c3, not rebased: main changed none of its files) and #4365 (C3, rebased to b2cea56fe6), in the two local: stack merge commits. The new work is the six commits from 4845a7e720 to 7912af56d0. Base: main 14951bc65d.

What the rebase changed (besides the merge bases):

  • gradient-serving.tsv: dc2ca8a178 left three rows stale (cuda/kernels.zig for the inkling2_loop image, experts.cuh and cuda/experts.zig for the round_caps switch), so test-gradient-serving failed there. Each row now takes its file's sha256 in the commit that changes the file (C4a, C4d).
  • core/profile.zig cuda_cache and docs/profiles.md name inkling2_loop: Mini has snap_save, and main's cuda_keep_others_test requires every CUDA family with a host prompt cache in the TENSORFOLD_PROMPT_CACHE_KEEP_OTHERS row (it failed on dc2ca8a178 too). The same list scopes TF_CACHE_EVICT on CUDA, so Mini now takes both switches like the other cached families. Both are off by default.
  • C4's own files: 32 two-line comments folded to one line each (tools/zig/lean_check.py's multi-line rule; dc2ca8a178 had 37 new findings with C3's), and zig fmt applied (@intFromEnum to @backingInt, table alignment) in the commits that added them; no code line changed.

What it adds

Loop kernels are a stand-in. families/inkling2/loop.cu and loop.zig (gates and cross-pass messages) follow #4337's arithmetic only so the model runs end to end. They are akol1's H3 and atakann's C2 in #4274, and are meant to be replaced by those slices when they land; I am not claiming them.

Evidence (GB10, sm_121, nvcc 13.0, original checkpoint ed40e7da)

Rerun on this head 7912af56d0 (main's core code under the engine moved, #4493's expert kernels among it; tf-cuda-test md5 a649f696):

check result
kernel contract inkling2 (C1's Mini shapes on main's kernels) 67 kernels pass gates 1-4; 32 controls, 32 red as planted; 0 limit problems
kernel contract, stored experts (C3) 9 kernels pass gates 1-4; 7 controls, 7 red as planted; 0 limit problems
greedy decode 64 tokens, ids identical to the pre-rebase probe (33.6 tok/s)
float64 host reference 48/48 greedy tokens equal (smallest margin 0.029)
prompt in chunks of 1 and 7 last-row logits bit-equal, 32 tokens equal
graphs vs direct launches first-step logits bit-equal, 32 tokens equal
concurrency 4 streams × 64 tokens == solo
prompt-cache state restored == fresh bit-equal at 12 of 25 tokens; another prompt's state as planted control, red
served 256 greedy tokens, text hash identical to b15dd116b0's served run; repeated request equal; 4 concurrent == solo; image part 400; --loops refused by name

Carried from dc2ca8a178 (not rerun): the planted reference control (messages dropped in the float64 reference: 1 of 16 tokens differ, red), and the Metal cross-check below.

Cross-check against #4337's Metal build (8606b655d6), tiny checkpoint ee242a48, teacher-forced on Metal's 48 ids per prompt:

  • the last-prompt top-5 is identical for both prompts;
  • the mean top-1 logit difference is 0.021 (A) and 0.017 (B);
  • there is one top-1 difference outside Metal's tie list, A17, where CUDA is about 0.18 lower. The float64 reference sides with Metal there.
  • Rounding gate/up to bf16 before the softcap (the open question on cuda experts: Inkling 2 Mini's stored NVFP4 and MXFP8 experts in core (C3, proposal) #4365) does not close it. It stays available as an A/B switch, off by default.

Speed (served, greedy, 256 tokens, --no-drafts, A-B-B-A pairs, 4 per cell). The rows were measured on dc2ca8a178; the rebase moved no code on Mini's decode path except the cache-family list, and one served run on this head gives the same figures:

c=1 tok/s c=4 tok/s
dc2ca8a178 (A-B-B-A, carried) 33.3 79.2
this head 7912af56d0 (one served run, not A-B-B-A) 33.3 79.0
#4387 + its 2 load fixes (0 of 4 pairs faster) 5.5 5.5 (3 of 4 requests NoFreeSlot)
#4387 + all 3 fixes (one run) 5.5 not run
vLLM bar from #4274 38.7 102.3

This is still below the vLLM bar, so don't land yet on speed. Where the time goes now:

  • fused attention GEMV 28 %;
  • core NVFP4 expert up 16 % and down 8 %;
  • lm_head 10.5 %;
  • main's tf_ink2_mix 4.2 % (one block per row at decode).

Not in this PR (stated, not hidden)

Lint and host tests on this head: pr-ready gives 0 fail. tools/pr_check.py: 0 errors, lean 165 vs 165, 0 new; zig fmt --check: clean. GB10: test-cuda-host, test-inkling2-cuda-host, test-inkling2-host, test-visit-plan-host, test-dory-host, test-gradient-serving pass. x86: check-native-cuda-host, compile-cuda-tests, test-host, test, test-golden, test-kernel-contract, test-server-security, test-pull-security, fuzz-cortheon, check-release-paths pass, except request_admission_http_test "every way an n-choices request ends returns its places". That test fails on main 14951bc65d on the same x86 box and passes on reruns of this head (x86 once, GB10 three times, the binary alone five times), so it is main's flaky test. Merges cleanly with main 14951bc65d.

Proposed CHANGELOG line: - Inkling 2 Mini serves on CUDA at one rank, text only: 48 loop visits on core/visit_plan, NVFP4/MXFP8 experts in core cuda.experts, graphs and prompt-cache states (#4364, #4365, this PR).

Every Inkling 2 CUDA kernel but the EXL3 expert epilogues now also runs at
Inkling 2 Mini's one-rank shapes (hidden 2,304, 24 over 8 key heads, k/v
width 1,024, 128 experts top 8, floor 8,192, one 201,024-wide vocab row),
each with its planted control. No kernel source changes: the widths were
already arguments. Small's registrations keep their names, shapes and seeds.

Host checks refuse what the kernels cannot hold, by name: Inkling2MixWidth,
Inkling2RouterShape, Inkling2ConvHeads, Inkling2Heads.
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 22, 2026
…tates (C4d) and the experts' round_caps A/B switch
…SwiGLU in core

Core grouped experts gain Format.mxfp8 (e4m3 codes times one E8M0 scale per row per 32 inputs, folded
exactly into the bf16 mma operand, fp32 sums) and Layer.caps, Inkling's soft-capped SwiGLU epilogue
(experts.cuh epilogue 4) on the NVFP4 decode and prompt kernels and on the new MXFP8 ones. NVFP4's
per-expert factor is amax / denominator, each rounded to bf16 (experts_mx.nvfp4Factor, open question F1).

Evidence: stored-experts contract 9 kernels pass gates 1-4, 7 short-K controls red; checkpoint layers 0
and 20 decode bit for bit on every weight of 128 experts, outputs within the fp32 bound; SASS of all
465 pre-existing (unit, sm, function) triples equal main on sm_80/86/89/120/121.
… checked on the GPU

experts_mx.splitGateUp takes stored row 2j to gate j and 2j + 1 to up j before packGateUp (the kernels are
unchanged); a host test plants a code in stored row 1 and requires it in the up part. The checkpoint
reference reads row 2j + m. stored-experts ckpt adds E8M0 bytes 0 to 240 through tf_mxfp8_down_f32
against the host decode (byte 0 = 2^-127).
…dule on it

core/visit_plan.zig walks prelude, core x passes and coda, numbering each
state kind's slots in run order, with enter/leave per pass and taps as
step inputs or the post-norm output. Dory's schedule.build now uses it;
its Step, Schedule and tests are unchanged (test-dory-host 43 pass,
3 skip, same as main).
…an, controller and cross-pass names

inkling2_loop parses its loop_config (is_varloop refused, core in whole blocks, passes >= 2, rank <= 128) and
counts the drafter's taps by visit. The plan walks the visits through core/visit_plan.zig with a sliding, full
and conv slot kind. names.zig adds the four controllers a core layer and the two cross-pass query tables; each
layer's expert precision stays read from its w13 dtype. The quantization_config goes through core.modelopt
(admitByTensors, std-only modelopt_config.zig split out so host-only tests import it). Fixtures: Mini's
config.json and its two headers folded (1244 + 54 tensors, sha256 of the unfolded lines).
…ates, core experts

Weights load layer by layer through core.checkpoint (ModelOpt admitted by core.modelopt). Experts run as core
cuda.experts: NVFP4 in L0-19 and MXFP8 in L20-23. Each stream holds 48 visit slots (40 sliding, 8 full, 48 conv).
The loop mix and controller gates (loop.cu) stand in for C2/H3 and use ashhart#4337's arithmetic. A float64 host
reference (mini_ref.zig) checks the greedy tokens. tf-cuda-test inkling2-mini runs on the real checkpoint:
- greedy output is coherent;
- a prompt cut into chunks of 1 or 7 gives bit-equal last-row logits and equal tokens;
- 4 streams together give the same tokens as each alone.
…): inkling2_loop, text only

Each stream gets a cache slot of 48 visit slots. A prompt takes one 512-row chunk a step. A round runs one-row
windows over every stream in a single forward. It offers no drafts and no copies: a conv state has no rollback here.
Refused by name before any load: --loops (the pass count comes from loop_config), a drafter (C5) and captured
kernels. A prompt holding the image token is refused (C6). Streams are fitted to the room at open, as in Dory.
…ates spread over the GPU

- Decode forwards of n one-row windows replay as CUDA graphs keyed by n.
- A one-row forward runs q, gate, rel, sink (and k, v when they share the input) as one product. It uses a single
  packed buffer per layer, with views pinned to the parts' own K slices, so the bits are unchanged.
- Before this, the loop gates ran on 1-3 blocks at decode, about 35% of GPU time. They now spread over rank and
  output blocks. Each output keeps its summation order.
Greedy ids on the real checkpoint are identical to C4a. c=1 is 22 -> 33 tok/s, c=4 63 -> 79 tok/s.
The server's default drafts flag is no longer refused: there is no head, so nothing is drafted.
The tiny checkpoint's 128-wide rel_logits_proj is zero-padded to the kernels' 1024. Mini's is uploaded as stored.
tf-cuda-test inkling2-mini-xcheck compares top-2 logits against ashhart#4337's Metal forward on prompts teacher-forced on
another engine's tokens.
…A/B switch

Prompt-cache states:
- A stream's state at a prompt mark holds each of the 48 visits' K and V: the full caches through the mark, and
  the sliding rings' last 1,023 positions. It also holds every visit's four conv states.
- The states are saved and restored through the native store's snap_* hooks.
- tf-cuda-test checks restored == fresh bit-equal. Its planted control restores another prompt's state and goes red.

The round_caps A/B switch:
- experts.Layer.round_caps rounds the gate and up sums to bf16 before Inkling's soft caps, in the EPI 4 epilogue
  (a negative up cap). It is off by default and the default bits are unchanged.
- The float64 reference and the tests take INKLING2_ROUND_CAPS=1.
- On the tiny checkpoint it does not close the one CUDA-vs-Metal top-1 difference outside Metal's tie list.
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
… drop ashhart#4387's loop engine and port its serving checks

ashhart#4387's separate loop engine advertised structured output it always refused and duplicated ashhart#4441's registered path. Its draws, resume and two-stream checks now run against ashhart#4441's Mini; copy drafting is not checked, as that engine has no draft path.
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
@jschmied

Copy link
Copy Markdown
Contributor Author

Closing as superseded. Mini on CUDA now goes through #4387's engine: #4640 for correctness, and #4697, #4718, #4728 and #4729 for speed. Those four take it from 5.6 to 28.2 tok/s stacked, bit-equal to #4640, and a PR sharing one forward across streams follows. This stack would be a second Mini engine beside it (see #4387, comment 7092191800). The branch stays on my fork, so it can be reopened if a piece of it is wanted. The likeliest candidate is #4365's core NVFP4/MXFP8 expert entries, if Mini or another family moves onto core experts.

@jschmied jschmied closed this Nov 23, 2026
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
… of origin/main brought back unreachable

ashhart#4441's engine serves inkling2_loop here (as 9f542e6 decided); the merge re-added cuda_native, loop_* and the
loop_math image and contract tests without wiring them.
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
's engine

Ports jschmied's crossPrompt check (c79a58f) from origin/main's serving tests.
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.

1 participant