Repository navigation
refactor: references, inputs and compare in float32; drop fp64 from the kernels - #293
Merged
Merged
Conversation
xiaobochen-amd
requested review from
RuibinCheung,
irvineoy,
jiejingzhangamd,
kyle-256 and
zhenhuang12
as code owners
November 19, 2026 08:29
There was a problem hiding this comment.
🟡 Changes recommended
Critical numerical-stability defects on valid finite inputs corrupt reference outputs and can cause validation to accept incorrect results or reject correct ones.
13 open issues
Overflowing subtraction breaks otherwise valid SQNR comparisons · New Non-finite GEMM reference can validate an incorrect kernel · New Magnitude overflow allows incorrect balanced outputs to pass · New Int8 GEMM rounding bound rejects correct outputs after prescaling · New Residual mixing and layer normalization overflow on large inputs · New Residual sum overflows before normalization · New RMSNorm squares overflow for valid large finite inputs · New Sigmoid weight normalization produces NaNs for very negative logits · New Bank and prefix normalization overflows for large inputs · New Latent normalization overflows for valid large projections · New Prefix normalization overflows for valid large inputs · New Stress bound overflow accepts corrupted finite outputs · New Floating-point violation fraction rejects allowed threshold cases · New
What changed in this PR
Moves AKLR’s reference and validation pipeline to float32, aligning it with inference precision and removing the need for float64-specific kernel logic.
Changes:
- Standardizes reference signatures, float32 arithmetic, and declared integer output dtypes.
- Adds score-aware ID comparison and updates comparison, validation, and stress-check calculations.
- Updates tests, authoring guides, tutorials, and knowledge-base citations.
| File | Description |
|---|---|
tests/plugins/sglang/test_reference.py |
Tests router ID swaps for equal and distant scores. |
tests/ops/test_sparse_prefill_reference.py |
Adapts reference calls and comparison tolerances. |
tests/ops/test_reference.py |
Checks output dtypes; removes float64-specific tests. |
tests/op_case.py |
Updates reference calls and passes ID scores. |
tests/core/validation/test_pipeline.py |
Removes float64 overflow-retry coverage. |
tests/core/contract/test_semantics.py |
Adds integer, ID-score, scaling, and decoding tests. |
tests/core/contract/test_schema.py |
Uses float32 fixtures and independent output copies. |
harness/skills/port-generated-kernels/references/new-op.md |
Updates reference and baseline authoring guidance. |
harness/skills/kb/triton/tuning.md |
Updates historical pins and comparison citations. |
harness/skills/kb/triton/moe.md |
Pins historical kernel examples and adjusts citations. |
harness/skills/kb/triton/kernels/kernel_library.md |
Marks removed fp64 kernels as historical examples. |
harness/skills/kb/triton/gluon/wave_ops.md |
Pins a historical kernel citation. |
harness/skills/kb/triton/gluon/mfma.md |
Pins historical matrix-operation examples. |
harness/skills/kb/triton/gluon/memory.md |
Pins a historical memory-layout example. |
harness/skills/kb/triton/gluon/layouts.md |
Pins historical layout examples. |
harness/skills/kb/triton/gemm/small_m_gemm.md |
Updates the determinism-check citation. |
harness/skills/kb/triton/gemm.md |
Adjusts contract and comparison citations. |
harness/skills/kb/triton/gdn.md |
Updates a reference-helper citation. |
harness/skills/kb/triton/authoring.md |
Updates contract citations and historical pins. |
harness/skills/kb/triton/attention.md |
Updates the determinism-check citation. |
harness/skills/kb/pitfalls/baseline_silently_wrong.md |
Updates the baseline-relative bound citation. |
harness/skills/kb/cases/k3_bf16_splitk_narrow_n.md |
Updates the error-bound constants citation. |
harness/scripts/forge_task/assets/aklr_forge_driver.py |
Converts bounded stress comparisons to float32. |
docs/ops_tutorial.zh.md |
Updates Chinese reference and baseline guidance. |
docs/ops_tutorial.md |
Updates English reference and baseline guidance. |
aklr/plugins/vllm/models/muse_spark/reference.py |
Uses float32 decoding and revised reference calls. |
aklr/plugins/vllm/models/kimi_k3/attn_res/reference.py |
Converts residual aggregation to float32. |
aklr/plugins/sglang/models/qwen3_next/reference.py |
Updates reference signatures and float32 decoding. |
aklr/plugins/sglang/models/qwen3_moe/reference.py |
Computes router projections in float32. |
aklr/plugins/sglang/models/qwen3_5/reference.py |
Converts recurrence and attention references to float32. |
aklr/plugins/sglang/models/qwen2_moe/reference.py |
Adds router ID scores and declared integer outputs. |
aklr/plugins/sglang/models/qwen2_moe/contract.py |
Documents adjacent-logit ID swaps in comments. |
aklr/plugins/sglang/models/minimax_m2/reference.py |
Standardizes float32 input decoding. |
aklr/plugins/sglang/models/kimi_k3/reference.py |
Converts projections and gating references to float32. |
aklr/plugins/sglang/models/forward_mla_rocm/reference.py |
Uses float32 decoding for value absorption. |
aklr/plugins/sglang/models/deepseek_v2/reference.py |
Computes router projections in float32. |
aklr/plugins/sglang/models/deepseek_common/reference.py |
Converts normalization and absorption references to float32. |
aklr/plugins/sglang/layers/mla_decode/reference.py |
Standardizes float32 query and cache decoding. |
aklr/plugins/sglang/layers/dsa_indexer/reference.py |
Converts indexing preparation arithmetic to float32. |
aklr/plugins/sglang/layers/dsa_indexer/contract.py |
Clarifies reference-precision commentary. |
aklr/plugins/sglang/layers/dsa_backend/reference.py |
Uses float32 arithmetic and declared page-index dtype. |
aklr/plugins/sglang/layers/attn_residual/reference.py |
Converts residual aggregation to float32. |
aklr/plugins/aiter/situv2_a4w4_moe/reference.py |
Adapts the delegated fused-MoE reference call. |
aklr/ops/topk/reference.py |
Uses float32 scores and declared integer outputs. |
aklr/ops/rms_norm/reference.py |
Converts residual sums and normalization to float32. |
aklr/ops/README.md |
Defines reference, baseline, and ID-score policies. |
aklr/ops/quant/reference.py |
Uses float32 quantization arithmetic and integer exponents. |
aklr/ops/mla/reference.py |
Standardizes float32 decoding and reference signatures. |
aklr/ops/mla_prefill/reference.py |
Converts sparse and variable-length attention to float32. |
aklr/ops/mhc/reference.py |
Converts mixing and normalization references to float32. |
aklr/ops/mega_moe/reference.py |
Updates grouped reference and weight-decoding calls. |
aklr/ops/gemm/reference.py |
Removes float64 paths and standardizes float32 products. |
aklr/ops/fused_moe/reference.py |
Uses float32 decoding and revised helper signatures. |
aklr/ops/attention/reference.py |
Standardizes float32 attention inputs. |
aklr/core/validation/stages/_bench/_evaluation/_reference.py |
Removes float64 retry and supplies ID scores. |
aklr/core/validation/stages/_bench/_evaluation/_comparison.py |
Uses float32 for reference-finiteness checks. |
aklr/core/utils/testing.py |
Uses float32 for distributed timing reduction. |
aklr/core/contract/semantics/_workloads.py |
Uses float32 decoding and encoding for magnification. |
aklr/core/contract/semantics/_dtypes.py |
Removes float64 support and adds float32 encoding. |
aklr/core/contract/semantics/_distributions.py |
Converts distribution checks and sampling arithmetic to float32. |
aklr/core/contract/semantics/_compare.py |
Adds integer comparison, ID equivalence, and scaled measures. |
aklr/core/contract/semantics/__init__.py |
Updates exported conversion helpers. |
aklr/core/contract/op.py |
Simplifies reference calls and adds ID-score discovery. |
Review effort: Max
xiaobochen-amd
force-pushed
the
cursor/reference-fp32-f4ec
branch
from
November 19, 2026 09:27
056a2d6 to
0f4dcd4
Compare
xiaobochen-amd
force-pushed
the
cursor/reference-fp32-f4ec
branch
from
November 20, 2026 03:19
0f4dcd4 to
0d43247
Compare
…ores for router ids References compute in float32 and take no decode argument; inputs are drawn, decoded and encoded through float32; compare measures in float32 (scaled by the peak against overflow) and compares integer outputs as integers. Integer outputs come back in their declared dtype, and validation's float64 retry and DType.FLOAT64 go. A reference module may give <contract>_tie_scores, under which an id that differs only between two tied candidates passes; qwen2_moe_router ties its bf16 logits one bf16 step apart.
51 kernel files rewritten without fp64 (deepseek_v2 fp8 MoE, qwen3_next gated attention, minimax_m2 MXFP4 MoE, qwen2_moe, biased_grouped_topk) and 4 qwen2_moe router+experts files withdrawn. biased_grouped_topk ranks near ties by the reference's own fp32 key instead of a float64 one.
…stress bounds, exact int8 gemm sums
…erify kernel sums its taps in float32
… aiter a6c759b1f runs aiter's untuned gemm_a8w8_bpreshuffle pads m and k but not n of a preshuffled b. At k = 256 its heuristic tile is 256 wide, so n = 32 raised "This GEMM is not supported" in aiter-test since #271; from k = 512 the tile is 32 wide. Checked on MI355X with aiter a6c759b1f: n = 32 fails at k = 256 and passes at k = 512 and 1024.
xiaobochen-amd
force-pushed
the
cursor/reference-fp32-f4ec
branch
from
November 20, 2026 06:02
b54757c to
d169cf6
Compare
zhenhuang12
approved these changes
Nov 20, 2026
zhenhuang12
approved these changes
Nov 20, 2026
ChengYao-amd
added a commit
that referenced
this pull request
Nov 23, 2026
Conflict in models/kimi_k3/api.py: this branch's kimi_k3_kda_verify api stub beside main's _forward_fused route, which now declares sglang 0.5.22 and 0.5.23. tests/plugins/sglang/names.txt regenerated. The kimi_k3_kda_verify reference follows main's #293: no decode argument, inputs read through to_float32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
added a commit
that referenced
this pull request
Nov 23, 2026
…e (as #293) main's references now take (point, row_major_args) and read their inputs through to_float32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
added a commit
that referenced
this pull request
Nov 23, 2026
…ecode (as #293) main's references now take (point, row_major_args) and read their inputs through to_float32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
added a commit
that referenced
this pull request
Nov 23, 2026
…fp8-vc-quant Brings in origin/main through the base branch's new head. Conflict in tests/plugins/sglang/cases.py's GFX950_CONTRACT_IDS: both main's kda_chain_verify_ring and this branch's mla_vc_fp8. The mla_vc_fp8 reference follows main's #293: no decode argument, inputs read through to_float32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
added a commit
that referenced
this pull request
Nov 23, 2026
Conflict in layers/dsa_indexer/reference.py, which main's #293 moved to float32 without decode: this branch's helpers (_turn, _normalized, _scales' floor, negative slots) and dsa_indexer_writer_prepare_reference written the same way, in float32 and reading inputs through to_float32. On the small Points the three dsa_indexer references match the float64 ones but for float32 rounding (2e-11 in head_weights). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 23, 2026
Closed
menghongtao
added a commit
to yueliu14/AKLR
that referenced
this pull request
Nov 23, 2026
Resolve three conflicts with main: - ci.yaml: keep AKLR_BASELINE_SGL_AMD_MONO and main's AKLR_REFERENCE_CONTRACTS in PASS_ENV - stack.json: take main's aiter pin (a6c759b1), keep sgl_amd_mono - ops/README.md: keep the shared-input note, reference signature without decode Also port muse_spark_layer/reference.py to main's float32 convention (AMD-AGI#293): the decode callable is dropped and every read goes through to_float32(tensor, dtype). The reference's outputs are returned in float32; compare casts them to the declared dtype. Co-authored-by: Cursor <[email protected]>
xiaobochen-amd
pushed a commit
that referenced
this pull request
Nov 23, 2026
…ng 0.5.23 route and MI355X kernels (#86) * feat(plugins): DeepSeek-V4 router with fused shared experts: op and sglang 0.5.23 route [email protected] (aklr/plugins/sglang/layers/moe_topk, sglang's srt/layers/moe/topk.py): sqrtsoftplus scoring, the correction bias, top-k, renormalization and routed scaling, with the fused shared expert appended and DP-padded rows zeroed, as aiter's topk_gating plus sglang's fused_append_shared_experts compute them. The route on select_experts falls back when sglang passes router-logit partials (rocm_router_gate's split-K decode path). The reference follows aiter's in-lane sorting order on ties and floors the weights' sum at 1e-20. * feat(plugins): DeepSeek-V4 router kernels on MI355X One Triton kernel by GEAK in two schemas of [email protected]: the target model's router (384 experts, top 6 + the shared one) and the DSpark draft model's (128, top 3 + 1), with the workloads AKLR_EXPORT recorded serving DeepSeek-V4.1-Flash at concurrency 32 and 64. * refactor(plugins): DeepSeek-V4 router reference in float32, without decode As main's references after #293: the reference reads its inputs with to_float32 and takes no decode argument; the renormalized weights are float32, as the kernel computes them, and the ids come back as integers. The ranking (aiter's in-lane sorting network, then the lanes merged by value) is unchanged.
kyle-256
added a commit
that referenced
this pull request
Nov 23, 2026
…ed as reference(point, args) #293's contract: no decode argument, operands read through to_float32. The decode test's float64 check of the recurrence now holds the float32 reference to the float64 matrix form within float32's rounding; the tests' Points carry each operand's logical dtype. (cherry picked from commit 06fbaa9)
kyle-256
added a commit
that referenced
this pull request
Nov 24, 2026
…s in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype.
kyle-256
added a commit
that referenced
this pull request
Nov 24, 2026
… the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x
kyle-256
added a commit
that referenced
this pull request
Nov 24, 2026
…s in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype.
kyle-256
added a commit
that referenced
this pull request
Nov 24, 2026
… the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x
kyle-256
added a commit
that referenced
this pull request
Nov 25, 2026
…s in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype.
kyle-256
added a commit
that referenced
this pull request
Nov 25, 2026
… the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x
kyle-256
added a commit
that referenced
this pull request
Nov 25, 2026
…s in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype.
kyle-256
added a commit
that referenced
this pull request
Nov 25, 2026
… the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x
zhenhuang12
added a commit
that referenced
this pull request
Nov 25, 2026
New: the b-shuffled fp8 block-scaled gemms in hsaco at n2048_k7168, n7168_k2048 and n8192_k1536 (#255), and the SwiGLU fused MoE at model dim 6144, 128 experts and inter dim 384 (#320). Replaced: the fused MoE at model dim 7168, which no longer imports and calls its baseline above 70 tokens and keeps the 9 workloads up to 70 (#322), and the two biased_grouped_topk kernels, which rank near ties by the float32 reference's key instead of a float64 one (#293). Withdrawn: two situv2 fused MoE kernels under main's MXFP8 bound (#322), a third and the flydsl gemm at n32_k6144 with no Point steadily at 1.05 (#326, #338), and the flydsl gemm at n256_k6144 (#316). Where main keeps a withdrawn kernel's workloads as a definition, they go to the schema's kernel-less file. A replaced kernel's source is main's new one under the branch's entry: its positional parameters, and its bindings of the attrs the body still reads. The files pass the audit; none was run on gfx950 here.
zhenhuang12
added a commit
that referenced
this pull request
Nov 25, 2026
Main's reference has since #293, and its two kernels rank near ties by that key: two experts whose biased scores round to one float32 value tie, and the lower one wins. A float64 reference orders them by the bits float32 drops and rejects the kernels there.
zhenhuang12
added a commit
that referenced
this pull request
Nov 25, 2026
…at the rebase leaves Main's kernels report (#319) reads the contract registry: its test and the publish-kernels job are out until it reads the schema files, as the plugins' tests are, and its imports sort as ruff now sees the removed package. TODO.md: what core reads of aklr/plugins/aiter, and what of main's #293 and #322 is not carried (float32 references but biased_grouped_topk's, the common tolerance and SQNR bounds, the shorter bench_cudagraph).
kyle-256
added a commit
that referenced
this pull request
Nov 26, 2026
…s in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype.
kyle-256
added a commit
that referenced
this pull request
Nov 26, 2026
… the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x
zhenhuang12
pushed a commit
that referenced
this pull request
Nov 27, 2026
…ts fp8 attention residual, and the attention-residual and GEMM points main misses (#302) * feat(plugins/vllm): Kimi-K3's latent-MoE tail as one FlyDSL kernel on ROCmLatentMoERunner._shard_up_proj_tail Under tensor parallelism vLLM ends each Kimi-K3 latent-MoE layer on ROCm with four ops in ROCmLatentMoERunner._shard_up_proj_tail: the TP all-reduce of the routed experts' latent partial, the latent RMSNorm, the addmm of this rank's up-projection rows into its columns of the shared experts' partial, and the all-reduce of that shared output. The new contract [email protected] states the four as one op that every rank of the TP group calls (ranks="tp_size"); its baseline is vLLM's four ops on vLLM's TP group. Its one FlyDSL schema (B0, TP 8, hidden 7168, latent 3584) runs them in one launch and does both TP reductions over peer memory: an uncached buffer each rank allocates and every rank maps over HIP IPC, set up once over vLLM's TP CPU group. Below 28 rows the launch takes kernel_small.py, from 28 kernel.py (the up projection spread over up to 4 sets of workgroups, bulk hand-offs as data then flag). The schema is unmeasured; its workloads are the row counts 1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 60, 64, 80, 120 and 128, matched exactly. The route, on vLLM 0.34.0 and 0.32.1rc1.dev276 (the same latent_moe_runner.py), takes 1 to 128 rows of dense bf16 at TP 8 and hands anything else back to vLLM. Every decision reads only what is the same on every rank, so the ranks launch the kernel together. The peer memory is set up by the first call outside a graph capture. The first eager call of each row bucket (rows of one bit length) is checked against vLLM's tail on the same operands; the ranks agree on the verdict, and a bucket any rank finds different stays with vLLM. Fail-stop: an in-kernel wait gives up after 10 s, records where it waited and sets a sticky FAILED word, so no rank hangs. The vLLM plugin gets AFTER_STEP, a list of watches run after each execute_model on every rank; the op registers one that every 16 steps has the ranks agree over the CPU group and raises on all of them at the same step once any rank's wait gave up. Switches: AKLR_VLLM_MOE_TAIL=0 hands every call back to vLLM; AKLR_VLLM_MOE_TAIL_CHECK=0 skips the first-call check. The kernel requires flydsl>=0.3.2, as CI runs; it has been compiled and run on FlyDSL 0.4.0 only. Measured on 8 MI355X in the vLLM 0.32.1rc1.dev276 image: 92 layers in one CUDA graph, cold weights, the slowest rank, us a layer: M B0 vLLM 1 9.78 40.92 2 10.40 42.63 4 11.66 45.25 5 12.21 44.25 8 14.26 43.67 10 16.30 45.85 16 19.65 45.00 20 22.99 45.10 24 25.46 45.35 32 28.70 46.07 40 29.93 48.81 60 35.28 53.06 64 35.76 53.38 80 42.10 56.48 120 49.80 63.69 128 51.76 64.07 At each M every harness check passes: the same bits on all ranks, within the contract's bound of the reference, the first-call check against vLLM, AKLR's dispatch serving the same bits, 100 graph replays each the eager bits, and no wait gave up. M=24 has no workload in this schema, so here it stays with vLLM. * feat(fastkey): rows of one page grid that never meet are not an overlap vLLM keeps a Mamba layer's convolution state and recurrent state in the same pages: a slot's convolution state, then its recurrent state. Their spans interleave, so the fast key's overlap test declined every call that writes one of them in place and reads the other. Two tensors whose spans meet are now apart when they have the same row stride in bytes, each row is dense, and the other's row lies, in every page, between the end of the written one's and the start of the next page. Rows that meet, or of another stride, still decline. This changes aklr/core, so validation re-benches every schema. * feat(plugins): kimi_k3_kda_spec_stage_c, Kimi-K3's KDA layer in a speculative verify step as one FlyDSL launch In a pure speculative verify step, vLLM's Kimi-K3 runs each KDA layer between in_proj and o_proj as three kernels: a copy of f_a, the f_b GEMM, and aiter's fused short convolution + recurrence + gated norm. The new contract [email protected] states that stage on vLLM's tensors (views of the in-projection's rows, the conv and recurrent states in their shared Mamba pages); its baseline is vLLM's f_b GEMM dispatch and aiter's fused kernel. The route at KimiDecoderLayer._run_self_attn (vLLM 0.34.0 and 0.32.1rc1.dev276) runs vLLM's in_proj, the op, then vLLM's o_proj. Everything else goes back to vLLM before anything runs: MLA layers, prefill, mixed and plain decode steps, ragged windows, breakable graphs, and a layer or cache outside the contract, such as a recurrent state that is not float32 (vLLM 0.34's mamba_ssm_cache_dtype). AKLR_VLLM_KDA_STAGE_C=0 hands every call back. One FlyDSL kernel (gfx950, 12 heads a rank, DSpark's window of 5), one schema with a workload at every count of 1-32 sequences, unmeasured. On MI355X, graph replay, us per layer: n_seqs 1 2 4 8 16 24 stage C 10.6 11.6 12.6 14.1 20.5 30.5 vLLM f_b + aiter 19.9 18.6 19.6 20.5 24.8 35.5 Against the contract's reference it passes on mixed, padded and chained windows, and two launches are bitwise equal. Needs the fast key to take the two caches' interleaved page rows (previous commit). * refactor(plugins/vllm): the latent-MoE tail and KDA stage C references in float32, called without decode #293's contract on main: no decode argument, operands read through to_float32. Stage C's tests' Points carry each operand's logical dtype. * feat(plugins/vllm): Kimi-K3's attention residual with an fp8 out, and the K3 attn_res and GEMM points main misses vLLM's _apply_attn_res asks attn_res for a per-token fp8 out (quant_dtype float8_e4m3fn, with its scale) where the linear after it takes fp8: about half of Kimi-K3's attention-residual calls. The new contract [email protected] states that out beside [email protected]'s (its reference in float32, as #293's); the route hands those calls to it (fnuz fp8 stays with vLLM) and also declares vLLM 0.32.1rc1.dev276, the K3 AgentX image. 124 schemas (unmeasured; CI measures) at the points of the Kimi-K3 AgentX trace that main does not serve, each kept only where an 11-20 validate on MI355X (vLLM 0.34.0 image, graph mode, paired against the baseline) passed accuracy and ran >= 1.05x with its lower bound >= 1.0 (310 points measured twice keep the worse): kimi_k3_attn_res 74 schemas, 1736 points, 1.05-2.09x kimi_k3_attn_res_fp8 44 schemas, 546 points, 1.06-2.20x gemm n2112/n6288 k7168 1.14-1.64x, n3584 k7168 1.20x, n20480 k7168 1.13x, n2304 k1536 1.06x, n3072 k512 1.05x * fix(fastkey): compare the written tensor's storage extent with the others', not their logical sizes A strided view reaches past its nbytes: a state view one page after its convolution view lands on the later pages' convolution rows, though the two views' logical sizes end before it. The overlap guard now compares the extents from the first element to the end of the last (_span) before it asks whether the two are rows of one page grid apart in every page. * fix(plugins/vllm): KDA stage C opt-in, tensor-dependent declines asked again, the baseline's float32 scale and staged conv weight - The route runs only with AKLR_VLLM_KDA_STAGE_C=1, read at each call: over three chained steps of two sequences the op and vLLM's served aiter chain are not yet shown to agree. - The route keeps a shape's verdict only: OUT_OF_CONTRACT, which can come from the step's own tensors (a slot table off the fast key's 16-byte alignment), is asked again at the next step, as NOT_WARMED was. - The baseline compares scale with head_dim ** -0.5 as float32s: the workloads record 0.0883883461356163. - The baseline's width-major conv weight belongs to the weight tensor, freed with it, and is staged again from the weight's values at every call outside a graph capture (validation reloads weights in place); a capture, what bench times, reads the copy of the eager call before it. - state_indices: positive slots distinct, 0 and -1 repeated in vLLM's padding windows; the schema re-rendered (uuid unchanged, unmeasured). The drawn distribution stays positive and distinct. - Tests: the switch, the recheck, the scale, the in-place reload and the staged copy's lifetime; on a GPU, the capture, and on gfx950 the kernel on padding windows of 0 and of -1 and a padding row against the reference. * fix(plugins/vllm): the latent-MoE tail's ranks agree before every collective path; shared written in place; a failed step reported at that step without a host wait - The route hands the dispatcher aligned, non-overlapping operands and agrees serve or fall back over the TP CPU group on each (rows, eps, capture) key's first call; setup agrees after each step that can fail on one rank (GPU check, allocation and export, mapping) before the next collective, and releases what it made. - shared is written in place, as vLLM's addmm_ does: the contract makes it mutable, the reference returns it, and both kernels write their own columns in the up stage's epilogue, after the flags. - Fail-stop: a wait that gives up writes FAILED into every rank's peer buffer; each step copies its rank's word to pinned memory on a side stream and the step's output leaves the worker only after that copy is checked in vLLM's output thread (no collective, no host wait, nothing inside a capture). PP falls back. - n_tokens covers the op's own range; the kernel's 128-row cap lives in its workloads and the route's guard. - Failure-injection tests on spawned gloo ranks. On 8 MI355X (vLLM 0.34.0 image): within the bound, shared's own columns in place and the others untouched, the same bits on every rank and over 100 graph replays; a stalled rank's step raises on all 8; setup and alignment faults agree on all 8; after_step 36 us CPU with the step's GPU work still running (49 of 50 steps), 12.8 us on the step's stream; 0.5-0.8 us a layer over the head's kernel at M >= 40. * fix(plugins/vllm): Kimi-K3 attention-residual kernels zero their claim counter in the call, mask with -inf, mix without overflow In the 12 kernel sources the review found (94 schemas, re-rendered and unmeasured): - the claim counter is torch.zeros in the call, only where a token past the statically assigned ones can be claimed; the rows5 split zeroes its slots' 8-byte tags and reads a partial only under its tag; - masked lanes score -inf; - the exponentials are scaled by 2**-4 (exact) instead of left unnormalized, so the mix and its sum of squares never exceed the normalized ones; outputs match the previous kernels bit for bit wherever their mix did not overflow. On MI355X: 1348 checks of the review's inputs (claims under a poisoned allocator, 20 eager calls and 20 graph replays; rows scoring -3.35e38; rows of 2**57) and 50 gfx950 cases pass. Paired with the head's kernels over 120 workloads, graph mode: geomean 0.998, the same bits; the rows5 split at 513-560 tokens is 1.14-1.16x for its per-call zeroing. * fix(plugins/vllm): the latent-MoE tail serves vLLM 0.34.0's unpadded calls, whose trunc_size is the hidden width vLLM 0.34.0 passes a latent MoE with shared experts the shared experts' width as the tail's trunc_size, padded or not, and keeps states[..., :trunc_size]. The route took any trunc_size as a padded hidden dim, so on Kimi-K3 it declined every call (seen serving the AgentX recipe on 8 MI355X). Only a size below the hidden width strips columns now; the test that called HIDDEN padded uses a real truncation, and a new one has None and HIDDEN reach the dispatcher. * refactor(plugins/vllm): the latent-MoE tail, KDA stage C and fp8 attention residual on #322's references, baselines and bounds - [email protected]: KimiK3LatentMoeTailReference (a DistOpReference, every rank's call and the rank) and KimiK3LatentMoeTailBaseline (a DistOpBaseline); group.py goes, its peer memory set up by the baseline's setup over the default group. No teardown: the buffers live until the process ends, as in vLLM, since a rank cannot free its buffer before its peers stop writing to it without a collective that a peer stopped at a finding would never join. - [email protected]: KimiK3KdaSpecStageCReference and KimiK3KdaSpecStageCBaseline on the call's keywords; L2_NORM_EPS moves to the reference, which alone reads it. max_violation_fraction goes: on MI355X (11-23, before the reference rounded its out) the committed kernel's state_cache peaked at 0.19 of its bound and out at 0.34, no element past either. - The references return their outputs in the declared dtypes, so the bf16 and fp8 outputs' bounds add one rounding of the output's dtype (2**-7, 2**-3), as #322 did for the bounds that relied on the compare's own allowance: the latent-MoE tail's out and shared, stage C's out and kimi_k3_attn_res_fp8's quantized. Float32 and exact bounds are unchanged. - The tests call the classes and read check()'s failures. - The 126 schema files of these contracts and of gemm drop max_violation_fraction and element_order, rendered by schema_text; their kernels and workloads are unchanged. * refactor(plugins/vllm): the latent-MoE tail's kernels import their runtime from aklr.core.jit (SA5) SA5 lets a kernel import nothing of aklr but aklr.core.jit; the tail's kernel.py and kernel_small.py imported the plugin's runtime module, the per-rank state they run with (the peer buffers, launch counters and health words) and its constants. The module moves, unchanged but for one thing, to aklr/core/jit/kimi_k3_latent_moe_tail.py, and the kernels' one import line follows; the schema file takes its new uuid. The kernels' code and the workloads are as they were. The one thing: setup no longer adds the fail-stop watch to the vLLM plugin's AFTER_STEP (core imports no plugin); the route adds it once its group is set up, as setup did there. * revert(plugins/vllm): KDA stage C and its fast key change leave this PR [email protected] is a route without end-to-end evidence: its one schema holds windows of 5 tokens, and the deployment verifies windows of 8, so the route never served a step there. Its contract, reference, baseline, route, schema, tests, small Point and names go, with the AKLR_VLLM_KDA_STAGE_C switch. The fast key's storage-extent and page-grid overlap tests were added for stage C's interleaved Mamba pages; they go with it, and aklr/core/contract/fastkey and its test are main's again. The latent-MoE tail and the attention residual pass their tests without them. * refactor(plugins/vllm): the latent-MoE tail's group state lives in its kernel's sources, not in aklr/core The per-rank state the tail kernel runs with (the peer buffers every rank maps, the launch counters, the health words and their setup) was aklr/core/jit/kimi_k3_latent_moe_tail.py, one op's code in the core. It is now runtime.py of the kernel's own sources, as mega_moe keeps its buffers in its sources, and the kernels import it relatively (SA5): - The vLLM route sets the group up through the module of the kernel the dispatcher serves the call with (api.serving's metadata names the kernel's module; runtime is a module of its package), over vLLM's TP group, before that kernel's first call. Where no caller set one up (validation's ranks), the kernel's first call sets it up over torch.distributed's default group, in a compile function (runtime.default_group). The CPU barrier after a build's first, compiling launch is a compile function too (runtime.every_rank_compiled). - The fail-stop watch, the vLLM plugin's step hook, is the plugin's (failstop.py); it copies the group's FAILED word with the runtime's HIP calls. TailGroup keeps only what launches read; its unused failed, clear_failed, given_up_waits and close go, with Hip.zero. - The baseline sets nothing up: vLLM's tail sets its TP group up at its first call. The route: - Shapes, dtypes, layouts and the TP size are the op's to judge: the route no longer checks them against 8 / 7168 / 3584, and hands vLLM's TP size over. It declines before the dispatcher only what vLLM's tail computes otherwise (padded columns stripped, a reduced routed output, no latent norm, pipeline stages) and, new, a skipped final all-reduce (moe_config.skip_final_all_reduce). Row counts past every committed schema's go back before the dispatcher's verdict, which costs a collective at each new count. - AKLR_VLLM_MOE_TAIL and AKLR_VLLM_MOE_TAIL_CHECK go: [email protected] hands every call to vLLM; the first eager call of a row bucket is always checked. - versions: 0.34.0, the release it was run on. The kernel's sources otherwise: run_traced (no caller) goes, run returns nothing, the entry docstring holds no measurement or commit, and requires FlyDSL >= 0.4.2, the version it was developed and run on. The kernels' device code is unchanged. * fix(plugins/vllm): the latent-MoE tail's contract states the op, not the kernel; common SQNR bounds - tp_size takes 2 and 4 too: vLLM runs the tail at any TP size that divides the hidden width. latent_size % tp_size goes: vLLM requires no such split; the kernel's own is its schema's. - out and shared take the GEMM's common bf16 bound (45 dB). The tolerance's absolute part held only for partials below 16 in magnitude, the workloads' draws: where a rank's own column cancels in the sum over ranks, the kernel's one rounding against vLLM's two (out), or a normalized latent rounded apart at a tie (shared), shows in full. The CPU model of the committed kernel's layout is at 55 dB (out) and 83 dB or more (shared) from 1 to 128 rows. * fix(gemm): Kimi-K3's n 2112 / 6288 kernel zeroes the scratch words a launch compares with its tag The kernel's split launches (tiled.py's two-way K split, which serves its m 600 and 1030 workloads, kernel.py's split-K and skw.py's folds) tell which split folds by comparing scratch words with the launch's tag (dispatch id and queue), and the call handed them torch.empty scratch: a word an earlier tensor left there could hold the tag, and a split would fold before the others wrote their planes. As the attention residual's kernels now do, the call zeroes those words (aklr/ops/README.md: scratch is written before it is read): the tiles' fold counters after the partial planes (_scratch; the builders report where they start), and skw.py's scratch whole. The planes, which every launch writes before it reads them, are not zeroed. The device code is unchanged; each call with split scratch runs one small fill before the launch. The schemas require FlyDSL 0.4.2, the version the kernel is run on. * fix(plugins/vllm): the rows5 attention residual's split build takes the mix's sum of squares from the mix Past 512 tokens the rows5 kernel spreads each leftover token over 14 column shares, which exchanged the rows' dots, sums of squares and cross products and took the mix's sum of squares from those Gram partials, sum w_r^2 |x_r|^2 + 2 sum w_r w_s x_r.x_s. Where rows cancel the terms are far larger than the result: in a float32 model of the merge, bank rows x and -x at 1024 times the others put 7140 of 7168 columns past the contract's bound, and at 4096 the sum is negative and the out NaN (the reference, vLLM and the other kernels sum the mix's squares). The shares now exchange twice: the dots and sums of squares (the scores; the cross products go), then each share's sum of squares of its own columns of the mix, summed over the token's shares in slot order; a partner late on either is recomputed from its rows, and p is stored into the prefix only after both exchanges. The call zeroes both tags of a slot. The float32 model of the new merge passes the bound at every ratio up to 2**20; a gfx950 test runs the committed kernel at its split workloads (520, 550) on such rows. The second exchange lengthens the share wave's merge, which the token waves' second barrier waits for: the split workloads are expected somewhat slower. * fix(plugins/vllm): the Kimi-K3 attention residual's fp8 bound, overflow-safe reference, export and requires - kimi_k3_attn_res_fp8's quantized bound is one fp8 code again (2**-3 of the value, 2**-9 below the normals): both sides are fp8 values, so the output's own rounding adds nothing. - The reference takes each mean square of a row scaled down by a power of two first: rows near 2**58 with a norm passed float32 in their squares and gave 0 where the normalized mix is the norm weight. Its results elsewhere are bit for bit the former ones. - The package exports kimi_k3_attn_res_fp8; the baseline's copy of vLLM's launcher is checked against vLLM's in fp8 too (gfx950). - The contract no longer comments on how a kernel or dispatch serves its tokens. - One schema of the rows5 kernel goes: it repeated another file's kernel at a subset of its workloads. - The 117 schemas this PR adds require FlyDSL 0.4.2, the version their kernels were developed and run on. * test(plugins/vllm): the latent-MoE tail's committed kernel on 8 gfx950 GPUs The GPU checks of the tail, run on 8 MI355X by hand so far, as gfx950 tests that spawn 8 ranks of one torch.distributed group (skipped on fewer than 8 GPUs): - the kernel computes the op on every rank, at every row count of both builds: the same bits on every rank, out and the shared partial's own columns within their bounds of the reference, the other columns untouched, 100 graph replays the eager bits, no wait given up; its first call sets its group up over the default group, as validation's ranks do; - through the route and the committed schema every rank serves, and the group the route set up through the serving kernel's runtime is the one the kernel reads (the kernel set none up), with the fail-stop watching it; - a rank late past the kernel's (2 s) wait: every rank finishes, the step's output and the next's raise on every rank, through the plugin's step hooks and the group word the kernel wrote; late below it, the exact out, the output handed over; - HIP's allocation, export or mapping failing on one rank: setup is None on every rank, nothing left, a clean setup after; - one rank's operand off alignment or aliased, or its dispatcher without the schema: the group serves (or declines) together. * docs(vllm): the plugin tutorial's fp8 output is kimi_k3_attn_res_fp8's; an op whose ranks call it together The tutorial said the attention residual's fp8 output was in no contract and _triton.py had no fp8 launcher; this PR adds both. A section on the latent-MoE tail states the rules of an op whose ranks call it together: the same path on every rank, the kernel's state in its own sources set up by the route (or by its first call over the default group), the in-kernel 10 s wait that fails the group, the plugin's AFTER_STEP step watch that stops the step, and AKLR_DISABLE to turn it off. * test(plugins/vllm): the tail's setup-failure test measures what a failed setup leaves, not the process's first tensors On 8 MI355X the mapping case failed on every run: it is the first case that gets as far as the group's tensors, and a process's first GPU tensors cost it 2 MiB of the device once (measured per rank: 2.0 MiB on the 7 ranks that mapped, at the first such case only; 0 at every later one, mapping failures included). The test makes such tensors before it measures, and the ranks meet at a CPU collective between the release and the measurement, as a peer that still maps a rank's buffer keeps its memory. * fix(plugins/vllm): the latent-MoE tail's baseline sets vLLM's TP group up where its sockets' paths fit CI's vllm-test aborted the tail's schema: every workload's baseline failed with "ZMQError: ipc path ... is longer than ...". vLLM's TP group binds its message queue's ZMQ sockets at <VLLM_RPC_BASE_PATH>/<uuid4>, the base by default the temp directory, and validation gives each task a TMPDIR nested deep enough that the path passes the 107 bytes a Unix socket path holds. The baseline now sets the group up with VLLM_RPC_BASE_PATH at /tmp (vLLM's default without TMPDIR) where the temp directory is too long, keeps a base the caller set, and puts the variable back afterwards. A CPU test sets up a stand-in vLLM under validation's nested TMPDIR, a short one, and a preset base; it fails without the fix. * docs(tests): the attention residual's scratch test names aklr/plugins/aiter's README, where #327 moved it * fix(plugins/vllm): the latent-MoE tail's baseline times its graphs inside vLLM's graph_capture vLLM's TP all-reduce (aiter's custom all-reduce on ROCm) registers the buffers a CUDA graph reads as vLLM's graph_capture ends, after the capture and before any replay. The bench captured the baseline's graph outside it and replayed it at once, so the replays read unregistered peer addresses: a GPU memory fault at a null address on all 8 ranks, every workload candidate_crash in CI's vllm-test. The baseline's profile (the candidate's clock too) now captures each graph inside graph_capture, on the timing's own stream; its eager calls stay outside, and with no vLLM TP group yet nothing changes. * perf(plugins/vllm): the latent-MoE tail's workloads are the rows it wins at in serving, 6 to 14 validate times the kernel alone, and there it is 1.5 to 4.3 times vLLM's tail at every row count to 128. A served decode step says otherwise past a few rows. Kimi-K3 on 8 MI355X, vLLM 0.34.0, the daily 8K/1K flow, CUDA graphs replayed on the eight ranks, each step timed alone, AKLR on with the tail served against the tail left to vLLM: rows of the step 6 10 16 20 30 40 80 step, tail served 16.82 17.39 - 21.53 24.45 26.57 34.08 ms step, tail vLLM's 16.56 18.04 - 21.02 22.93 25.41 33.18 ms the kernel saves -0.26 +0.65 -0.15 -0.51 -1.52 -1.16 -0.90 ms (two servers, one prompt a concurrency: about 0.5 ms of resolution). vLLM's two all-reduces, its norm and its addmm are not slow when eight ranks step together, and the waits of the kernel's hand-offs outweigh the launches it saves; the kernel's own time shows none of that. The schema, the same kernel in one file, now holds 6, 8, 10, 12 and 14 rows: the even graph sizes around the one where the step gains, all in the kernel's small launch (under 28 rows); 8, 12 and 14 were not timed in serving on their own. The route's guard is the largest committed row count, so it follows to 14. The tests that drove the route at 15 to 40 rows use rows up to 14. * fix(plugins/vllm): the latent-MoE tail's contract names out_dtype as its output's dtype param Since #352 a contract's api takes an out_dtype only where an output's dtype names it; the tail's route and kernel take one, so its contract names it (the kernel and its schema file are unchanged). * test(plugins/vllm): the tail's graph-capture test stands in for the timing module It imported aklr.core.utils.testing inside the test. Importing that module registers AKLR's profiler with rocprofiler-sdk, which the vLLM image's SDK refuses once the GPU is up: in vllm-test, where the tests before it have used the GPU, both cases failed on the import (8 MI355X, tests/plugins/vllm in one process). The test only needs the two names the baseline reads, which it replaced anyway: it now puts a module holding them in sys.modules and on aklr.core.utils (the baseline's 'from aklr.core.utils import testing' reads the package's attribute first), and both are put back afterwards. * test(plugins/vllm): the tail's route tests ask for the row counts its schema holds Two of the 8-GPU tests went through the route at 1 to 128 rows, and at 10 and 40. Since the schema kept the rows the kernel wins at in serving (6 to 14), the route serves no other count, and both failed on a GPU (served: False at the others). They now ask for the schema's own counts; the test of the kernel itself keeps 1 to 128 rows. * test(plugins/aiter): the K3 GEMM kernel test tells its kernel by the scratch it hands out, not by sizes The test picked, in gemm_n2112_k7168 and gemm_n6288_k7168, the schema files with skw.py whose smallest m is past 128 rows, to leave out main's sibling kernel (skw.py too, small m, no _scratch). A schema may hold any m: a file giving the sibling larger sizes (#276 adds one at 148 to 380 rows) was taken for the K3 kernel and failed on _scratch. It now picks the files whose sources define _scratch, which is what it tests. --------- Co-authored-by: kyle-256 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Why
References computed in float64, inputs were generated and decoded through float64, compare measured errors in float64, and validation fell back to float64 when a float32 reference overflowed. Inference runs bf16/fp8 operands with fp32 accumulation (sglang and vLLM routers included), so float64 only made references and kernels more complex: 59 kernels carried fp64 accumulators, midpoint corrections, error certificates, exact repairs or float64 ranks to match an exact-sum reference. This PR drops float64 (and int64) everywhere an op does not declare it: references, input generation, decoding and compare run in float32, integer outputs come back in their declared dtype, and the fp64 code leaves the kernels.
Scope
semantics.to_float32/from_float32replaceto_float64/from_float64(inputs drawn, decoded and encoded in float32;rounded_to_bfloat16is a cast);compare_outputsmeasures in float32, scaling by the peak before squares, sums and norms so large values do not overflow, and compares integral outputs as integers (float32 holds an int exactly only to 2**24); validation's float64 retry, the float64 checks in_comparison.pyand the float64 timing all-reduce go.DType.FLOAT64, which no contract declares, goes too: an op that needs float64 brings its decoding and compare with it.reference.pycomputes in float32 and returns integer outputs (ids, slots, mxfp8 exponents) in the contract's declared dtype (int32, uint8), not int64; thedecodeparameter is gone (<contract>_reference(point, row_major_args));OpContract.reference_outputs,tests/op_case.py, docs and the new-op skill follow. The references main added since (mla_decode_fwd_cprr,situv2_a4w4_moe,deepseek_common,qwen3_moe) too.aklr/ops/README.mdgains "Reference and baseline": the reference computes in the op's dtypes (a bf16 gemm as torch's bf16 matmul), else float32, float64 or int64 only where the op declares them (for now float32 everywhere); it rounds only where every correct kernel rounds and sums nothing exactly; the baseline is the engine's own call, nothing reimplemented or added. The tutorials and the new-op skill point to it.<contract>_id_scores(point, row_major_args), per integer output the candidates' scores in their float dtype.compare_outputs(id_scores=...)then counts an id that differs from the reference's as equal when its score equals the reference id's or is the next value of that dtype above or below, the id is in range and its row repeats no id.qwen2_moe_routergives its bf16 logits: a kernel sums the projection in another order than torch's float32 matmul, so a logit at a rounding midpoint lands on the next bf16 value and two experts one value apart swap (3 of its kernels failed exact ids at 0.5–8 per 10⁴ before). Contracts without one compare ids exactly as before.7d7e,04e9,ddb8,99f4) withdrawn, each slower at its only Points than3504orc07d. Removed with fp64: midpoint-correction helpers, router error bounds/certificates and their exact repairs, the norms and CTAs that fed them, the exact scalar gate-up for power-of-two scales (a171, 30a0), the near-midpoint gate-up repair (868f), and policy fields only those read.2c66/3504(W13 unroll),c07d(M64 gate-up occupancy from 128 rows) re-tuned after the fp32 change.04977b1e→ac401aa1,d7d33c29→a191a754): ranked near ties by a float64 key and fell back to a float64 arg-max; against the float32 reference main's files choose other ids on 28 and 18 of the cases below. Their exact paths now rank by the reference's own key, torch's fp32 sigmoid (accurate exp, IEEE divide: bitwise equal to it on the GPU over all 65280 finite bf16 inputs) plus the bias, ties to the lower expert, as one 64-bit integer (the key's order image, then the reversed expert). The fast screens keep their fp32 keys and margins (GAP_REL2^-21,RANK_MARGIN3·2^-22), which also cover the reference's key: each fast key is within 2^-23 + 2^-23 |k| of it, two within 2^-21 max(1, |k|); the bias prune's cut checked over every pair of finite bf16 values in float32 (at T' = 1 it is -2^-25).Tradeoffs
A float32 reference differs from an exact one by one more summation order; the contracts' bounds already admit kernels' own orders (e.g. dsa_indexer's "the projections' other summation order rounds a few values to the next bf16"). Exact integer ids against a float32-summed score hold only up to that rounding, which
id_scoresallows per contract; a contract whose ids come from a sum and that gives none fails a kernel on such a swap.Verification
Environment: base
7e9cff86+ this diff, then rebased on8806c22a(the topk, router and unit-test checks rerun there); MI355X (gfx950) ×8; sglang 0.5.23 image, ROCm 7.15.26333, torch 2.11.0+rocm10.0.0, Triton 3.8.0+git4cff872c, FlyDSL 0.4.0, aiter 0.1.26.dev144+g285579b62Gate overrides: none
Every schema, accuracy
python -m aklr validate --stages audit,bench --no-timing --devices 0-7over all 717 schemas (828 batches, 4569 workloads; 2 skipped bykernel.requires, FlyDSL 0.4.0 and aiter on this host): accuracy ok 4566, FAIL 3, the 3qwen2_moe_routerfiles above (ca826892,4c2bed7e,c3889614, topk_ids only). Withid_scoresall 7qwen2_moe_routerfiles pass (--no-timing, accuracy ok 7). After review, on the final tree, every schema butmega_moe's 3 (8 ranks; unchanged since): accuracy ok 4550, FAIL 0 (825 batches, the same 2 skipped).Kernels
biased_grouped_topk, beyond validation: every path (both kernels'
FORCE_SLOW/FORCE_CLASHvariants) at every launch configuration (n_tokens 1 – 16384 across the small/prune/tiered/top-2 thresholds) on 8 input kinds built to tie (randn, uniform over finite bf16 bits, a few repeated values, saturated sigmoids, all equal, wide biases, bias steps at the key's ulp, a shared bias peak): ids equal to the float32 reference in all 144 + 176 cases (main's files: 18 + 28 differ); weights within 7 ulps except on the bits kind (tiny sigmoids), as main's files. Against main's files in validation (graph vs incumbent): 0.997 – 1.021 at every Point.Demoted in the first pass:
regressedat 0.985–0.986 for a171 (n 80, 88, 104, 120) and e0cf (n 32); rerun alone a171 passed at all 13 Points; back-to-back timing at n 96 is bimodal (≈245 / ≈254 µs by run order) with the fp32 file equal to or faster than main's in both orders.c07dn 56 dropped: main's file leaves rows 48–55 unprocessed at non-multiples of 16 (inf/NaN; passed on uninitialized memory), and9e9dserves 56.deepseek_v2 … inter512n 8 dropped: 1.049 on main, 1.02–1.03 now, below 1.05 either way.Validation logs
Code
pytest tests1320 passed, 9 failed — the same 9 fail on main on that host (no CUDA, FlyDSL version);pre-commit runon the changed files andpython -m aklr export checkpass.pytest tests/core tests/ops tests/benchmarks1182 passed;pytest tests/plugins299 passed.test_outputs_are_declaredrequires float32 for float outputs and the declared dtype for integer ones (failed on 23 contracts before); new: integer compare exact past 2**24, large values keep their SQNR, float32 decoding inverts encoding for bf16/fp8/fp4/e8m0, ids of adjacent bf16 scores swap / two values apart fail / a repeated id fails / equal-score ids are no bias, the qwen2_moe_router case; removed the six tests that only proved float64 was needed (large-input rms_norm/add_rms_norm/mhc, the float32-tie topk case, float32-vs-float64 fares, validation's float64 retry).Not run
aiter-test,sglang-test,vllm-test): not run yet.vllm-testand the pinned-aiteraiter-testenvironment were not available locally, nor the 2 schemaskernel.requiresskipped here.Risk
Affects: every contract's reference, inputs and compare (validation of every kernel), the 51 rewritten and 4 withdrawn kernels, qwen2_moe_router's id compare
AgentX: all
If wrong: a kernel validated against a float32 reference that misses its bound or an exact id at a bf16 rounding boundary (demoted, falls back to the baseline); a rewritten kernel slower than main's at a Point (demoted);
id_scorespasses a kernel that swaps two experts whose logits are adjacent bf16 values but that a correct sum would not swap (only qwen2_moe_router gives one)Undo:
git revert; it restores the float64 references and the fp64 kernels, not the measurements CI publishes for the new files