Skip to content

cuda: add routed EXL3 rotation with FP16 products - #3607

Closed
francip wants to merge 5 commits into
ashhart:mainfrom
kortexa-ai:kortexa-ai/inkling2-exl3-half-rotate
Closed

francip wants to merge 5 commits into
ashhart:mainfrom
kortexa-ai:kortexa-ai/inkling2-exl3-half-rotate

Conversation

@francip

@francip francip commented Nov 16, 2026 •

Copy link
Copy Markdown

What this changes

Adds one shared routed EXL3 input rotation that rounds products to FP16 before the existing FP32 Walsh transform. The wider-product operator remains unchanged; this adds no family loader or serving path.

Checks on this head

  • Head commit: 71b4d47e3c0bbb485e4e48547cf601f700cc73bd; GPU-measured source 0193678bfae7e7c4da02ec53784957048662b477. Executable sources are unchanged; later changes contain receipts and two exact source-identity fixture hashes.
  • Lean checker: base 221, head 221 inherited findings; zero new. pr_check.py --base upstream/main: 0 errors, one advisory: no Unreleased bullet naming cuda: add routed EXL3 rotation with FP16 products #3607.
  • Tests: prior unchanged executable source: zig build -Dfixed-cpu test-host tf-exl3-routed-half-contract --test-timeout 20m -j6: 2116/2116 steps succeeded, 7372 tests passed, 66 skipped. zig build -Dfixed-cpu: 33/33 steps. Focused reference tests: 2 passed. zig fmt --check build.zig zig and git diff --check: pass.
  • CI: the previous No GPU run failed the serving source-identity fixture for the two additive exports. The current head refreshes their exact hashes; zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-host now passes 7/7 steps (identity test passed; Qwen checks cached). A planted legacy-serving-source mutation still fails. All other completed checks in the previous run passed; new No GPU and format runs await maintainer approval (action_required), so current-head CI is not yet green.
  • Not run: SM80/86/89/120 device execution; compile records audited for all five targets. Metal/HIP/Windows not run; no implementation changes there.

Receipt

Commands, raw gates and artifact identities.

  • Main against branch: operator-level wrong-rounding controls below; no Inkling serving caller exists on main or this branch.
  • Boxes it reaches: CUDA SM80/86/89/120/121; live checks on two independent GB10s.
  • New switch: none.
  • Environment: Zig 0.17.0, nvcc 13.0.88, driver 580.178.04, Linux, 128 GB DGX Spark; no checkpoint loaded.
  • Paths/platforms: shared CUDA rotation; run and unrun targets listed above.
  • Exactness: independent binary64 reference with declared FP16 output bound; five byte-identical repeats, input/guard checks, FP32-sum stress. No model token/fidelity claim.
  • Main against branch inference numbers: n/a, no serving caller in this change.
  • Decode before/after: n/a, no serving caller.
  • Cold prompt before/after: n/a, no serving caller.
  • New weights/drafter licence: n/a, neither added.
Kernel contract
  • tf_exl3_routed_half_rotate: shared/per-pair inputs × 192/384 experts, all served shapes and edges, registered in the full CUDA runner plus a standalone complete operator runner. Replaces no existing kernel.
  • Controls: unchanged widened-product rotation fails the intended byte comparison in both input modes.
  • Both GB10s, exit 0:
SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems
  • SM80/86/89/120: compiled/audited, no device run.

Checklist

  • Title and description match this head, receipt and scope.
  • Rounding controls fail as planted; new reference/contract tests pass; GPU dependency is absent from host-only reference tests.
  • Comments/docstrings are single lines; measurements are in the receipt.
  • No private identities, hosts, paths or tooling attribution in the outgoing changes/history.
  • Lane rounds: n/a, no serving caller added.
  • Draft/plain, resume/fresh and concurrent/solo equality: n/a, no serving caller added.
  • Arithmetic change is explicit: FP16 product rounding, FP32 transform; existing operators unchanged.
  • Served decode/prefill promotion: n/a, no serving caller added.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @francip for the careful work here. The operator is small and well fenced: the shape checks in zig/src/cuda/exl3_routed_half.zig refuse ragged and overflowing geometry before launch, the binary64 reference is independent of the GPU's butterfly order, and the planted widened-product control proves the test can tell the two roundings apart. The series applies cleanly on current main and adds no lean findings (221 before and after).

We can't take this one as written, though. The reason is the arithmetic, not the code quality.

  1. The FP16 product changes the result compared with main's EXL3 rotation. zig/kernels/cuda/exl3_routed_half.cu:14 computes __hmul(x, suh), so each product is rounded to FP16 before the FP32 Walsh transform. Every EXL3 input rotation on main multiplies in FP32 first:

    • zig/kernels/cuda/exl3_experts.cu:127 (routed, FP16 input)
    • exl3_experts.cu:123 (routed, BF16 input)
    • exl3_experts.cu:257 (tf_exl3_plan_rotate)
    • exl3_experts.cu:278 (tf_exl3_prompt_rotate)
    • zig/kernels/cuda/exl3_linear.cu:116-118 (rot_in_body)

    Your own receipt shows the two disagree: the widened-product control differs from byte 2 at 8x4608x128. The project has a hard rule against arithmetic that changes output tokens, and it applies to opt-in and caller-specific paths too. A routed path that rounds where main's does not falls under that rule.

  2. The FP16 rounding is not part of the checkpoint format. The EXL3 format stores suh as FP16 [K] (docs/recipes/exl3.md:46) and defines the layer as ((x * suh) @ H_K) ... (docs/recipes/exl3.md:78-79, :108). It does not say how the product x * suh is rounded at runtime. Rounding it to FP16 is a choice of arithmetic, not a way of reading the checkpoint, so the exception for a published checkpoint's own weight format doesn't cover it.

  3. What would make it exact: compute the product in FP32, as exl3_experts.cu:127 does (__half2float(x) * __half2float(suh)), then the same fwht128 and __float2half_rn(v * HAD_SCALE). That version is what main's tf_exl3_experts_rot_in already does for routed picks, including the per-pair layout (row = p / slots with slots = 1, and grid.z = 1 for a single matrix). So the loader in Inkling 2 Small: EXL3 support on 2× DGX Spark #3593 can call the existing kernel, with no new one. The test for that caller should be byte equality with main's rotation, not a bound against a binary64 reference.

Other points, in case parts of this come back in another PR:

  • zig/tests/cuda/contract_limits.zig: the shared kernel-contract-limits pass line loses its "every control red" and sm_110 wording for all callers. Please keep the existing messages for fatbins and give fatbinsFor its own line.
  • zig/tests/fixtures/pocket-serving-approved.tsv: approvals in this file, including the hashes on HELD lines, are recorded by maintainers when a change lands. Please leave it out of the PR, and we will update it at landing.
  • A PR that changes Zig needs a ## Unreleased line in CHANGELOG.md naming the PR.

For the record, we ran the full kernel contract at aabede8 on GB10 (CUDA, sm_121). The 4 new kernels and 2 controls all pass and go red as planted, and the limit check for tf-exl3-routed-half-contract passes too (20 registers). That shows the kernel matches its own FP16-product reference. It doesn't change the point above: main's rotations multiply in FP32, so replies would differ from main's.

I'm closing this for the reasons above. The rest of #3593 (the loader and two-rank execution) is welcome on top of main's FP32-product rotation.

  • Synthena

@ashhart ashhart closed this Nov 17, 2026
@francip

francip commented Nov 17, 2026

Copy link
Copy Markdown
Author

Gah, sorry for wasting your time @ashhart . I'll go back and review what the heck happened here.

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