Skip to content

[SGLANG] Enable test_fused_moe.py in the MoE suite - #7886

Open
wdziurdz wants to merge 1 commit into
mainfrom
sglang-enable-fused-moe
Open

[SGLANG] Enable test_fused_moe.py in the MoE suite#7886
wdziurdz wants to merge 1 commit into
mainfrom
sglang-enable-fused-moe

Conversation

@wdziurdz

Copy link
Copy Markdown
Contributor

Enables the upstream test_fused_moe.py in --sglang-moe, which until now could not even import on XPU because srt/layers/activation.py imports sgl_kernel at module level. The patch adds a native fallback for that import and makes the fp8 capability check skip rather than raise on XPU, where get_device_capability() returns (None, None).

sgl-kernel is intentionally removed from the XPU environment by
install-sglang.sh, but the Triton MoE path imports it unconditionally in its
`elif _is_xpu:` branches, so the test fails at collection with
ModuleNotFoundError.

Guarding the imports alone is not enough: moe_align_block_size and
topk_softmax resolve to AOT sgl_kernel ops with no Triton or JIT backend
registered in sglang, so the test would import and then fail at call time.
Patch the imports and add fallbacks:

- activation.py: guard silu_and_mul / gelu_and_mul / gelu_tanh_and_mul and
  fall back to the same math forward_native uses.
- triton_utils/fused_moe.py: clear _is_xpu on ImportError so the existing
  native silu_and_mul and moe_sum_reduce_triton paths are selected.
- triton_utils/moe_align_block_size.py: torch expert grouping producing the
  same layout, sentinel padding and per-block expert ids. Raises
  NotImplementedError for the expert-parallel -1 sentinel instead of silently
  miscomputing.
- moe/topk.py: torch topk_softmax shim, leaving topk_sigmoid undefined as the
  non-XPU branch already does.

Also patches the fp8 capability check in the test, which assumes a CUDA-style
get_device_capability(), and adds test_fused_moe.py to the sglang_moe suite.

No Triton backend change is needed: the kernels the test exercises
(fused_moe_kernel, moe_sum_reduce_triton) pass the test's full
m/n/k/e/topk/dtype sweep on XPU.

Signed-off-by: Witold Dziurdz <witold.dziurdz@intel.com>
@wdziurdz
wdziurdz force-pushed the sglang-enable-fused-moe branch from 26c8676 to 97671a7 Compare September 1, 2026 11:28
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.

1 participant