Skip to content

cuda ernie5_5: the router, two sigmoid scores and the top 10 of score + bias, under the kernel contract - #5368

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-route
Dec 2, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-route

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

tf_ernie55_route, in a new ernie5_5_moe image: ERNIE 5.5's router, as vLLM-ERNIE's ernie5_5_routing forms a row's picks, one row a block of 64 threads. Each of the 512 experts is scored from its two routers' fp32 logits (gate.weight's row, then weight_1's) as sigmoid(l0) + sigmoid(l1); the top 10 of score + correction bias are picked by core's row select (tf_topk::select_row: ties to the lower id, a NaN never picked ahead of a number, the picks in ascending ids); and each pick's weight is its score (without the bias) over the picks' summed scores, at least 1e-20, times the expert's learned scale. It writes the int32 picks and fp32 weights core's combine takes. Nothing launches it yet, so served output is unchanged.

This is the router your answer 2 on #4926 asked for: an ERNIE kernel that produces the picks and weights core's combine consumes, with the two-sigmoid score, the bias-only selection, the normalization and the per-expert scale together, not another moe_glue route mode (moe_glue's sigmoid routes take one sigmoid of the summed logits and one scale factor).

Three places differ from the vendor's torch routing in bits, not in the rule:

Checks on this head

  • On your rebase (fa89489b0f, on bfc564cb6a), on a GB10 (sm_121): the tree cleaned (git clean -xdf) with an empty global cache, zig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=... -Dsm=80,86,89,120,121 (nvcc 13.0.88): 0 errors. On the GPU, tf-cuda-test ernie5_5-moe: SUMMARY ernie5_5 moe: 1 kernels, 1 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; tf-cuda-test kernel-contract ernie5_5: SUMMARY 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 19 controls: 19 red as planted, 0 missed; 0 limit problems. Against its parent bfc564cb6a (your earlier restack of cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326, on main 388ec8c487), built and run the same way: kernel-contract-limits gives both the same 205 stale records and the same RED and FAIL lines, apart from this tree's 5 tf_ernie55_route lines (PASS ... (record current)); the one fatbin change is the added image ernie5_5_moe; the other 205 are the parent's to the byte. Host (zig build -Dfixed-cpu): test-ernie5_5-host 44/46 tests passed (2 skipped), test-gradient-serving 1/1 tests passed, test-kernel-contract 368/368 tests passed. The items below are from before your rebase.
  • Head commit: 6da578b2ea cuda ernie5_5: the router, two sigmoid scores and the top 10 of score + bias, under the kernel contract. 6da578b2ea differs from e9b17eb8dc only in the CHANGELOG line's pull request number. The GB10 gate below ran on 3b53b1fb58, this commit's code on cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's earlier head e2b9fb5d63 (main 469f1f7fd8); since, the stack was rebased onto main 8b1eaff2c7 and then onto cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's fixed head, and this commit's own lines are unchanged (the same patch id without context). On e9b17eb8dc, on Windows, zig build compile-cuda-tests, test-kernel-contract and test-gradient-serving, and pr_check (below).
  • Lean checker (tools/pr_check.py --base c100a00a31 --pr 5368, this commit against cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's here): 123 problems on both, 0 new; 0 errors. The 123 are inherited from main.
  • Tests run, with the command and pass, fail and skip counts (Zig 0.17.0, nvcc 13.0.88):
    • GB10 (sm_121): cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's head then (e2b9fb5d63) and then 3b53b1fb58, each in its own worktree with an empty global cache, zig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=... -Dsm=80,86,89,120,121: 0 errors. On the GPU, tf-cuda-test kernel-contract-limits zig-out/fatbin gives the five tf_ernie55_route lines PASS ... (record current) (40 registers at sm_80, 45 at 86 and 89, 50 at 120 and 121, 5,272 static shared bytes, bound 64), and its other lines are the base's but one: tf_nemo_router_tiles at sm_89, 196 registers (record stale) in the base's build and 184 (record current) in this one, the router-tiles entries whose compiles give more than one form (cuda: the shared router tiles read their shared-memory rows as 32-bit words #5360), which this commit does not touch. tf-cuda-test ernie5_5-moe passes gates 1-3 (gate 3 at 3 shapes, exact by its own check; gate 4 n/a, no sums) with both controls red as planted, and kernel-contract ernie5_5 passes its 14 kernels with all 19 controls red (the base's 13 and 17; below). zig build test-ernie5_5-host 42 of 44, 2 skipped; test-kernel-contract 353 of 353; test-gradient-serving 1 of 1. moe.cu's PTX: 33 compiles at each of compute_80, 86, 120 and 121 (3 with address randomization off, 30 on), one form at each.
    • Windows: on 883a7e8b42 (this commit on cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's e2b9fb5d63), zig build test-ernie5_5-host 42 of 44 passed, 2 skipped (main's), and test-kernel-contract 46 of 46 steps, 353 of 353 tests; pr_check 0 errors. On e9b17eb8dc, this head but for the CHANGELOG line's number: zig build compile-cuda-tests 12 of 12 steps; test-kernel-contract 46 of 46 steps, 356 of 356 tests; test-gradient-serving 1 of 1; pr_check --base c100a00a31 0 errors.
    • WSL 2 (x86-64): ptxas -v of moe.cu at the five SMs (13.0.88): tf_ernie55_route takes 40, 45, 45, 50 and 50 registers and 5,272 static shared bytes; at sm_80 it has a 16-byte stack frame with 12 bytes of spills, and none at the other SMs (the PTX has no calls; core's topk_rows.cu, which takes the same select_row with a row length it reads at run time, has none at sm_80). On this head: git diff --check against cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's commit here clean; zig build compile-cuda-tests 12 of 12 steps; test-ernie5_5-host 43 of 45, 2 skipped; test-kernel-contract 46 of 46 steps, 356 of 356 tests; test-gradient-serving 1 of 1; tools/zig/check_cuda_sources.py on moe.cu with clang++ 6 of 6; host_tests_test OK; CI's pytest from the root (-q -rs) 861 passed, 116 skipped, 827 subtests passed, the same skips as main 8b1eaff2c7's.
  • CI: (after the push)
  • Not run, and why: the contract on GPUs other than the GB10 (sm_121); the other four SMs are covered by their limits records only. No served path, since nothing launches the kernel.

Receipt

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: tf_ernie55_route (new; replaces none), records for sm_80, 86, 89, 120 and 121 in zig/src/core/contract/ernie5_5_records.zig.
  • A planted control for each new kernel, and each one fails as planted: tf_ctl_ernie55_route_one_sigmoid (one sigmoid of the two logits summed), red at shapes ("at 16x512x10: row 0: expert 170 ranks 1.55702725, unpicked expert 31 1.95733346"), and tf_ctl_ernie55_route_biased_weights (weights from score + bias), red at shapes ("at 16x512x10: row 0 slot 0: weight 0.13486953 where float64 gives 0.13309110").
  • Each backend's SUMMARY line and exit status: SUMMARY ernie5_5 moe: 1 kernels, 1 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed, exit 0; kernel-contract ernie5_5: (filtered) SUMMARY 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 19 controls: 19 red as planted, 0 missed; 0 limit problems, exit 0. CUDA only (no HIP, Metal or XPU image).
  • Chips I could not run: sm_80, 86, 89 and 120 GPUs (their limits records come from the fatbins).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (the host tests need only Zig; the contract's controls go red as planted; without a GPU or -Dnvcc the CUDA steps are not built, as for every image).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off (nothing launches the kernel yet).
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo (no served path changes).
  • No precision traded for speed. If the bits change, the description says which sums change and why (the scores and their sum in fp32 with round-to-nearest steps, the sum in id order; the three differences from torch above).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled (no served path changes).

@ashhart

ashhart commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you, @Bizuayeu. The unlaunched router looks safe to A/B.

I confirmed the two FP32 sigmoids, explicitly rounded additions, exact lower-ID tie handling, ascending-ID score sum, denominator clamp, and final division and multiplication. I also confirmed that only the CUDA contract runner imports this module, so serving output is unchanged today. The planted controls cover two meaningful routing mistakes.

The remaining evidence limit is important. The near-tie allowance can accept a different expert set, and the weight allowance can accept different FP32 values. Also, the host function named vendor shares the implementation's score and rank helpers, so it is not an independent upstream golden. These do not block an A/B of the unlaunched kernel, but stronger bit-level checks are needed before serving integration.

The supplied live run names an older head, so the final integrated tree still needs the synthetic CUDA contracts on GB10 sm_121 and RTX 5090 sm_120, with the five-SM compile and resource checks. No checkpoint is needed for the current unlaunched scope. Current-main integration has one conflict in zig/tests/fixtures/gradient-serving.tsv; its resolution must preserve main's annotations while adding the new image pin. The seven prerequisite ERNIE commits must also stay in order.

  • Synthena

@ashhart

ashhart commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@Bizuayeu, one small thing: this PR is still marked as a draft, so our landing train skips it. Mark it ready for review when you're happy with it and it goes straight into the next train.

  • Synthena

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

[...] it goes straight into the next train.

(#5368 (comment))

The five commits under the router are on main now through #5538, so this branch conflicts with main and only the router commit (e68d5b2f1c) is left. I can restack that one commit on main and retake its GB10 receipts, or leave the restack to you as before. Which would you prefer?

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks, @Bizuayeu. Five of the six kernels in this branch are already on main, with the same messages: the DSA indexer's keys, the mHC post side, hc_head, the mHC broadcast and the HCA compressor. Main has had a few fixes on top of them since.

The one piece not on main yet is the router commit: two sigmoid scores and the top 10 of score + bias. It reads well to us. The summation order is fixed, ties go to the lower id, a NaN ranks last, and k is refused past the top-k bound before the launch. We'll rebase this branch down to that one commit ourselves, so there's nothing more you need to do for the other five.

  • Synthena

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed at this head, restacked by us onto main from the router commit (authorship kept). On a GB10 (sm_121) the ernie5_5-moe contract passed every gate with both planted controls red, and the ernie5_5 kernel contract passed. Nothing launches the router yet, so served output is unchanged. This head's CI passed.

  • Synthena

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed at this head, rebased onto main by us after #5794 landed (registrations only; authorship kept). On a GB10 (sm_121) the ernie5_5-moe contract passed every gate with both planted controls red, and the ernie5_5 kernel contract passed. Nothing launches the router yet, so served output is unchanged. This head's CI passed.

  • Synthena

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Rebased onto main beside #5851 (the two test registrations in zig/tests/cuda/main.zig kept side by side); the router commit is unchanged. Its previous train passed local CI and device cells before the landing conflict, and its kernel contract run was clean.

  • Synthena

… + bias, under the kernel contract

tf_ernie55_route, in a new ernie5_5_moe image, routes a row as vLLM-ERNIE's ernie5_5_routing does: each of the 512
experts scored from its two routers' fp32 logits as sigmoid(l0) + sigmoid(l1), the top 10 of score + bias by core's
row select (tf_topk::select_row: ties to the lower id, the picks in ascending ids, as the vendor's slots but for
ties at the k-th value, which it puts last), and each pick's weight its score over the picks' sum, at least 1e-20,
times the expert's learned scale. It writes the
int32 picks and fp32 weights core's combine takes. moe_glue's sigmoid routes sum the logits before one sigmoid and
scale by one factor, so ERNIE's router is a family kernel (ashhart#4926).

The picks and weights are checked against float64 (ernie5_5/route.zig, whose host test holds it to the vendor's
torch routing): the same ranks with only near-ties swapped and exact ties to the lower id, and the weights within
2^-20. Two controls: one sigmoid of the two logits summed, and weights from score + bias.
@ashhart
ashhart merged commit 37ee1c5 into ashhart:main Dec 2, 2026
5 of 10 checks passed
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thank you @Bizuayeu. 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.

2 participants