Skip to content

fused_moe: remove incorrect topk adjustment in get_2stage_cfgs for EP - #5734

Merged
valarLip merged 1 commit into
ROCm:mainfrom
psakhamo:fix/get_2stage_cfgs-remove-topk-ep-adjustment
Sep 23, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
psakhamo:fix/get_2stage_cfgs-remove-topk-ep-adjustment

Conversation

@psakhamo

Copy link
Copy Markdown
Contributor

Summary

Removes topk -= int(is_ep) from get_2stage_cfgs in aiter/fused_moe.py.

Root Cause

When VLLM_ROCM_USE_AITER_FUSED_MOE_SHARED_EXPERT=1 is set together with EP (expert_mask is not None), the removed line incorrectly reduces
topk by 1 before building the config lookup key. This strips the Fused Shared Expert column from the key, causing a wrong tuned-config to be
selected (or a cache miss falling back to untuned defaults).

The adjustment was originally intended to strip the fake always-masked expert slot that EP callers append to topk_ids. That convention no longer
applies uniformly — fused shared expert uses the last expert slot as a real expert, so subtracting 1 is invalid in that path.

Change

Removes 4 lines from get_2stage_cfgs — the comment block and the topk -= int(is_ep) mutation.

Test Plan

  • Reproduce with EP + VLLM_ROCM_USE_AITER_FUSED_MOE_SHARED_EXPERT=1 and confirm correct config is selected
  • Run op_tests/test_moe_2stage.py to verify no regression on standard EP path

Fixes #5595

…or EP

Removes `topk -= int(is_ep)` from `get_2stage_cfgs`.

When VLLM_ROCM_USE_AITER_FUSED_MOE_SHARED_EXPERT is enabled with EP,
this subtraction incorrectly strips the Fused Shared Expert column from
the config lookup key, causing wrong tuned-config selection.

Fixes ROCm#5595

Co-Authored-By: Claude Sonnet 4 <[email protected]>
@github-actions

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 5734 --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.

@zufayu
zufayu self-requested a review September 22, 2026 01:51
@psakhamo

Copy link
Copy Markdown
Contributor Author

Validation on GLM-5.3-FP8 DP8+EP8 — MI300X (gfx942) — vLLM v0.28.0

Node: 8× MI300X, gfx942 | vLLM: v0.28.0+rocm723 | ROCm: 7.2.3
Model: zai-org/GLM-5.3-FP8 (744B total / 39B active, 256 routed + 1 shared experts)
Serving mode: DP8+EP8 (--data-parallel-size 8 --enable-expert-parallel)
Additional patches in image: PR#4365 (qh64 page_size=64 gate) + PR#5563 (__half JIT fix)

Launch Command

docker run -d --name glm53-fse-test \
    --network host --device /dev/kfd --device /dev/dri \
    --group-add video --group-add render \
    --ipc host --shm-size 128g \
    --cap-add SYS_PTRACE --cap-add IPC_LOCK \
    --security-opt seccomp=unconfined \
    --ulimit nofile=1048576:1048576 \
    -v /lvm-data/psakhamo/glm-5.3-fp8:/mnt/models/GLM-5.3-FP8:ro \
    -v /lvm-data/psakhamo/aiter_jit_glm53_fse:/opt/vllm_cache \
    -v /lvm-data/psakhamo/aiter_home_glm53_fse:/root/.aiter \
    -e HF_HUB_OFFLINE=1 -e TRANSFORMERS_OFFLINE=1 \
    -e VLLM_GCN_ARCH=gfx942 \
    -e VLLM_ROCM_USE_AITER=1 \
    -e VLLM_ROCM_USE_AITER_MOE=1 \
    -e VLLM_ROCM_USE_AITER_MLA=1 \
    -e VLLM_ROCM_USE_AITER_FP8BMM=0 \
    -e VLLM_ROCM_USE_AITER_FP4BMM=0 \
    -e VLLM_USE_V2_MODEL_RUNNER=1 \
    -e VLLM_ROCM_USE_AITER_FUSED_MOE_SHARED_EXPERT=1 \
    -e AITER_BATON_TIMEOUT=7200 \
    -e VLLM_ENGINE_READY_TIMEOUT_S=21600 \
    -e VLLM_HANDSHAKE_TIMEOUT_MINS=30 \
    -e HSA_NO_SCRATCH_RECLAIM=1 \
    -e AITER_JIT_DIR=/opt/vllm_cache/aiter_jit \
    -e VLLM_CACHE_ROOT=/opt/vllm_cache/vllm \
    vllm-glm53-v028-wideep-fse:latest \
    vllm serve /mnt/models/GLM-5.3-FP8 \
        --served-model-name glm-5-3-fp8 \
        --tensor-parallel-size 1 \
        --data-parallel-size 8 --data-parallel-size-local 8 \
        --enable-expert-parallel --trust-remote-code \
        --quantization fp8 --kv-cache-dtype fp8 \
        --max-model-len 202752 --max-num-batched-tokens 8192 \
        --no-enable-prefix-caching \
        --gpu-memory-utilization 0.9 \
        --distributed-timeout-seconds 7200 \
        --enable-auto-tool-choice --tool-call-parser glm47 \
        --port 30000

Reasoning Test

curl -s http://localhost:30000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-5-3-fp8","messages":[{"role":"user","content":"What is 15 * 47? Think step by step."}],"max_tokens":512,"temperature":0}' \
  | python3 -c "
import sys,json; d=json.load(sys.stdin); msg=d['choices'][0]['message']
print(msg.get('content','')); print('finish_reason:', d['choices'][0]['finish_reason'])"

Output:

# Calculating 15 × 47

**Step 1: Break down 47 into easier parts**
47 = 40 + 7

**Step 2: Multiply each part by 15**
- 15 × 40 = 600
- 15 × 7 = 105

**Step 3: Add the results together**
600 + 105 = **705**

**Verification** (using a different breakdown):
- 15 × 47 = (10 + 5) × 47
- 10 × 47 = 470
- 5 × 47 = 235
- 470 + 235 = 705 ✓

**Answer: 15 × 47 = 705**

finish_reason: stop

✅ Correct answer | ✅ Clean finish_reason: stop | ✅ All 8 DP workers completed warmup without GPU faults | ✅ VLLM_ROCM_USE_AITER_FUSED_MOE_SHARED_EXPERT=1 accepted without errors

Without PR#5734, the topk -= int(is_ep) line would silently corrupt the config lookup key when the fused shared expert path is active on EP, causing wrong tuned-config selection. With the patch, config selection is correct on gfx942 + DP8+EP8.

@yadaish

yadaish commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

LGTM @valarLip topk -= int(is_ep) should be applied to fake expert mode. Remove it .

@valarLip
valarLip merged commit 25ae2bf into ROCm:main Sep 23, 2026
48 checks passed
yifehuan pushed a commit that referenced this pull request Oct 22, 2026
…rows that lose to the CK 2-stage default (#6681)

The Qwen3-235B-A22B FP8 TP8+EP rows (cu_num 256, model_dim 4096,
inter_dim 1536, 16 local experts, top-8, per_1x128) at token=1 and
token=2 select the 1-stage ASM fmoe_bf16_blockscaleFp8_g1u1_vs_pf2_silu_16x128,
which is slower than the CK 2-stage default used when no row matches.

These rows only became reachable under EP with #5734, which removed
`topk -= int(is_ep)` from get_2stage_cfgs (before that the lookup used
topk=7 and fell back to the default). That made Qwen3-235B FP8 EP about
6% slower at conc 1 between the vLLM v0.30.0 and v0.31.0 ROCm images.

On aiter main (MI350X): token=1 32.2 -> 26.7 us, token=2 32.1 -> 30.6 us.
The token=4 and token=8 rows are kept because the tuned ASM kernel beats
the default there (36.5 vs 41.6 us, 37.8 vs 46.5 us).


Claude-Session: https://claude.ai/code/session_012XYVab4mQWCMPp2QoPkThy

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[ROCm][AITER]: get_2stage_cfgs: topk -= int(is_ep) incorrectly strips Fused Shared Expert column, producing wrong kernel config and gibberish output

3 participants