Skip to content

[FlyDSL] [gfx1250] mega_moe S1F: reachable stage-1 hook, plan precompile, opt-in tuning knobs (on #6564) - #7308

Closed
yhl-amd wants to merge 1 commit into
ROCm:ghu_mega_1250from
yhl-amd:hyi/s1f-tuning-on-6564
Closed

yhl-amd wants to merge 1 commit into
ROCm:ghu_mega_1250from
yhl-amd:hyi/s1f-tuning-on-6564

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Stacked on #6564 (base branch ghu_mega_1250), so the diff here is only this change. It fixes the stage-1 hook wiring and the in-loop JIT, and adds opt-in tuning knobs for the gfx1250 MegaMoE stage-1 fusion (S1F). Every knob defaults to the current behaviour.

Motivation

We ran #6564 on DSV4.1-Flash DEP4 (MI455X, MLPerf Endpoints agentic c512) and hit three problems:

  1. The fused stage-1 path was unreachable on the compact path. The grouped GEMM reads the hook from dispatch_context, but only target.scatter was replaced.
  2. The plan JIT-compiled inside the serving loop. The plan is keyed by (align_m, slot, waves, blocks, tok_map, fused quant), and waves and blocks follow the step's token count. Every new eager width compiled (~0.6 s each). Prefill steps took 250–680 ms for the first ~100 s, which cost −3.1% over a 10 min window even though steady state was +1.6%.
  3. Wide prefill steps and some tiles fell back or ran slower. The 2048-row bucket's tuned GEMM1 uses tile_k 128 and fell back with "GEMM1 tile_k 128 != 256".

Changes

  • mega_moe.py: swap the hook into dispatch_context as well when it is the same object as scatter.
  • stages/dispatch_compact.py:
    • _precompile_s1f_plans(): compile every plan variant a fused step can need at setup, compile only (48 variants, ~30 s on DEP4). AITER_S1F_PRECOMPILE=0 skips it.
    • AITER_TDM_COMPACT_ROUTE_UPTO / _ROUTE_SPEC / _ROUTE_PARALLEL: keep the route-parallel compact walk up to N tokens per rank.
  • s1f_ctl.py:
    • AITER_S1F_MAX_RECV=N: a step whose receive bound exceeds N runs the whole S1F=0 path (plan key and width, GEMM1, no probe).
    • AITER_S1F_ANY_TILE=1: only tile_m has to match; the stage-1 kernel runs its own 256×256 n/k tiles.
  • s1f_stage1.py: AITER_S1F_PRODUCERS / AITER_S1F_BLOCK_RUNS override the per-bucket tables. Format is "N" for all four buckets, or "a,b,c,d".

Performance (if applicable)

Hardware Workload/configuration Before After Change
MI455X ×4 DSV4.1-Flash DEP4 + DSpark, Endpoints agentic c512, 10 min, gen tok/s/GPU, mean of 2 11,085 (S1F off) 11,322 +2.1%
same + ATOM adaptive prefill admission (ROCm/ATOM#2897) 11,085 11,586 +4.5%

S1F config: AITER_MEGA_S1F=1 AITER_S1F_BLOCK_RUNS=4,2,8,8 AITER_S1F_MAX_RECV=4096 AITER_S1F_ANY_TILE=1 AITER_TDM_COMPACT_ROUTE_UPTO=1024 AITER_TDM_COMPACT_ROUTE_SPEC=384,16. The baseline already used the route-parallel walk. With precompile, no compile happened after load started (checked with a JIT log), and the first prefill steps took 103–117 ms.

Testing

  • Unit tests added or updated
  • Performance benchmarks run (E2E above)
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. All new knobs default to the current behaviour. Precompile runs only when S1F is enabled.

PR Self-Review

Reviewed revision

8e4c846

Behavior and intent

See Motivation. With the variables unset, only the hook fix and the setup-time precompile change behaviour, and only when AITER_MEGA_S1F=1.

Validation and unverified scope

PR-specific question

Should the tuned values (BLOCK_RUNS=4,2,8,8, MAX_RECV=4096, ANY_TILE) become defaults? We have only measured them on DSV4.1-Flash DEP4, so they stay opt-in for now.

Changed op tests

None

🤖 Generated with Claude Code

…ile, opt-in tuning knobs

On top of the stage-1 fusion (ROCm#6564):

- Fix: swap the stage-1 hook into dispatch_context as well as scatter. The
  grouped GEMM reads it off dispatch_context, so replacing scatter alone
  left the probe / fused stage-1 path unreachable on the compact path.
- Precompile every stage-1 compact-plan variant at setup (compile only,
  AITER_S1F_PRECOMPILE=0 skips). Eager widths otherwise JIT-compiled inside
  the serving loop: 250-470 ms prefill steps for the first ~100 s of a run.
- AITER_S1F_MAX_RECV=N: steps whose receive bound exceeds N run the whole
  S1F=0 path (plan, GEMM1, no probe), e.g. fuse decode only.
- AITER_S1F_ANY_TILE=1: fuse when the tuned GEMM1's tile_m matches; the
  stage-1 kernel runs its own 256x256 n/k tiles.
- AITER_S1F_PRODUCERS / AITER_S1F_BLOCK_RUNS: per tokens-per-rank bucket
  overrides of the stage-1 tables.
- AITER_TDM_COMPACT_ROUTE_UPTO / _ROUTE_SPEC / _ROUTE_PARALLEL: keep the
  route-parallel compact walk up to N tokens per rank.

All knobs default to the current behaviour.

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.

2 participants