Skip to content
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
c322810
fix: Add support for using MXFP8 datatype in flashinfer A2A communicator
djns99 Jun 11, 2026
561d357
Draft MegaMOE integration
djns99 Jun 23, 2026
0446deb
Add megamoe implementation file
djns99 Jun 23, 2026
0fff939
Fix incorrect sharding for shared expert
djns99 Jun 24, 2026
1a739fb
Fix incorrect sharding for shared expert
djns99 Jun 24, 2026
6d89639
MegaMOE NVFP4 support through FlashInfer
djns99 Jun 26, 2026
d247b52
MegaMOE MXFP8 support through FlashInfer
djns99 Jun 29, 2026
c99aecd
Rebase fixes
djns99 Jul 15, 2026
629a795
MoERunner based MegaMOE refactor
djns99 Jul 16, 2026
6d5024a
add more knobs
wenscarl Jul 17, 2026
a346da2
Expose FlashInfer MegaMOE combine dtype
wenscarl Jul 24, 2026
e6d9223
topk_idx_out created in inference mode, unblock inplace mutation
wenscarl Jul 31, 2026
7a50f0c
Revert "topk_idx_out created in inference mode, unblock inplace mutat…
wenscarl Aug 6, 2026
d42e789
cherry-pick Fix inference mode mismatch in FlashInfer warmup #33788
wenscarl Aug 6, 2026
422995f
perf: keep MegaMoE router IDs in int32
foraxe Aug 5, 2026
34b55ce
perf: use FlashInfer MegaMoE workspace output view
foraxe Aug 5, 2026
6b7e612
Merge pull request #5 from foraxe/codex/31470-zero-copy-output
wenscarl Aug 7, 2026
bd15853
Test fixes for MXFP8
djns99 Aug 7, 2026
63b2199
remove torch.inference_mode
wenscarl Aug 7, 2026
cca3e63
Merge upstream main into mega_moe_flashinfer
YAMY1234 Aug 12, 2026
01f2af0
Fix lint issues after main merge
YAMY1234 Aug 12, 2026
63aee97
Fix MegaMOE test registration
YAMY1234 Aug 12, 2026
9543940
Fix MegaMOE base CPU tests
YAMY1234 Aug 13, 2026
861cabc
Merge main into mega_moe_flashinfer
YAMY1234 Aug 14, 2026
ecb0862
Merge main into mega_moe_flashinfer
YAMY1234 Aug 18, 2026
6b4301d
Merge branch 'main' into mega_moe_flashinfer
YAMY1234 Aug 19, 2026
1ee198a
fix: address FlashInfer MegaMoE review feedback
foraxe Aug 21, 2026
a5bb425
fix: gate FlashInfer MegaMoE model support
foraxe Aug 24, 2026
161e237
Merge pull request #6 from foraxe/31470-ch-wan-review
wenscarl Aug 24, 2026
f0d5568
Merge branch 'main' into mega_moe_flashinfer
YAMY1234 Aug 25, 2026
b07d901
fix: rely on FlashInfer MegaMoE workspace pooling
YAMY1234 Aug 25, 2026
35f1f52
fix: validate FlashInfer MegaMoE quantization
YAMY1234 Aug 25, 2026
52c271e
test: add FlashInfer dispatcher test entrypoint
YAMY1234 Aug 25, 2026
a60bfdd
Address comments
wenscarl Aug 26, 2026
b4f7bff
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
wenscarl Aug 26, 2026
a28b571
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
wenscarl Aug 27, 2026
0dd62a0
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
YAMY1234 Aug 27, 2026
e533141
Fix FlashInfer A2A resolution reads
YAMY1234 Aug 28, 2026
6fd9740
Lower BCG dfv4-flash accuracy threshold.
wenscarl Aug 28, 2026
7233611
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
wenscarl Aug 28, 2026
b520eaf
Revert "Lower BCG dfv4-flash accuracy threshold."
wenscarl Aug 28, 2026
9599b80
Fix FlashInfer A2A dispatch arg after main merge
github-actions[bot] Aug 28, 2026
efcfba5
Fix MegaMOE tests after handler migration
github-actions[bot] Aug 28, 2026
8882850
test: patch MegaMOE SM100 check at its new owner
github-actions[bot] Aug 28, 2026
5f603ec
Merge origin/main into mega_moe_flashinfer
YAMY1234 Aug 29, 2026
ac339af
Fix FlashInfer dispatcher test fixture
github-actions[bot] Aug 29, 2026
1b39f4f
test: initialize FlashInfer dispatcher token limit
github-actions[bot] Aug 29, 2026
9c79251
Merge remote-tracking branch 'refs/remotes/guardian/upstream-main' in…
YAMY1234 Aug 29, 2026
e7ada3f
Fix arg init issue
wenscarl Aug 31, 2026
583ac01
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
wenscarl Aug 31, 2026
7a036be
Fix MegaMOE model config resolution
wenscarl Aug 31, 2026
e8fa406
Initialize MegaMOE layer state lazily
wenscarl Aug 31, 2026
eb3bfab
Select MegaMOE forward adapter at init
wenscarl Aug 31, 2026
2849c64
fix: repair MegaMOE CI fixtures and imports
YAMY1234 Aug 31, 2026
72787cd
fix: update MegaMOE model config fixtures
YAMY1234 Aug 31, 2026
8758486
long build
wenscarl Aug 31, 2026
088b604
fix build bug
wenscarl Sep 1, 2026
3492356
Merge remote-tracking branch 'origin/main' into mega_moe_flashinfer
wenscarl Sep 1, 2026
347113f
Format ModelOpt NVFP4 dispatch condition
YAMY1234 Sep 1, 2026
e71bbab
Merge branch 'main' into mega_moe_flashinfer
YAMY1234 Sep 1, 2026
d63d380
test: initialize MegaMOE workspace in adapter fakes
YAMY1234 Sep 1, 2026
f7c100d
Merge branch 'main' into mega_moe_flashinfer
nvpohanh Sep 1, 2026
df6f08b
Merge branch 'main' into mega_moe_flashinfer
YAMY1234 Sep 1, 2026
d506521
Avoid log flooding
wenscarl Sep 1, 2026
ce4f3ae
fix multinode device issue
wenscarl Sep 1, 2026
30a27fa
Merge branch 'main' into mega_moe_flashinfer
nvpohanh Sep 2, 2026
6fa767b
Merge remote-tracking branch 'refs/remotes/origin/main' into HEAD
YAMY1234 Sep 3, 2026
e19cbf8
Merge remote-tracking branch 'refs/remotes/origin/main' into HEAD
YAMY1234 Sep 3, 2026
685dabd
fix: format MegaMOE Python files
YAMY1234 Sep 3, 2026
4129714
fix mxfp8 per layer quantization
wenscarl Sep 8, 2026
dafb544
trim docstrings
wenscarl Sep 8, 2026
7ccac6d
fix merge conflicts
wenscarl Sep 8, 2026
2c196ea
Merge branch 'main' into mega_moe_flashinfer
wenscarl Sep 8, 2026
8a84122
Merge branch 'main' into mega_moe_flashinfer
nvpohanh Sep 9, 2026
3716192
Merge commit 'refs/guardian/sglang-ci-guardian/main-f1a512c5' into HEAD
YAMY1234 Sep 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/docs/advanced_features/server_arguments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,13 @@ Please consult the documentation below and [server_args.py](https://github.com/s
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}>`auto`</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}><code>auto</code>, <code>bf16</code>, <code>fp8</code>, <code>int8</code>, <code>nvfp4</code></td>
</tr>
<tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}><code>--flashinfer-a2a-dispatch-type</code></td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>Select FlashInfer A2A dispatcher activation dtype. When omitted, it falls back to the <code>SGLANG_MOE_NVFP4_DISPATCH</code> environment variable. Explicit <code>auto</code> selects <code>mxfp8</code> for <code>--quantization mxfp8</code>, <code>nvfp4</code> for modelopt FP4 or hybrid NVFP4 MoE checkpoints, and <code>bf16</code> otherwise. The <code>SGLANG_MOE_NVFP4_DISPATCH</code> environment variable cannot be set with this argument.</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}><code>None</code></td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}><code>auto</code>, <code>bf16</code>, <code>nvfp4</code>, <code>mxfp8</code></td>
</tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}>`--ep-num-redundant-experts`</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>Allocate this number of redundant experts in expert parallel.</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}>`0`</td>
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/references/environment_variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ SGLang supports various environment variables that can be used to configure its
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>The maximum number of dispatched tokens on each GPU for --moe-a2a-backend=flashinfer</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}>`"1024"`</td>
</tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}><code>SGLANG_FLASHINFER_MEGAMOE_COMBINE_DTYPE</code></td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>FlashInfer NVFP4 MegaMOE cross-rank combine wire format. Supported values are <code>bf16</code>, <code>mxfp8</code>, and <code>nvfp4</code>. Quantized formats are incompatible with <code>SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE=1</code>.</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}><code>"bf16"</code></td>
</tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}><code>SGLANG_FLASHINFER_MEGAMOE_MAX_TOKENS_PER_RANK</code></td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>Per-rank FlashInfer MegaMOE symmetric-workspace token capacity. A value of <code>0</code> derives the capacity from the runtime token limits.</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}><code>0</code></td>
</tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}><code>SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE</code></td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>Use the CuTe DSL MegaMOE in-kernel FC2 reduction. This can reduce workspace size and improve large-batch performance, but BF16 atomic accumulation is nondeterministic. It is incompatible with quantized combine dtypes.</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.02)"}}><code>"false"</code></td>
</tr>
<tr>
<td style={{padding: "9px 12px", fontWeight: 500, backgroundColor: "rgba(255,255,255,0.02)"}}>`SGLANG_DEEPEP_LL_COMBINE_SEND_NUM_SMS`</td>
<td style={{padding: "9px 12px", backgroundColor: "rgba(255,255,255,0.05)"}}>Number of SMs used for DeepEP combine when single batch overlap is enabled</td>
Expand Down
1 change: 1 addition & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies = [
"nvidia-cutlass-dsl[cu13]==4.6.2",
"nvidia-mathdx==25.6.0",
"nvidia-ml-py",
"nvshmem4py-cu13",
"openai==2.6.1",
"openai-harmony==0.0.4",
"orjson",
Expand Down
2 changes: 2 additions & 0 deletions python/sglang/srt/arg_groups/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"flashinfer_cutlass",
"flashinfer_mxfp4",
"flashinfer_cutedsl",
"flashinfer_megamoe",
"cutlass",
"aiter",
"marlin",
Expand All @@ -161,6 +162,7 @@
MXFP8_MOE_RUNNER_BACKEND_CHOICES = [
"cutlass",
"deep_gemm",
"flashinfer_megamoe",
"flashinfer_trtllm",
"flashinfer_trtllm_routed",
]
Expand Down
6 changes: 6 additions & 0 deletions python/sglang/srt/arg_groups/fields/exec_.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class ExecMoe:
"deepep_v2",
"ascend_tp",
"pplx",
"flashinfer_megamoe",
],
Arg(
help="Choose the backend for MoE A2A.",
Expand All @@ -643,6 +644,7 @@ class ExecMoe:
"deepep_v2",
"pplx",
"ascend_tp",
"flashinfer_megamoe",
],
resolvable=True,
),
Expand Down Expand Up @@ -687,6 +689,10 @@ class ExecMoe:
Literal["auto", "bf16", "fp8", "int8", "nvfp4"],
"Select DeepEP dispatcher output dtype",
] = "auto"
flashinfer_a2a_dispatch_type: A[
Optional[Literal["auto", "bf16", "nvfp4", "mxfp8"]],
"Select FlashInfer A2A dispatcher activation dtype.",
] = None
ep_num_redundant_experts: A[
int, "Allocate this number of redundant experts in expert parallel."
] = 0
Expand Down
188 changes: 174 additions & 14 deletions python/sglang/srt/arg_groups/moe_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import parse_connector_type
from sglang.srt.utils.common import is_sm100_supported, parse_connector_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -126,6 +126,110 @@ def handle_moe_kernel_config(server_args: Any):
)


def handle_flashinfer_a2a_dispatch_type(server_args: Any):
cfg = resolving_view(server_args)
cli_dispatch_type = cfg.flashinfer_a2a_dispatch_type
nvfp4_dispatch_env_is_set = envs.SGLANG_MOE_NVFP4_DISPATCH.is_set()

if nvfp4_dispatch_env_is_set:
raise ValueError(
"SGLANG_MOE_NVFP4_DISPATCH cannot be set together with "
"--flashinfer-a2a-dispatch-type."
)

dispatch_type = cli_dispatch_type or "auto"

supports_nvfp4_dispatch = (
cfg.quantization == "modelopt_fp4"
or model_config_of(server_args).nvfp4_moe_meta is not None
)
if dispatch_type == "auto":
if cfg.quantization == "mxfp8":
dispatch_type = "mxfp8"
elif supports_nvfp4_dispatch:
dispatch_type = "nvfp4"
else:
dispatch_type = "bf16"

if dispatch_type == "mxfp8":
if cfg.quantization != "mxfp8":
raise ValueError(
"--flashinfer-a2a-dispatch-type mxfp8 requires --quantization mxfp8."
)
if cfg.moe_runner_backend != "flashinfer_trtllm_routed":
raise ValueError(
"--flashinfer-a2a-dispatch-type mxfp8 requires "
"--moe-runner-backend flashinfer_trtllm_routed."
)
elif dispatch_type == "nvfp4" and not supports_nvfp4_dispatch:
raise ValueError(
"--flashinfer-a2a-dispatch-type nvfp4 requires NVFP4/"
"modelopt-FP4 quantization or hybrid NVFP4 MoE metadata."
)

declare_resolution(
server_args,
"_handle_flashinfer_a2a_dispatch_type",
flashinfer_a2a_dispatch_type=dispatch_type,
)


def validate_flashinfer_megamoe_envs() -> None:
combine_dtype = envs.SGLANG_FLASHINFER_MEGAMOE_COMBINE_DTYPE.get().strip().lower()
if combine_dtype not in ("bf16", "mxfp8", "nvfp4"):
raise ValueError(
"SGLANG_FLASHINFER_MEGAMOE_COMBINE_DTYPE must be one of "
f"'bf16', 'mxfp8', or 'nvfp4', got {combine_dtype!r}."
)
if (
combine_dtype != "bf16"
and envs.SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE.get()
):
raise ValueError(
"SGLANG_FLASHINFER_MEGAMOE_COMBINE_DTYPE="
f"{combine_dtype!r} is incompatible with "
"SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE=1."
)


def validate_flashinfer_megamoe_model(server_args: Any) -> None:
model_config = model_config_of(server_args)
architectures = model_config.hf_config.architectures or []
validated_architectures = (
"DeepseekV2ForCausalLM",
"DeepseekV3ForCausalLM",
"DeepseekV32ForCausalLM",
"DeepseekV4ForCausalLM",
"Glm4MoeForCausalLM",
"NemotronHForCausalLM",
"NemotronHPuzzleForCausalLM",
"Qwen2MoeForCausalLM",
"Qwen3MoeForCausalLM",
)
if not any(
architecture in validated_architectures for architecture in architectures
):
raise ValueError(
"FlashInfer MegaMOE is not validated for model architectures "
f"{architectures}. Supported architectures: "
f"{sorted(validated_architectures)}."
)

quantization = resolved_view(server_args).quantization
supports_megamoe_quantization = (
quantization in ("mxfp8", "modelopt_fp4")
or model_config.is_fp4_experts
or model_config.nvfp4_moe_meta is not None
)
if not supports_megamoe_quantization:
raise ValueError(
"FlashInfer MegaMOE currently supports only MXFP8, ModelOpt "
"NVFP4, FP4-expert, or hybrid NVFP4 MoE checkpoints; got "
f"quantization={quantization!r}. Standard FP8 MoE checkpoints "
"are not supported."
)


def handle_a2a_moe(server_args: Any):
# The backend overrides and the ep_size=tp_size adjustments moved to
# the resolution pipeline (arg_groups/overrides.py:
Expand All @@ -149,6 +253,38 @@ def handle_a2a_moe(server_args: Any):
)
logger.info(f"Waterfill is enabled with moe_a2a_backend='{a2a_backend}'.")

if a2a_backend != "flashinfer" and cfg.flashinfer_a2a_dispatch_type not in (
None,
"auto",
):
raise ValueError(
"--flashinfer-a2a-dispatch-type requires --moe-a2a-backend flashinfer."
)

if a2a_backend == "flashinfer_megamoe":
Comment thread
wenscarl marked this conversation as resolved.
Resolved
validate_flashinfer_megamoe_model(server_args)
validate_flashinfer_megamoe_envs()
assert cfg.enable_dp_attention and cfg.dp_size == cfg.tp_size, (
"FlashInfer MegaMOE is only supported with dp_size == tp_size and --enable-dp-attention"
)
if resolved_view(server_args).moe_runner_backend == "auto":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug] --moe-a2a-backend flashinfer_megamoe only auto-selects --moe-runner-backend flashinfer_megamoe when the resolved runner is still "auto". handle_moe_kernel_config runs first and _moe_runner_backend_quant_constraints already rewrites MXFP8 auto to flashinfer_trtllm (allowed list now includes flashinfer_megamoe, but the default does not prefer it). The megamoe handler then skips the declare and hits assert resolved_view(...).moe_runner_backend == "flashinfer_megamoe". NVFP4 MegaMOE with auto works; MXFP8 MegaMOE, a documented format, fails at startup unless the runner is set explicitly. Tests always pass moe_runner_backend="flashinfer_megamoe", so they miss this. This is the leftover of prior issue 1 after the _declare/bag fix.

Suggestion: In _moe_runner_backend_quant_constraints, if view.moe_a2a_backend == "flashinfer_megamoe" and the runner is auto, choose flashinfer_megamoe instead of flashinfer_trtllm. Alternatively last-writer-wins declare megamoe when the operator left the runner at auto (raw input), even if MXFP8 already defaulted it. Add a unit test: dummy MXFP8 + a2a megamoe + runner auto after the real pipeline order (handle_moe_kernel_config then handle_a2a_moe).

declare_resolution(
server_args, "_handle_a2a_moe", moe_runner_backend="flashinfer_megamoe"
)
assert resolved_view(server_args).moe_runner_backend == "flashinfer_megamoe", (
"FlashInfer MegaMOE a2a backend requires --moe-runner-backend flashinfer_megamoe"
)
if not is_sm100_supported():
raise ValueError(
"FlashInfer MegaMOE currently requires an SM100-family "
"CUDA device for all supported quantization formats."
)
logger.info(
"FlashInfer MegaMOE is enabled. The expert parallel size is "
"adjusted to be the same as the tensor parallel size[%s].",
cfg.tp_size,
)

if a2a_backend == "deepep":
if cfg.moe_runner_backend == "flashinfer_cutedsl":
if cfg.deepep_mode == "auto":
Expand Down Expand Up @@ -260,7 +396,7 @@ def handle_a2a_moe(server_args: Any):
moe_a2a_backend="none",
)

if cfg.moe_a2a_backend == "flashinfer":
if a2a_now == "flashinfer":
assert (
resolved_view(server_args).enable_dp_attention
and cfg.dp_size == cfg.tp_size
Expand All @@ -273,20 +409,44 @@ def handle_a2a_moe(server_args: Any):
resolved_view(server_args).moe_runner_backend == "flashinfer_cutedsl"
and envs.SGLANG_FLASHINFER_CUTEDSL_NVFP4_W4A16.get()
)
if use_cutedsl_w4a16:
if envs.SGLANG_MOE_NVFP4_DISPATCH.get():
if use_cutedsl_w4a16 and envs.SGLANG_MOE_NVFP4_DISPATCH.get():
raise ValueError(
"CuTe DSL NVFP4 W4A16 requires BF16 FlashInfer MoE "
"dispatch; unset SGLANG_MOE_NVFP4_DISPATCH."
)
if cfg.flashinfer_a2a_dispatch_type is None:
if (
not use_cutedsl_w4a16
and not envs.SGLANG_MOE_NVFP4_DISPATCH.is_set()
and (
resolved_view(server_args).quantization == "modelopt_fp4"
or model_config_of(server_args).nvfp4_moe_meta is not None
)
):
envs.SGLANG_MOE_NVFP4_DISPATCH.set(True)
logger.warning(
"SGLANG_MOE_NVFP4_DISPATCH is set to True for Flashinfer MoE A2A"
)
else:
if resolved_view(server_args).moe_runner_backend == "flashinfer_trtllm":
declare_resolution(
server_args,
"_handle_a2a_moe",
moe_runner_backend="flashinfer_trtllm_routed",
)
logger.warning(
"Flashinfer MoE A2A is enabled with flashinfer_trtllm. "
"Using flashinfer_trtllm_routed because A2A dispatch "
"provides top-k ids and weights."
)
if use_cutedsl_w4a16 and cfg.flashinfer_a2a_dispatch_type in (
"auto",
"nvfp4",
):
raise ValueError(
"CuTe DSL NVFP4 W4A16 requires BF16 FlashInfer MoE "
"dispatch; unset SGLANG_MOE_NVFP4_DISPATCH."
"CuTe DSL NVFP4 W4A16 requires --flashinfer-a2a-dispatch-type bf16."
)
elif not envs.SGLANG_MOE_NVFP4_DISPATCH.is_set() and (
resolved_view(server_args).quantization == "modelopt_fp4"
or model_config_of(server_args).nvfp4_moe_meta is not None
):
envs.SGLANG_MOE_NVFP4_DISPATCH.set(True)
logger.warning(
"SGLANG_MOE_NVFP4_DISPATCH is set to True for Flashinfer MoE A2A"
)
handle_flashinfer_a2a_dispatch_type(server_args)
assert resolved_view(server_args).moe_runner_backend in [
"flashinfer_cutlass",
"flashinfer_cutedsl",
Expand Down
13 changes: 10 additions & 3 deletions python/sglang/srt/arg_groups/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,12 @@ def _moe_runner_backend_quant_constraints(view: Any) -> dict:
allowed = list(MXFP8_MOE_RUNNER_BACKEND_CHOICES)
if is_gfx95_mxfp8:
allowed.append("triton")
mxfp8_default = "triton" if is_gfx95_mxfp8 else "flashinfer_trtllm"

if view.moe_a2a_backend == "flashinfer_megamoe":
mxfp8_default = "flashinfer_megamoe"
else:
mxfp8_default = "triton" if is_gfx95_mxfp8 else "flashinfer_trtllm"

if moe_runner_backend == "auto":
moe_runner_backend = mxfp8_default
elif moe_runner_backend not in allowed:
Expand Down Expand Up @@ -1629,15 +1634,16 @@ def _moe_runner_fusion_disable(view: Any) -> dict:
def _a2a_fusion_adjustments(view: Any) -> dict:
"""A2A-backend-driven shared-experts fusion adjustments, declared at the
legacy write slots in _handle_a2a_moe: Waterfill requires the
fusion enabled; FlashInfer and DeepEP v2 A2A require it disabled."""
fusion enabled; FlashInfer, FlashInfer MegaMOE, and DeepEP v2 A2A require it disabled.
"""
if view.moe_a2a_backend in ("deepep", "megamoe") and view.enable_waterfill:
if view.disable_shared_experts_fusion:
logger.warning(
"disable_shared_experts_fusion is overridden to False because Waterfill requires shared expert fusion."
)
return {"disable_shared_experts_fusion": False}
return {}
if view.moe_a2a_backend == "flashinfer":
if view.moe_a2a_backend in ("flashinfer", "flashinfer_megamoe"):
logger.warning(
"Flashinfer MoE A2A is enabled. --disable-shared-experts-fusion is automatically set."
)
Expand All @@ -1658,6 +1664,7 @@ def _a2a_fusion_adjustments(view: Any) -> dict:
"nixl",
"ascend_fuseep",
"flashinfer",
"flashinfer_megamoe",
"mori",
"pplx",
"deepep_v2",
Expand Down
15 changes: 15 additions & 0 deletions python/sglang/srt/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,21 @@ class Envs:
# Per-rank dispatch capacity of the FlashInfer MoE A2A dispatcher. Unset
# means each call site keeps its own default.
SGLANG_FLASHINFER_NUM_MAX_DISPATCH_TOKENS_PER_RANK = EnvInt(None)
# FlashInfer MegaMOE (generic moe_ep.MoEEpMegaLayer backend). Sizes the
# per-rank symmetric workspace; must be >= the largest padded per-rank batch
# (derived from cuda_graph_max_bs / chunked_prefill_size when unset).
SGLANG_FLASHINFER_MEGAMOE_MAX_TOKENS_PER_RANK = EnvInt(0)
# Opt-in in-kernel FC2 top-k reduce (cross-rank REDG atomic-add) for the
# cutedsl mega kernels (NVFP4 / MXFP8). Deletes the multi-GB combine staging
# region and can win at large batch, but makes the output accumulation order
# nondeterministic (bf16 unordered sum) -- keep off for bit-reproducibility.
# No effect on the DeepGEMM (block-FP8) mega path, which lacks the knob.
SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE = EnvBool(False)
# Cross-rank combine wire format for the FlashInfer NVFP4 cutedsl MegaMOE
# kernel. "bf16" is exact/default; "mxfp8" and "nvfp4" reduce combine
# traffic with a small accuracy tradeoff and require FC2 reduce outside the
# kernel.
SGLANG_FLASHINFER_MEGAMOE_COMBINE_DTYPE = EnvStr("bf16")
# Enable per-token FP32 activation scaling for serialized ModelOpt FP4 with
# FlashInfer TRT-LLM or CuTe DSL v2 MoE.
SGLANG_FLASHINFER_NVFP4_PER_TOKEN_ACTIVATION = EnvBool(False)
Expand Down
Loading
Loading