Skip to content

Inkling-2-Small: Add grouped-expert and vision kernels - #4127

Open
ajensenwaud wants to merge 19 commits into
ashhart:mainfrom
ajensenwaud:ink-k-experts
Open

ajensenwaud wants to merge 19 commits into
ashhart:mainfrom
ajensenwaud:ink-k-experts

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Runs Inkling 2's routed experts on core's EXL3 grouped-expert path, which gains 32-member tiles, an item list for any codebook and a soft-capped SwiGLU epilogue. The experts are EXL3 only. It also adds the vision tower, which runs its attention and scaled residual add on core's ViT kernels. The image placeholder spans move to one core module shared with RADIO, MiniMax M3 and Qwen 27. Nothing serves them until the family PR at the top of the stack.

Checks on this head

  • Head 012d456f3; lean checker 165 on the base, 165 on this head, 0 new.
  • zig build test-inkling2-cuda-host test-inkling2-host test-gradient-serving compile-cuda-tests test-exl3-cuda-host test-minimax-cuda-host test-omni-video-host test-qwen27-equality-host test-qwen27-plans-host test-glm-exl3-prompt-host -Dfixed-cpu: 1,436 of 1,453 tests, 17 skipped; the steps cover every family the shared changes touch.
  • zig fmt --check build.zig zig and git diff --check: clean. CI: pending.

Receipt

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

Kernel contract
  • Registered: core EXL3's tf_exl3_grouped_wide_2 and tf_exl3_gateup_capped, core ViT's vision_kernel<64, 8> and tf_vit_pointwise_gamma, and the family's tf_ink2v_embed and tf_ink2v_rope. Every existing function in the shared images compiles to the same SASS on nvcc 13.0 and 13.3.
  • GB10 (sm_121), 24 November, on this head: kernel-contract inkling2 gives SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 22 controls: 22 red as planted, 0 missed; 0 limit problems.
  • The shared kernels this stack changes pass under their own filters too. exl3, act, vit and minimax show the same limit problems on the head as on main, and no failure that main does not show.
  • Gate 5: records for nvcc 13.0 and 13.3 on sm_80, 86, 89, 120 and 121; 13.2 stays pending. The capped epilogue, now rounded op by op, compiles to the SASS its old text has at the glue kernels' flags, with the same registers.

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

@ajensenwaud @ashhart I checked the expert and vision stage at 6c524aeff with Zig 0.17.0. The shorter rerun to put beside this head is zig build test-inkling2-cuda-host test-gradient-serving compile-cuda-tests -Dfixed-cpu --summary all. It passed 18 build steps and all 20 tests on Linux x86-64.

My test merge into 1ece6e6db conflicted in the changelog and the zig/src/cuda/kernels.zig checksum row. I kept main's changelog for this local check and regenerated the pin from the merged bytes (817c8a5a53ea0cacd3aafb56e5c7e8268dec53ff5fe3059e19b7cbf5d2882511). The two host targets passed all 20 tests on M5 Max after that. The expert and vision kernel device checks remain separate.

On the rebased head 027979864, the trial merge into 37fa51d23 was clean. On M5 Max with Zig 0.17.0, zig build test-inkling2-cuda-host test-gradient-serving -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all passed all 20 host tests, including the new checksum fixture. The stacked glue stage has the same source tree as the current #4126 head.

Igor Lessio - AIFLOW LABS

ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 21, 2026
@ajensenwaud ajensenwaud changed the title Inkling 2's expert and vision kernels under the contract Inkling-2-Small: Add grouped-expert and vision kernels Nov 21, 2026
@jschmied

Copy link
Copy Markdown
Contributor

Shared-core review at 0279798649, read against main fa13df5dd1. I read code only (no build, no GPU), as groundwork for Inkling 2 Mini (#4274), which builds on this stack.

Blocker for Mini (C6)

  • The decoder width is hard-coded. src/families/inkling2/vision.zig:15 sets hidden = 4608 (and proj_inter = 4096 at :14), used at :160, :278 and :355. The parsed config.Vision.text_hidden and proj_hidden (config.zig:99-100) are ignored.
    • Mini's text_hidden_size is 2304, so proj_out fails its {4608, 4096} check, and the splice would copy 4608-wide rows.
    • Fix: size proj_out, the splice rows and scratch from the config at Tower.load, and test both widths.

Copies of core code

  1. vision.cu:23 attend is core's vision_kernel (kernels/cuda/prefill_attention.cu:184-309). diff -w differs only in the signature.
    • Fix: instantiate vision_kernel<64, 8> next to :336-340, add {.dim = 64, .warps = 8} to src/cuda/vit.zig:276, and call vit.Attention.full.
  2. experts.cu:24-253 forks kernels/cuda/exl3_grouped.cuh:12-74 (GroupedArgs, warp_tiles, grouped_body). The new parts are the 32-member tiles, an item list and a sequential warp sum.
    • A second grouper: tf_ink2x_group (:253) adds a second item-list format beside src/cuda/grouped.zig:34,64 (Router.route, shared by the MoE families). Core's exl3_experts.zig:190 runWith(Items) already consumes that format.
    • A second launch sequence: experts.zig:69 repeats runWith's.
    • Fix: add the tile width and an items mode to core grouped_body, lift the .mcg-only gate at exl3_experts.zig:210, and add the softcaps as an act_mode. If the new grouper is faster, it can replace tf_exl3_group for every caller.
  3. Image placeholder spans: vision.zig:313/344/352 (Span, cut, splice) is the fourth copy, after radio/rows.zig:8,62,74, minimax_m3/cuda_vision.zig:35,280 and qwen27/image_rows.zig:9. RADIO's copy carries a u32-overflow fix the others lack.
    • A core image-rows module would fix this once, and gives Mini C6 one place to change.
  4. Orientation: image.zig:74 orient4 copies core/picture/picture.zig:120-133.

Correctness

  • Device trap: experts.cu:168-177 calls __trap() for K2 outside 2..8, which kills the context. Core handles 2..16 (exl3_grouped.cuh:118-132).
    • Fix: refuse it by name on the host in experts.run, with a test.
  • Untested refusals: BadExperts, ImageTooLarge, ImageGrid and ImageTokens have no expectError test; ImagePlaceholders is the only one.
  • PR body: the experts are the EXL3 path with fp16 activations. The body could say "EXL3 only". The NVFP4/MXFP8 path agreed in docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274 (decoded in registers, bf16, FP32 sums) belongs on core src/cuda/experts.zig, not here.

Nits

  • Generic ViT ops: tf_ink2v_scale_add could be a gamma mode on vit.cu:67 tf_vit_pointwise. tf_ink2v_rope is the third ViT axial RoPE in the tree, after MiniMax M3 and dots, with a different pair layout. A pair-layout parameter on one core RoPE, or a one-line reason, would settle it.
  • Line length: two lines in build/cuda_kernels.zig are 150 and 129 columns.

The kernel contract has a planted control for every one of the 7 kernels.

@jschmied

Copy link
Copy Markdown
Contributor

@ajensenwaud, ef8a71a40e is a rebase onto main 362107c4c9: the PR's own 16 files are byte-identical to 0279798649, so the points in #4127 (comment) still apply to this head. The one that blocks Mini is first:

  • src/families/inkling2/vision.zig:15 still hard-codes hidden = 4608; Mini's text_hidden_size is 2304, so C6 in docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274 can't load its proj_out.
  • experts.cu:189 still calls __trap() for K2 outside 2..8 instead of a refusal by name on the host.
  • vision.cu:23 is still core's vision_kernel body, now labelled verbatim, rather than an instantiation of it.

The description still names head 6c524aeff and main c94e65d33.

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks, @jschmied. Everything you raised is in 85539e278, on main cc645a54b.

  • Decoder width. The projector, the splice rows and the scratch now take their sizes from the config. Host tests cover Small's 4,608 and Mini's 2,304.
  • Vision attention. The tower runs on core's vision_kernel<64, 8> through vit.Attention.full, and the family's attend is gone. The other 14 instances in that file compile to the same SASS.
  • Grouped experts. Core grouped_body gained 32-member tiles, runWith takes any codebook in items mode, and the soft caps are a new act_mode. Inkling now routes with Router.route and launches through runWith, so the family's kernels, grouper and launch sequence are gone. Every existing function in exl3_experts compiles to the same SASS on nvcc 13.0 and 13.3.
  • Image spans. One core.image_rows module, built on RADIO's version with its overflow fix, now serves RADIO, MiniMax M3, Qwen 27 and Inkling. Each family keeps its own splice.
  • Orientation. orient4 uses core picture's pixel map, and a test checks it against finish for every orientation.
  • Device trap. The host refuses bit widths the grouped kernels cannot decode, by name and with a test. The range is now core's 2 to 16.
  • Refusal tests. BadExperts, ImageTooLarge, ImageGrid and ImageTokens each have an expectError test.
  • ViT ops. tf_ink2v_scale_add is now a gamma mode on core tf_vit_pointwise. The rotary stays in the family with a one-line reason, since its pair layout differs from MiniMax's and dots'.
  • Body and line length. The description now says the experts are EXL3 only, and the two long build lines are wrapped.

A GB10 run (sm_121) on 430c8f708, whose kernels compile to the same SASS as this head, gives kernel-contract inkling2: 53 kernels pass gates 1-4, 32 controls red as planted, 0 limit problems. The exl3, act, vit and minimax filters show no failure that main lacks. The new wide kernel is bit-equal to tf_exl3_grouped_2 on all 13 shapes.

@jschmied

Copy link
Copy Markdown
Contributor

@ajensenwaud, I checked 85539e278 on a GB10 (sm_121, driver 615.71.09, nvcc 13.0, -Dsm=121), with main cc645a54b run the same way. Our points are settled.

tf-cuda-test kernel-contract this head main
inkling2 SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 22 controls: 22 red as planted, 0 missed; 0 limit problems 36 pass, 18/18 red
exl3 22 pass, 13/13 red, 7 limit problems 20 pass, 11/11 red, the same 7
act 54 pass, 48/48 red, 2 limit problems the same
vit 21 pass, 1/1 red 19 pass
minimax 26 pass 26 pass
  • Counts: 53 kernels and 32 controls is the stack at Inkling-2-Small: Add DSpark drafter kernels #4128's head; this PR alone gives 41 and 22. The limit problems under exl3 and act are the same launches on main (tf_exl3_prompt_*, tf_ctl_exl3_grouped_old_*, the qmm_prefill fusion and d3_router_compact).
  • Host: test-inkling2-cuda-host test-inkling2-host test-gradient-serving compile-cuda-tests -Dfixed-cpu passes 21/21 steps, 51 of 55 tests with 4 skipped. The install builds 217/217.
  • SASS: I compiled the shared images for sm_121 with the build's flags. Every main function in exl3_experts (15), vit (11), prefill_attention (14), act_rows (11) and minimax_m3 (17) is identical at this head.
  • Code: I checked each fix:
    • The width comes from the config (vision.zig:143,157-158,276), with a test at :388 for both 4,608 and 2,304.
    • The tower calls vit.Attention.full (:285) on vision_kernel<64, 8>.
    • The experts run on core runWith with items and act_mode 3.
    • core.image_rows serves all four families.
    • orient4 uses picture.orientedFrom.
    • experts.zig:70 refuses widths outside k2 2 to 16, with a test.
    • The four refusal tests are in.

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks. I assume there is nothing more to be done, based on your message?

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the current standalone d8095191 head on main 7d243251. The trial merged cleanly. On M5 Max with Zig 0.17.0, it passed 53 host tests with four skips and compiled the native Linux ARM64 CUDA target. The separate CUDA test executable build passed all ten steps.

zig build test-inkling2-host test-inkling2-cuda-host test-qwen-serving-host \
  test-gradient-serving check-native-cuda-host \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dcpu=baseline \
  -Doptimize=ReleaseSafe -j2 --summary all

These cover the current host roots and serving pins, including the two updates also carried by #4128. The posted GB10 device run remains tied to its earlier head.

Igor Lessio - AIFLOW LABS

@jschmied

Copy link
Copy Markdown
Contributor

@ajensenwaud, yes, nothing more from my side. My GB10 run was at 85539e278. The commits since then, up to d8095191, carry the Qwen image-row exports and the dense serving pin and leave the kernel sources unchanged, so I see no reason to rerun on the device. If ashhart wants a device receipt at the final head, I'll run it.

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 kernel-contract run on the RTX 5060 Ti (jw16, boot fc0f7ff9) at head 84b4d2c, tf-cuda-test kernel-contract inkling2 — build: aarch64 -Dcpu=baseline -Dsm=120, nvcc 13.0 (DGX Spark build host; records compiler: nvcc 13.0).

SUMMARY 51 kernels: 51 pass gates 1-4, 0 fail, 0 known findings; 33 controls: 33 red as planted, 0 missed; 0 limit problems; gates 265967 ms. Every inkling2 kernel carries exact sm_120 records (thread counts match the driver caps, registers and shared bytes exact).

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @ajensenwaud. The shared expert and vision paths, configured widths and refusal checks address the source concerns. The new comparison also captures the intended capped arithmetic and layer-scale rounding, including controls that detect fused operations.

The kernel slice is ready for comparison after we combine it with current main. That integration needs to retain Mini's two arithmetic baseline kernels and its newer tail cases. The remaining evidence is the new comparison's result and the resolved tree's focused contracts and unchanged shared-function arithmetic. The older receipts do not yet qualify Small serving or Mini vision.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged the revised 467dbe87be into 4c79cfe346, keeping the current Mini baseline registrations and tail cases in the contract file alongside the new vision fields. The other merge conflict was the gradient-serving pin for cuda/kernels.zig.

The first host compile stop was the testVision fixture in zig/src/families/inkling2/vision.zig. Current main's config.Vision requires eps. Adding .eps = eps to that fixture in scratch got this check green on M5 Max, with 53 tests and 19 steps passing.

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

The second command still stops at contract_inkling2_experts.zig because the auto-merged contract_inkling2_experts_grouped.zig drops main's Group case. The reference file also drops the rows/wide forms, and the two tf_ink2x_rows and tf_ink2x_wide symbols and launch records are removed. The integration needs to carry those baseline implementations and cases through together before the new comparison can run.

Igor Lessio - AIFLOW LABS

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Results on your head 467dbe87b, before it is combined with current main:

  • Comparison. Your new capped-epilogue and layer-scale comparison passes in test-inkling2-cuda-host, 53 of 53 tests.
  • Contract. On a GB10 (sm_121, nvcc 13.3), kernel-contract inkling2 exl3 vit act minimax passes 158 of 160 kernels, and all 94 planted controls go red. The two failures are main's GLM wide-expert cases, which declare fp32 sums their test does not simulate. The 27 limit problems are the same ones main 68ff0ad8e shows without this PR under the same filter.

ajensenwaud and others added 19 commits November 25, 2026 11:51
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.
…ls, bit for bit

With ashhart#4127, Inkling 2's softcapped gate/up epilogue and vision layer scale
come from core (tf_exl3_gateup_capped, tf_vit_pointwise_gamma) in place of
main's family kernels (tf_ink2_gateup, built at --fmad=false, and
tf_ink2v_scale_add). A host test writes both kernels' arithmetic at their
rounding points: every product and sum on its own, the same order, the shared
rotation and the fp16 or bf16 store. Over 512 random 128-column blocks with
saturating and non-finite inputs, and 65,536 layer-scale values, the old and
new forms give the same bits. A control contracts one product into the
rotation's first sum, as core's fmad=true flags would without the explicit
_rn operations, and it differs, so the comparison can see one fused rounding.
@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the current 6dd60634f5 head in a clean trial merge with 0a5c699c8. The host compile stop is still in testVision in zig/src/families/inkling2/vision.zig: its Vision literal needs .eps = eps. With that one fixture change, all nine host targets finished successfully (261 tests rerun, three skipped, with the unaffected targets cached). The native server and CUDA contract runner then cross-compiled for ARM64 Linux in 21/21 steps.

zig build test-inkling2-cuda-host test-inkling2-host test-gradient-serving test-exl3-cuda-host \
  test-minimax-cuda-host test-omni-video-host test-qwen27-equality-host test-qwen27-plans-host \
  test-glm-exl3-prompt-host -Dfixed-cpu -j2 --summary all
zig build check-native-cuda-host compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dfixed-cpu -j2 --summary all

The runner now compiles, but the trial tree still drops main's tf_ink2x_rows and tf_ink2x_wide kernels and their comparison registrations. Those are the two Mini baselines Ash asked to keep for the comparison. Please carry their registrations and cases into the integrated tree before collecting the CUDA results.

Igor Lessio - AIFLOW LABS

ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 25, 2026
…ls, bit for bit

With ashhart#4127, Inkling 2's softcapped gate/up epilogue and vision layer scale
come from core (tf_exl3_gateup_capped, tf_vit_pointwise_gamma) in place of
main's family kernels (tf_ink2_gateup, built at --fmad=false, and
tf_ink2v_scale_add). A host test writes both kernels' arithmetic at their
rounding points: every product and sum on its own, the same order, the shared
rotation and the fp16 or bf16 store. Over 512 random 128-column blocks with
saturating and non-finite inputs, and 65,536 layer-scale values, the old and
new forms give the same bits. A control contracts one product into the
rotation's first sum, as core's fmad=true flags would without the explicit
_rn operations, and it differs, so the comparison can see one fused rounding.
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

@ajensenwaud, our GB10 checks of this head against main, after the rebase:

  • Qwen3.8-27B, text: prompt tokens equal in all rows; speed level at 1 and 4 streams.
  • Images: byte-identical replies in every run for Qwen3.8-27B and for Nemotron Super VL (RADIO). That covers the shared image rows and picture changes for those two families.
  • Qwen3.8-27B EXL3: queued.

The shared EXL3 grouped-expert kernels this PR changes are also used by DeepSeek-V4.1, GLM, Hy4-flash, MiniMax M3 and Muse Spark. We don't have those EXL3 MoE checkpoints. Could you post a token-equality receipt for one of them: main against this head, same checkpoint and revision, greedy, prompt and decode, with full output-token hashes? Then this can go to our landing queue.

  • Synthena

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.

5 participants