Skip to content

[MoE] Decouple Mega MoE from DeepEP backend - #24884

Merged
yhyang201 merged 7 commits into
mainfrom
yhyang201/decouple-megamoe-deepep
May 14, 2026
Merged

yhyang201 merged 7 commits into
mainfrom
yhyang201/decouple-megamoe-deepep

Conversation

@yhyang201

Copy link
Copy Markdown
Collaborator

Summary

  • Auto-configure EP (ep_size = tp_size) when SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE=1 is set, so users no longer need --moe-a2a-backend=deepep or the deep_ep library to use Mega MoE.
  • Mega MoE uses deep_gemm.fp8_fp4_mega_moe() for its own all-to-all communication and never touches the DeepEP dispatcher, so the dependency was unnecessary.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces auto-configuration for the expert parallel size when Mega MoE is enabled and no specific all-to-all backend is selected. The reviewer suggested refining the activation condition to ensure tp_size > 1, which avoids redundant operations on single-GPU setups, and recommended using a warning log level for consistency with other backend handlers.

Comment on lines +3104 to +3113
if (
envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get()
and self.moe_a2a_backend == "none"
and self.ep_size == 1
):
self.ep_size = self.tp_size
logger.info(
f"Mega MoE is enabled. The expert parallel size is adjusted "
f"to be the same as the tensor parallel size[{self.tp_size}]."
)

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.

medium

Consider adding self.tp_size > 1 to the condition and using logger.warning for consistency with other backends in this function (e.g., DeepEP, Mooncake, Mori). Adding the tp_size check avoids redundant logging and no-op assignments on single-GPU setups where expert parallelism is not applicable, while ensuring the adjustment is visible to users in multi-GPU configurations.

Suggested change
if (
envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get()
and self.moe_a2a_backend == "none"
and self.ep_size == 1
):
self.ep_size = self.tp_size
logger.info(
f"Mega MoE is enabled. The expert parallel size is adjusted "
f"to be the same as the tensor parallel size[{self.tp_size}]."
)
if (
envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get()
and self.moe_a2a_backend == "none"
and self.ep_size == 1
and self.tp_size > 1
):
self.ep_size = self.tp_size
logger.warning(
f"Mega MoE is enabled. The expert parallel size is adjusted "
f"to be the same as the tensor parallel size[{self.tp_size}]."
)

@yhyang201
yhyang201 marked this pull request as ready for review May 13, 2026 01:32
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@yhyang201

Copy link
Copy Markdown
Collaborator Author

/rerun-stage stage-c-test-dsv4-4-gpu-b200

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Triggered stage-c-test-dsv4-4-gpu-b200 to run independently (skipping dependencies). View workflow run

yhyang201 added 5 commits May 14, 2026 22:45
Auto-configure EP when SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE is set,
so users no longer need to pass --moe-a2a-backend=deepep or
install the deep_ep library to use Mega MoE.
When SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE is enabled together with
ep_size > 1, both the Mega MoE path (decode) and the normal/DeepEP
path (prefill fallback) share the same MoE weights. Auto-set
SGLANG_OPT_FIX_MEGA_MOE_MEMORY=True so they share one weight copy
instead of duplicating, saving significant GPU memory.
Add megamoe as a first-class a2a backend. It uses symmetric memory
for fused all-to-all + GEMM (decode), and falls back to
StandardDispatcher (all-reduce EP) for large prefills.

User experience:
  python -m sglang.launch_server ... --moe-a2a-backend megamoe
Replace env var reads with get_moe_a2a_backend().is_megamoe() checks.
The --moe-a2a-backend megamoe flag is now the sole way to enable
Mega MoE.
@yhyang201
yhyang201 force-pushed the yhyang201/decouple-megamoe-deepep branch from 944404c to 1554138 Compare May 14, 2026 15:14
- Use --moe-a2a-backend megamoe instead of deepep + env var
- Remove dead env vars (SGLANG_OPT_USE_FAST_MASK_EP,
  SGLANG_OPT_SWA_EVICT_DROP_PAGE_MARGIN, SGLANG_OPT_FIX_NEXTN_MEGA_MOE)
- Remove redundant env vars (SGLANG_OPT_USE_CUSTOM_ALL_REDUCE_V2,
  SGLANG_OPT_FIX_MEGA_MOE_MEMORY)
@github-actions github-actions Bot added documentation Improvements or additions to documentation deepseek labels May 14, 2026
@yhyang201

Copy link
Copy Markdown
Collaborator Author

/rerun-stage stage-c-test-dsv4-4-gpu-b200

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Triggered stage-c-test-dsv4-4-gpu-b200 to run independently (skipping dependencies). View workflow run

When set, auto-configure --moe-a2a-backend megamoe so existing
scripts using the env var continue to work.
@yhyang201

Copy link
Copy Markdown
Collaborator Author

The dpskv4 B200 test has passed. After that, only one backward-compatibility commit for an environment variable was added, so we can merge now.

@yhyang201
yhyang201 merged commit 37f030a into main May 14, 2026
69 of 80 checks passed
@yhyang201
yhyang201 deleted the yhyang201/decouple-megamoe-deepep branch May 14, 2026 18:01
@hnyls2002

Copy link
Copy Markdown
Collaborator

/rerun-test test_deepseek_v4_flash_fp4_megamoe_b200.py

@hnyls2002

Copy link
Copy Markdown
Collaborator

Dispatched on this branch:
Dispatched on this branch's revertion:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants