Repository navigation
Expose the fused_moe activation dtype resolution for dispatch dtype selection - #5221
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
8fbe3c8 to
de38c40
Compare
There was a problem hiding this comment.
🟡 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 makefused_moe()’s activation-dtype selection available to callers, including “M is optional” behavior viaNone. - Refactored
_fused_moe_impl()to callresolve_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.
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]>
@yadaish — you maintain Two things to weigh it by. The three findings were attacked by the same reviewer that For calibration: measured over 250 PRs, roughly 3 in 4 of this skill's findings survive ROCm/aiter PR #5221 — Expose the fused_moe activation dtype resolution for dispatch dtype selectionLifts the activation-dtype heuristic that Review (advisory):
📝 📝 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 ( |
`_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.
de38c40 to
960d7cc
Compare
There was a problem hiding this comment.
🔵 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_dtypeis 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 documentedM=Nonebehavior or the threshold/arch/env combinations, so this helper can drift from_fused_moe_implwhile the current tests continue to pass. Add direct coverage forM=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
Exposes the activation-dtype resolution
fused_moe()already does internally, soa caller can produce activations in the dtype the kernel consumes instead of one
it has to convert.
fused_moe()picksq_dtype_afrom the quant type, weight dtype, activation,gate mode, arch and token count, then converts
hidden_stateswhen they arriveas 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_mxfp4plus 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.
Mis optionalSuch a caller has no
M: one format serves every batch that follows. Omitting itreturns
Nonewherever the answer would have needed M, and the caller falls backto bf16, which
fused_moe()accepts from any path. Since M >= 0, a bound of 0still 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 atsmall 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.