Repository navigation
Sm90 megamoe optimization #4688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jiahanc
merged 21 commits into
flashinfer-ai:main
from
inocsin:sm90_megamoe_optimization
Sep 17, 2026
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4b612cc
perf(moe_ep): SM90 Hopper FP8 MegaMoE CGA, ping-pong scheduling, and β¦
inocsin 687e85c
bench(moe_ep): align SM90 mega benchmark with the drop harness and arβ¦
inocsin 1ad1a30
feat(moe_ep): SM90 FP8 mega tuning stack (knob cache + autotune) and β¦
inocsin fe6ddc6
chore(moe_ep): refresh SM90 pull-style vendored sweep harness
inocsin 4fe4392
feat(moe_ep): SM90 pull mega top-k dedup (dispatch + combine) and quaβ¦
inocsin 9cf13ef
feat(moe_ep): SM90 pull mega active_dispatch_warps knob (default 1)
inocsin 685393d
docs(moe_ep): refresh SM90 pull mega TUNING.md sweep numbers
inocsin 259dd24
feat(moe_ep): SM90 pull mega empty-warp FC1 store offload + early pubβ¦
inocsin 1e41349
feat(moe_ep): SM90 pull mega fold producer warps into dispatch WG; reβ¦
inocsin b1b6b39
Merge remote-tracking branch 'origin/main' into sm90_megamoe_optimizaβ¦
inocsin 2915cd6
feat(moe_ep): SM90 pull mega swap-AB token tile N=8 and heuristic rows
inocsin 3ddfc5b
feat(moe_ep): SM90 pull mega generate_c training-forward output
inocsin bcd84b8
perf(moe_ep): SM90 pull mega 16-byte generate_c stores + compact dispβ¦
inocsin b66f879
Sync Hopper FP8 generate_c sweep comparisons and N=8 validation
inocsin 0c8522d
Sync Hopper FP8 register allocation and blockwise FC2 overlap
inocsin 242012b
Address Hopper MoE review feedback and fix FC2 completion ordering
inocsin f605c14
fix(moe_ep): SM90 pull mega grouped combine SMEM slot per pull warp
inocsin 27bf240
chore(moe_ep): fix pre-commit for the SM90 pull mega tree
inocsin 2b8daed
fix(moe_ep): address SM90 pull mega review feedback
inocsin 2ae8fc6
test(moe_ep): run SM90 pull tuner tests in their own interpreter
inocsin c969e2c
Merge branch 'main' into sm90_megamoe_optimization
inocsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
flashinfer/moe_ep/backends/mega/kernel/sm90/fp8_fp8_bf16_pull_cutedsl/tuner.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Offline knob tuner for the SM90 pull-style FP8 mega kernel. | ||
|
|
||
| Invoked through the :mod:`flashinfer.moe_ep.tune` CLI shim (``--dtype | ||
| sm90_fp8_e4m3`` / ``sm90_fp8_e5m2``). Kernel-specific pieces (dummy input | ||
| creation, candidate enumeration, knob resolution, the autotune entry point) | ||
| live here, next to the backend that consumes the recorded winners; the sweep | ||
| loop and shared helpers come from ``backends/mega/kernel/tuning.py``. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ...tuning import finish_sweep, run_tuning as _run_tuning, schedule_candidates | ||
|
|
||
|
|
||
| def _kind(args) -> str: | ||
| # CLI dtype "sm90_fp8_e4m3" -> shim kind "fp8_e4m3". | ||
| return args.dtype.removeprefix("sm90_") | ||
|
|
||
|
|
||
| def tune_one(args, rank: int, world_size: int, max_tokens: int) -> dict: | ||
| from ......kernel_src.sm90.pull_style_cutedsl_megakernel import ( | ||
| autotune_hopper_fp8_mega_moe, | ||
| create_dummy_hopper_fp8_inputs, | ||
| hopper_fp8_candidates, | ||
| resolve_knobs, | ||
| ) | ||
|
|
||
| live_tokens = args.live_tokens if args.live_tokens is not None else max_tokens | ||
| if live_tokens > max_tokens: | ||
| raise SystemExit("--live-tokens must be <= --max-tokens") | ||
| symm_buffer: Any = None | ||
| try: | ||
| y, l1, l2, symm_buffer = create_dummy_hopper_fp8_inputs( | ||
| rank, | ||
| world_size, | ||
| args.num_experts, | ||
| max_tokens, | ||
| live_tokens, | ||
| args.topk, | ||
| args.hidden, | ||
| args.intermediate, | ||
| kind=_kind(args), | ||
| fp8_scale_mode=args.fp8_scale_mode, | ||
| gate_up_clamp=args.gate_up_clamp, | ||
| seed=args.seed, | ||
| ) | ||
| candidates = hopper_fp8_candidates( | ||
| fp8_scale_mode=args.fp8_scale_mode, | ||
| max_tokens=max_tokens, | ||
| ) | ||
|
|
||
| if args.sweep == "schedule": | ||
| import json | ||
|
|
||
| if args.base_knobs: | ||
| base = json.loads(args.base_knobs) | ||
| base = { | ||
| k: tuple(v) if isinstance(v, list) else v for k, v in base.items() | ||
| } | ||
| else: | ||
| base, src = resolve_knobs( | ||
| dtype=_kind(args), | ||
| fp8_scale_mode=args.fp8_scale_mode, | ||
| world_size=world_size, | ||
| hidden=args.hidden, | ||
| intermediate=args.intermediate, | ||
| num_experts=args.num_experts, | ||
| topk=args.topk, | ||
| max_tokens=max_tokens, | ||
| ) | ||
| if rank == 0: | ||
| print(f"[moe_ep-tune] schedule sweep base ({src}): {base}") | ||
| candidates = schedule_candidates(base) | ||
|
|
||
| return finish_sweep( | ||
| args, | ||
| rank, | ||
| max_tokens, | ||
| live_tokens, | ||
| symm_buffer, | ||
| y, | ||
| l1, | ||
| l2, | ||
| candidates, | ||
| autotune_hopper_fp8_mega_moe, | ||
| ) | ||
| finally: | ||
| if symm_buffer is not None: | ||
| symm_buffer.destroy() | ||
|
|
||
|
|
||
| def run_tuning(args) -> int: | ||
| from ......kernel_src.sm90 import pull_style_cutedsl_megakernel as pkg | ||
|
|
||
| return _run_tuning(args, tune_one, pkg=pkg) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.