Skip to content

Expose the fused_moe activation dtype resolution for dispatch dtype selection - #5221

Merged
Duyi-Wang merged 1 commit into
ROCm:mainfrom
Duyi-Wang:feat/resolve-activation-dtype
Sep 16, 2026
Merged

Duyi-Wang merged 1 commit into
ROCm:mainfrom
Duyi-Wang:feat/resolve-activation-dtype

Conversation

@Duyi-Wang

@Duyi-Wang Duyi-Wang commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Exposes the activation-dtype resolution fused_moe() already does internally, so
a caller can produce activations in the dtype the kernel consumes instead of one
it has to convert.

fused_moe() picks q_dtype_a from the quant type, weight dtype, activation,
gate mode, arch and token count, then converts hidden_states when they arrive
as something else. That decision was not reachable from outside. This lifts it
into resolve_activation_dtype() and calls it from _fused_moe_impl.

Why

SGLang's MoRI EP fixes its dispatch format when the communication buffers are
sized -- before the first token -- and derives it from the expert weight dtype
alone. For MXFP4 weights that says nothing about the kernel: the same weights run
a16w4, a8w4 or a4w4. On DeepSeek-V4-Pro the MoE is a8w4, so the guessed fp4 costs
an upscale_mxfp4 plus a re-quantize on every layer, in both prefill and decode.
Nothing errors; it is just slower. Driving the format from this resolution takes
gsm8k 200q from 100.0 s to 62-67 s on MI355X / TP8 + EP8, accuracy unchanged.

M is optional

Such a caller has no M: one format serves every batch that follows. Omitting it
returns None wherever the answer would have needed M, and the caller falls back
to bf16, which fused_moe() accepts from any path. Since M >= 0, a bound of 0
still settles its branch without M.

The distinction matters because the two directions are not symmetric: bf16 where
fp8 was wanted costs a quantize on the receive side, while fp8 where bf16 was
wanted raises Unsupported kernel config for moe heuristic dispatch -- or at
small M returns garbage without raising.

No behavior change

Identical to the inlined resolution on 414720 combinations of quant type, weight
dtype, activation, gate mode, arch, M and the relevant environment variables.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5221 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@Duyi-Wang
Duyi-Wang force-pushed the feat/resolve-activation-dtype branch from 8fbe3c8 to de38c40 Compare September 3, 2026 03:38
@Duyi-Wang Duyi-Wang changed the title Expose the fused_moe activation dtype resolution Expose the fused_moe activation dtype resolution for dispatch dtype selection Sep 3, 2026
@Duyi-Wang
Duyi-Wang marked this pull request as ready for review September 3, 2026 03:41
@Duyi-Wang
Duyi-Wang requested review from a team and a lite review from Copilot September 3, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is a confirmed logic/clarity bug in an environment-variable check and the new public API should be covered by focused tests to prevent future heuristic drift.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR exposes the activation-dtype heuristic used internally by fused_moe() as a new helper (resolve_activation_dtype()), enabling external callers (e.g., dispatch/all-to-all paths) to pre-produce activations in the kernel-consumed dtype and avoid redundant conversions.

Changes:

  • Added resolve_activation_dtype() (and _bound_split()) to make fused_moe()’s activation-dtype selection available to callers, including “M is optional” behavior via None.
  • Refactored _fused_moe_impl() to call resolve_activation_dtype() instead of duplicating the resolution logic inline.
File summaries
File Description
aiter/fused_moe.py Factors activation dtype resolution into a reusable helper and updates _fused_moe_impl to use it.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/fused_moe.py Resolved
@zufayu
zufayu self-requested a review September 4, 2026 23:45
zufayu added a commit that referenced this pull request Sep 7, 2026
perf_claims knew x, %, us, ms, TFLOPS, GB/s and tok/s. Run against aiter#5221, whose
headline is `gsm8k 200q from **100.0 s to 62-67 s**` -- a 38% wall-clock win and the whole
reason the PR exists -- it printed "no numeric performance claim in the PR description".
That is worse than missing it quietly: the reviewer is told the axis was checked and came
back empty, and P1 and P3 are adjudicated against that.

What is matched is the transition between two durations, not the unit. A bare second over
279 PR descriptions hits four lines and two of them are not claims at all: a `600s wait`
timeout constant and a `4 passed in 541.10s` pytest summary. `from A s to B s` hits one
line in the same 279 -- #5221's -- and neither trap. Both traps are tests.

A transition also carries its own baseline. "from 100.0 s to 62-67 s" names both sides of
the comparison in the sentence; asking what it was measured against is asking something
the line already answered.

0.36% of the corpus, which is below the rate at which detectors have been turned down
here, and the rate is the wrong test again: this is not a detector finding less, it is an
artifact making a false statement about what it looked at.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu

zufayu commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Automated advisory review — not a human sign-off, and not a merge gate.
Produced by this repo's own review-pr skill (.claude/skills/review-pr) run against
this PR. Treat every line below as a lead to check, not as a conclusion.

@yadaish — you maintain aiter/fused_moe.py, so flagging this for you.

Two things to weigh it by. The three findings were attacked by the same reviewer that
wrote them and by nobody else, which is what not independently refuted on the card
means. And the equivalence check behind the first one was run rather than taken on trust:
base and head transcribed into a differential harness, 186624 combinations, zero
mismatches. Anything marked [unverified] was not checked.

For calibration: measured over 250 PRs, roughly 3 in 4 of this skill's findings survive
an independent reader told to assume they are false. The fourth costs you the minutes it
takes to dismiss it. Its false-clearance rate — how often it says nothing when something
is wrong — has never been measured, so silence from it means nothing.


ROCm/aiter PR #5221 — Expose the fused_moe activation dtype resolution for dispatch dtype selection

Lifts the activation-dtype heuristic that fused_moe() computed inline into a public resolve_activation_dtype(), so a caller that builds the activations itself — SGLang's MoRI EP sizing its all-to-all buffers — can emit the dtype the kernel wants instead of one fused_moe() has to convert.

Review (advisory): ⚠️ NEEDS WORK — not independently refuted
Validation (deterministic): NOT RUN — the PR changes runtime code (aiter/fused_moe.py, executed on every MoE call) but ships no test target, so triage had nothing to run
Perf (advisory): NOT RUN — REVIEW_AUTO_VALIDATE=0 and the PR ships no benchmark entry point; an environment gap, and base-vs-head timing would compare an identical dispatch decision on both sides (see below)

⚠️ The new public resolve_activation_dtype() in aiter/fused_moe.py has no test, and the one thing about it that is new — _bound_split() returning None when M is omitted — has no in-tree caller at all, because _fused_moe_impl always passes M = topk_ids.shape[0]. Meanwhile op_tests/test_moe_2stage.py:969 (_runtime_situv2_mxfp4_q_dtype_a) and :991 (_runtime_swiglu_mxfp4_q_dtype_a), whose docstrings say they "Mirror fused_moe's ... routing" and which are live oracles at lines 233, 363, 883 and 893, were left as hand copies rather than pointed at the new single source of truth. Impact: if a later edit makes another branch M-dependent without routing it through _bound_split, resolve_activation_dtype(M=None) silently returns a concrete-but-wrong dtype instead of None; MoRI EP then sizes fp8 buffers where bf16 was needed, which this PR's own description says raises Unsupported kernel config for moe heuristic dispatch or returns garbage at small M — and the test that should catch it is a copy of the code it is testing. The extraction itself is sound: I transcribed both sides into a differential harness and swept 186624 combinations of quant type x w1.dtype x activation x gate mode x M x hidden_states.dtype x a1_scale x gfx x env with 0 mismatches, and every non-None M-omitted answer matched the base answer for every M. [verified] Author must add a table test that calls resolve_activation_dtype() directly, pinning the M=None contract, and switch op_tests/test_moe_2stage.py:969/:991 to call it instead of re-deriving the routing.

📝 os.environ.get("AITER_FORCE_A8W4", "0") in ("1") on the new gfx1250 override in aiter/fused_moe.py is a substring test against the string "1", not tuple membership — ("1") is a string. Concrete trigger: with AITER_FORCE_A8W4="" exported (set-but-empty, e.g. export AITER_FORCE_A8W4= in a launch script), "" in "1" is True, so gfx1250 silently forces fp8 activations; AITER_FORCE_A8W4="11" is False. It is carried verbatim from the deleted block, not introduced here, so this is a note, not a regression — but the diff re-authors the line, and the test mirror at op_tests/test_moe_2stage.py:977 spells the same check == "1", so implementation and oracle already disagree on that input. [verified] Author must change it to == "1" while the line is being moved, so the public resolver and its test mirror agree.

📝 The headline number -- gsm8k 200q from 100.0 s to 62-67 s on MI355X TP8+EP8 -- is [unverified]: the claim ships no script, no ROCm/SGLang version, no commit and no checkpoint, and the code that produces the win is in SGLang, not in this diff, so nothing in this repo reproduces it. The equivalence claim's "414720 combinations" is likewise not traceable (grep -rn 414720 over the merge target returns nothing), though I reproduced the property independently over 186624 combinations. Relatedly, the new resolve_activation_dtype() in aiter/fused_moe.py is inert inside aiter -- its only in-tree caller, _fused_moe_impl, gets exactly the answer it already computed inline -- so 100% of the PR's value depends on an SGLang MoRI EP change, and pr_meta.json shows no linked consumer PR and no URL in the body. Impact: the API in aiter/fused_moe.py could land, drift and never be exercised, and no reviewer can check the number that justifies it. [verified] Reviewer should ask for the MoRI EP PR link and the repro command plus ROCm/SGLang commits behind the 100.0 s to 62-67 s measurement.

`_fused_moe_impl` resolves `q_dtype_a` from the quant type, weight dtype,
activation, gate mode, arch and token count, then converts `hidden_states`
if they arrive in another format. Callers that produce the activations
themselves -- an all-to-all dispatch, a fused epilogue -- have no way to
ask what that answer will be, so they either guess or emit a format the
kernel has to convert.

Lift the decision into `resolve_activation_dtype()` and call it from
`_fused_moe_impl`, so there is one copy rather than one per caller
willing to mirror it.

`M` is optional. A dispatch format is fixed when the communication
buffers are sized, before any token exists, so such a caller cannot
follow an answer that moves with the batch. Omitting `M` returns None
wherever the answer would have needed it -- "cannot commit to a format"
-- and the caller falls back to bf16, which fused_moe() always accepts.
Since M >= 0, a bound of 0 still settles its branch without M.

No behavior change: the resolution is identical on 414720 combinations
of quant type, weight dtype, activation, gate mode, arch, M and the
relevant environment variables.
Copilot AI review requested due to automatic review settings September 16, 2026 02:39
@Duyi-Wang
Duyi-Wang force-pushed the feat/resolve-activation-dtype branch from de38c40 to 960d7cc Compare September 16, 2026 02:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Add direct tests covering M=None, zero, boundary values, architectures, and environment overrides.

Review details

Suppressed comments (1)

aiter/fused_moe.py:739

  • resolve_activation_dtype is a new public decision point, but the existing MoE tests still duplicate the old selection logic instead of calling this helper. No test protects the documented M=None behavior or the threshold/arch/env combinations, so this helper can drift from _fused_moe_impl while the current tests continue to pass. Add direct coverage for M=None, zero, and boundary values on gfx950/non-gfx950 with the relevant environment overrides.
    `M` is the token count. Omit it when the dtype has to be chosen before any
    token exists: the result is then None wherever the answer would have needed
    M, and the caller should fall back to bf16, which fused_moe() accepts from
    any path.
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@Duyi-Wang
Duyi-Wang merged commit 977d857 into ROCm:main Sep 16, 2026
56 checks passed
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.

4 participants