Skip to content

[fused_moe] Raise when an active swiglu_limit would be silently dropped - #6335

Closed
jatseng-ai wants to merge 2 commits into
ROCm:mainfrom
jatseng-ai:aiterker-222-swiglu-limit-guard
Closed

jatseng-ai wants to merge 2 commits into
ROCm:mainfrom
jatseng-ai:aiterker-222-swiglu-limit-guard

Conversation

@jatseng-ai

@jatseng-ai jatseng-ai commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a caller passed a real swiglu_limit into aiter.fused_moe() and stage-1 resolved to a kernel that cannot consume it, the bound was discarded and the kernel ran an unclamped activation. On gfx942 that showed up as identical output for swiglu_limit=1.0 and swiglu_limit=None on the bf16 QuantType.No / ActivationType.Silu path.

This change is the guard. Teaching the gfx942 SiLU epilogue to honor the bound is separate follow-up work and is not implemented here.

Predicate

_swiglu_limit_is_active is true only for a finite positive value. It is the only thing that may raise.

Checked against runtime_swiglu_limit (aiter/ops/flydsl/moe_kernels.py) and _opus_runtime_swiglu_limit (aiter/ops/opus/moe_stage1_a8w4.py):

value helper result for SiLU active? why
None +inf (unset) no function default
0.0 +inf (falsy, unset) no vLLM's ROCm backend forwards 0.0 when moe_config.swiglu_limit is None, so this arrives on every unconfigured call
+inf +inf no both helpers use +inf as the SiLU no-clamp value, and a truthy +inf is passed through as that same value
finite > 0 the value itself yes a real clamp

Negative finite, NaN, and -inf are not active. Those three are truthy in the two helpers (they would be forwarded as a bound), but they are not a caller sentinel, and the requested predicate is finite-and-positive so the existing <= 0 "unset" convention keeps working. Please say if any of those should raise instead.

SwiGLU's internal default of 7.0 when the limit is unset is unchanged. Raising on None or 0.0 would break every existing caller.

Dispatch sites

  • 2-stage fused_moe_2stages. FlyDSL stage-1 and Opus still receive the caller limit. MXFP4 stage-1 still receives it for SiLU and SwiGLU (runtime_swiglu_limit). CK, CK-Tile, and asm stage-1 have no parameter: an active limit now raises NotImplementedError. MXFP4 + any other activation (SiTUv2) nulls the limit, so that also raises. FHMoE's FlyDSL wrapper already carries the limit in _stage1_extra_args and is not an error.
  • 1-stage fused_moe_1stage. The asm fmoe / fmoe_g1u1 launch has no limit argument. An active limit raises before the launch. On gfx942, bf16 QuantType.No + SiLU with token < 256 takes this path.
  • flydsl_gfx942 whole-graph backend. The limit is forwarded. SwiGLU applies it. The SiLU epilogue ignores it, so an active SiLU limit now raises. Making that epilogue honor the bound is separate follow-up work, not this PR.
  • gfx1250 grouped a8w4. Already receives the limit and applies it. No hole.

Before / after

Before: ck_moe_stage1 / fused_moe_1stage with swiglu_limit=10.0 returned the unclamped tensor.

After, that call raises, for example:

ck_moe_stage1 cannot apply swiglu_limit=10.0 for ActivationType.Silu on gfx942; the clamp would be silently dropped. Supported stage-1 families for a clamped activation are FlyDSL and Opus.

None, 0.0, and +inf still run, including on CK.

Raise vs warn

This raises. There is no warning mode and no environment escape hatch.

That turns a deployment that today starts and returns a numerically wrong activation into a startup failure. That is the behaviour this change is meant to produce, and it is a behaviour change in a patch release. If a warning (or a default-raise escape hatch) is preferable for the rollout, say so. A silently wrong default is what this change exists to remove, so the default stays raise.

Tests

op_tests/test_fused_moe_swiglu_limit.py

  • Predicate: None, 0.0, 0, +inf inactive; finite positive active.
  • CK, CK-Tile, asm, and fused_moe_1stage raise on a finite limit and do not raise on None / 0.0 / +inf.
  • FlyDSL, Opus, and MXFP4 SiLU/SwiGLU accept a finite limit.
  • gfx942 whole-graph SiLU raises; SwiGLU and inactive limits do not.
  • GPU repro (QuantType.No, ActivationType.Silu, bf16, AITER_BYPASS_TUNE_CONFIG=1) expects the raise. Skipped without a GPU, and skipped on archs other than gfx942/gfx950.

black 26.3.0 and ruff check are clean on the two files.

Run on gfx942 (Instinct MI300X), pytest op_tests/test_fused_moe_swiglu_limit.py:

  • Unit tests: 44 passed, 2 deselected, 19.26s.
  • GPU repro test_bf16_noquant_silu_repro_raises (token=4 and token=256): 2 passed, 16.04s. Both sizes raised NotImplementedError (cannot apply swiglu_limit) instead of returning an unclamped tensor. On gfx942, token=4 is fused_moe_1stage and token=256 is ck_moe_stage1.

Reviewer

Please add Tang, James. I could not find his GitHub account from commits or reviews on this repo (the Tang accounts in history are amd-ruitang3 and jtang10 / Jingning Tang), so I did not guess.

@jatseng-ai
jatseng-ai requested a review from a team October 9, 2026 17:00
@github-actions

github-actions Bot commented Oct 9, 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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:multi-gpu 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 6335 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

@jatseng-ai
jatseng-ai force-pushed the aiterker-222-swiglu-limit-guard branch from 8422d8a to 2cb0d2d Compare October 9, 2026 17:12
@jatseng-ai

Copy link
Copy Markdown
Contributor Author

Test result (gfx942)

Ran op_tests/test_fused_moe_swiglu_limit.py on gfx942 (Instinct MI300X).

  • Unit tests (predicate, dispatch guards, whole-graph SiLU): 44 passed, 2 deselected, 19.26s.
  • GPU repro test_bf16_noquant_silu_repro_raises (bf16 QuantType.No / ActivationType.Silu, swiglu_limit=1.0, AITER_BYPASS_TUNE_CONFIG=1, token=4 and token=256): 2 passed, 16.04s.

Both token counts raised NotImplementedError (cannot apply swiglu_limit) instead of returning an unclamped tensor. On this arch, token=4 is fused_moe_1stage and token=256 is ck_moe_stage1.

@fsx950223

fsx950223 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Swiglu limit should be a feature added into CK

@jatseng-ai

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (395babca1). No conflicts. The guard is still invoked at the whole-graph, 1-stage, and 2-stage sites. ruff check (0.16.0, the pre-checks pin) and black are clean on the two changed files. CI will re-run on this push.

@jatseng-ai
jatseng-ai force-pushed the aiterker-222-swiglu-limit-guard branch from 8b1f3ef to b9bad33 Compare October 21, 2026 18:48
@jatseng-ai

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (1c464e51b). No conflicts.

  • The previous run's build_aiter_wheels / Aiter Test Gate failure was a runner fault, not this change: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. The push re-triggers CI.
  • op_tests/test_fused_moe_swiglu_limit.py on gfx942 (MI300X), head b9bad33fe: 46 passed.
  • ruff check 0.16.0 and black 26.10.1 are clean on the changed files.

@jatseng-ai

jatseng-ai commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@fsx950223 @XiaobingSuper

Agreed: swiglu_limit should be a CK feature. That is the long-term fix, and it takes longer than this workload can wait, so it is separate work and will be tracked on its own ticket. It is not part of this PR.

FlyDSL is what unblocks the workload in the meantime. ROCm/aiter#6552 routes gfx942 bf16 QuantType.No SiLU/SwiGLU with an active limit to the a16wmix port, which applies the clamp.

This PR is the guardrail for the kernels that still cannot apply a limit, including CK. An active limit raises NotImplementedError instead of returning the unclamped activation. None, 0.0, and +inf still run on CK, so existing callers are unchanged. Once CK accepts the parameter, those paths stop raising.

The guardrail is what lets vLLM open the gate. vllm-project/vllm#61508 is what starts sending a real swiglu_limit into aiter.fused_moe. Until this PR is in place, that limit can hit CK two-stage on gfx942 and be silently dropped. #61508 should not land ahead of this guard.

CK, CK-Tile, asm, and the 1-stage path discard a caller-supplied clamp
and run an unclamped activation. Fail that configuration instead.

Signed-off-by: jatseng-ai <[email protected]>
Co-authored-by: Cursor <[email protected]>
@jatseng-ai
jatseng-ai force-pushed the aiterker-222-swiglu-limit-guard branch from b9bad33 to db71a81 Compare October 22, 2026 16:44
@jatseng-ai

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (2fa9f7e7c). No conflicts. The patch is unchanged from b9bad33fe.

  • op_tests/test_fused_moe_swiglu_limit.py on gfx942 (MI300X), head db71a81ca: 46 passed.
  • ruff check 0.16.0 and black 26.10.1 are clean on the changed files.
  • CI on the previous head was green (37 passed, including Standard Tests and Aiter Test Gate). This push re-runs it.

vLLM has said they will review vllm#61508 after this PR and #6552 are merged and in an aiter release. The reply to the CK-feature comment is in the thread above: this PR is the guardrail, and the CK parameter is separate work.

@fsx950223 fsx950223 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.

Reviewed exact head 957e09c, the complete diff, dispatch callers, backend limit handling, tests, existing feedback, and CI results. No blocking defect found. All 46 focused tests passed on gfx942, including both GPU reproductions. Review remains pending targeted gfx950 validation because the configured container is unavailable.

Validation:

  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: docker exec sixifang_dev python3 -c "import torch; print([(i,torch.cuda.get_device_properties(i).gcnArchName) for i in range(torch.cuda.device_count())])"; docker exec sixifang_dev rocm-smi --showuse --showmemuse
    Verified gfx942 inside the container; all devices reported 0% activity and 0% allocated VRAM before testing. Selected device 0. Log: gfx942-probe.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: In isolated exact-head checkout: env HIP_VISIBLE_DEVICES=0 PYTHONPATH=$PWD AITER_JIT_DIR=/tmp/codex-pr-review-6335-20261106/cache/aiter FLYDSL_RUNTIME_CACHE_DIR=/tmp/codex-pr-review-6335-20261106/cache/flydsl TORCH_EXTENSIONS_DIR=/tmp/codex-pr-review-6335-20261106/cache/torch TRITON_CACHE_DIR=/tmp/codex-pr-review-6335-20261106/cache/triton flock /tmp/codex-pr-review-6335-20261106/gpu.lock timeout 240 python3 -m pytest op_tests/test_fused_moe_swiglu_limit.py -v
    Exit 0: 46 passed in 37.61s, including token=4 and token=256 GPU reproductions. Remote git rev-parse HEAD matched the supplied SHA. Import provenance resolved aiter.fused_moe to the isolated checkout; FlyDSL version 0.4.0. Logs: gfx942-tests.log and gfx942-import.log.
  • SKIP on dzm-mi355-gpu34-dev / mi355-gpu-34: SSH with RemoteCommand=none: squeue -h -u zhiming_ding_qle -o '%i|%N|%t'; srun --overlap --jobid=9275 --ntasks=1 --cpus-per-task=1 podman exec -i sixifang_atom_dev sh -c 'python3 -c "import torch; print(torch.__version__)"; rocm-smi --showuse --showmemuse'
    Discovered RUNNING allocation 9275 on mi355-gpu-34. Container probe failed with exit 125: no container named sixifang_atom_dev. Architecture verification and targeted tests could not run. Logs: gfx950-probe.log and gfx950-device.log.

Remaining validation:

  • Targeted gfx950 validation remains outstanding; retry when the configured container is available.
  • CI for the exact head reports successful standard tests on MI300X and MI35X, but retrieving detailed run logs returned HTTP 410, so case-level CI coverage could not be verified.
  • No base comparison was run because no suspected regression was identified.

Automated Codex review of commit 957e09cd9a08.

@fsx950223 fsx950223 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.

No blocking findings in the swiglu_limit predicate and dispatch guards. Reviewed exact head 957e09c and verified that non-consuming paths reject active limits while the supported paths and inactive sentinels retain their expected behavior. Independently ran all 46 focused tests on each of gfx942 and gfx950, including the bf16 no-quant SiLU reproductions at token counts 4 and 256.

Validation:

  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: docker exec sixifang_dev python3 -c "import torch; print([(i,torch.cuda.get_device_properties(i).gcnArchName) for i in range(torch.cuda.device_count())])"; docker exec sixifang_dev rocm-smi --showuse --showmemuse
    Verified gfx942 inside the container; all devices reported 0% activity and 0% allocated VRAM before testing. Selected device 0. Log: gfx942-probe.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: In isolated exact-head checkout: env HIP_VISIBLE_DEVICES=0 PYTHONPATH=$PWD AITER_JIT_DIR=/tmp/codex-pr-review-6335-20261106/cache/aiter FLYDSL_RUNTIME_CACHE_DIR=/tmp/codex-pr-review-6335-20261106/cache/flydsl TORCH_EXTENSIONS_DIR=/tmp/codex-pr-review-6335-20261106/cache/torch TRITON_CACHE_DIR=/tmp/codex-pr-review-6335-20261106/cache/triton flock /tmp/codex-pr-review-6335-20261106/gpu.lock timeout 240 python3 -m pytest op_tests/test_fused_moe_swiglu_limit.py -v
    Exit 0: 46 passed in 37.61s, including token=4 and token=256 GPU reproductions. Remote git rev-parse HEAD matched the supplied SHA. Import provenance resolved aiter.fused_moe to the isolated checkout; FlyDSL version 0.4.0. Logs: gfx942-tests.log and gfx942-import.log.
  • PASS on dzm-mi355-gpu34-dev / sodev (gfx950): In the isolated exact-head source snapshot: env HIP_VISIBLE_DEVICES=0 PYTHONPATH=$PWD AITER_JIT_DIR=/tmp/codex-pr-review-6335-20261106-gfx950/cache/aiter FLYDSL_RUNTIME_CACHE_DIR=/tmp/codex-pr-review-6335-20261106-gfx950/cache/flydsl TORCH_EXTENSIONS_DIR=/tmp/codex-pr-review-6335-20261106-gfx950/cache/torch TRITON_CACHE_DIR=/tmp/codex-pr-review-6335-20261106-gfx950/cache/triton flock /tmp/codex-pr-review-6335-20261106-gfx950/gpu.lock timeout 300 python3 -m pytest op_tests/test_fused_moe_swiglu_limit.py -v
    Exit 0: 46 passed in 18.11s, including token=4 and token=256 GPU reproductions. Source was streamed with git archive from the verified head SHA. Import provenance resolved aiter.fused_moe to that isolated source; gfx950, torch 2.10.0+rocm7.2.4 and FlyDSL 0.4.1 were verified. Selected idle device 0. Log: gfx950-tests.log.

Automated Codex review of commit 957e09cd9a08.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@jatseng-ai

Copy link
Copy Markdown
Contributor Author

Closing this as superseded. The guard it adds now exists on main, assembled from #7019,
#7361 and #8531.

Verified on main @ 7a8a0a37:

CK 2-stage, for any quant type outside RUNTIME_SILU_LIMIT_QUANT_TYPES, including bf16
QuantType.No
— raises in aiter/moev2/segments/ck.py, ck_moe_stage1:

if quant_type not in RUNTIME_SILU_LIMIT_QUANT_TYPES or (w1_dtype != dtypes.fp8):
    raise NotImplementedError(
        f"CK MoE stage1 cannot apply swiglu_limit={swiglu_limit!r} for ..."
    )

That is the exact case this PR was filed against: bf16 QuantType.No + SiLU returning
identical output for swiglu_limit=1.0 and swiglu_limit=None.

1-stage raises at fused_moe.py:1852-1857, and is activation-gated only rather than
quant-gated, so it covers every quant type.
CK-Tile raises at fused_moe.py:4920-4924.
ASM stage-1 without split-K raises at aiter/moev2/segments/asm.py:65-71.

Rebasing is not worthwhile either: _swiglu_limit_is_active is already on main, having
arrived with #6552, where _can_reroute_bf16_to_a16wmix calls it. This branch would
redefine it and fail ruff F811.

One gap this PR covered that main still does not. MXFP4 / MXMOE stage-1 with a
non-SiLU, non-SwiGLU activation (SiTUv2, Gelu, Relu2) still accepts an active limit and
discards it with no diagnostic: aiter/moev2/policy.py :: _normalize_mxfp4_activation_params
nulls the limit for those activations, so neither the stage-1 raise ladder nor
active_silu_limit fires. Filed separately as #NNNN rather than carrying 254 lines for it.

Separately, the bf16 QuantType.No raise in ck.py does not appear to have direct op-test
coverage, so if that guard regresses nothing currently fails.

@jatseng-ai jatseng-ai closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants