Skip to content

[XPU] Route grouped_topk to the fused _moe_C kernel on XPU - #53580

Merged
jikunshang merged 4 commits into
vllm-project:mainfrom
mfylcek:xpu/enable-fused-grouped-topk
Sep 7, 2026
Merged

[XPU] Route grouped_topk to the fused _moe_C kernel on XPU#53580
jikunshang merged 4 commits into
vllm-project:mainfrom
mfylcek:xpu/enable-fused-grouped-topk

Conversation

@mfylcek

@mfylcek mfylcek commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

vllm-xpu-kernels ships a fused grouped_topk (noaux_tc) kernel registered into the same _moe_C::grouped_topk op that CUDA uses, but both gates guarding it test is_cuda(), so XPU always fell back to the eager decomposition.

This PR routes grouped_topk to the fused _moe_C kernel on XPU and registers a fake (meta) implementation for _moe_C::grouped_topk, which previously had only device kernels and no meta kernel, so torch.compile could not trace through it resulting in graph breaks (not XPU-specific — adding the meta implementation helps on CUDA too).

Affects: every DeepSeek-V3-style (noaux_tc) MoE model — DeepSeek-V3/R1, Kimi-K2.6, Trinity-Nano, Ling/Bailing, GLM-4.5, Longcat-Flash

Test Result

Tested model: arcee-ai/Trinity-Nano-Base
Inputs: 4096-in / 1024-out, concurrency 48
B70 XPU

arm out tok/s vs eager+native vs default latency (s) routing kernel (ms) routing launches total launches compiled regions
eager + native 1066.1 -6.2% 46.11 269.0 33,912 174,119 2
eager + fused 1149.8 +7.9% +1.2% 42.75 224.1 4,752 142,205 6
torch.compile + native (current default) 1136.1 +6.6% 43.26 268.2 33,912 140,943 4
torch.compile + fused 1203.6 +12.9% +5.9% 40.84 225.3 4,752 109,029 8
torch.compile + fused + meta impl 1213.0 +13.8% +6.8% 40.52 225.1 4,752 109,029 4

@mergify mergify Bot added the intel-gpu Related to Intel GPU label Aug 24, 2026
@mfylcek
mfylcek marked this pull request as ready for review September 1, 2026 10:09

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mfylcek

mfylcek commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@jikunshang @yma11
Could you review?

@yma11

yma11 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Code change looks good to me. Can you provide data for model zai-org/GLM-4.7-Flash?

@mfylcek

mfylcek commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@yma11

GLM-4.7-Flash, 128-in/128-out, concurrency 32, TP=4 on 4× B70:

arm total tok/s output tok/s Δ vs eager/native Δ vs default
eager / native 681.52 340.76 +1.4%
eager / fused 725.38 362.69 +6.4% +7.9%
tc / native (default) 672.31 336.16 −1.4%
tc / fused 700.49 350.25 +2.8% +4.2%
tc / fused + fake 739.35 369.68 +8.5% +10.0%

@yma11

yma11 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@jikunshang PTAL, thanks.

@jikunshang

Copy link
Copy Markdown
Member

please rebase and fix dco issue. thanks.

@jikunshang jikunshang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mfylcek and others added 2 commits September 2, 2026 10:04
vllm-xpu-kernels ships a fused grouped_topk (noaux_tc) kernel registered
into the same `_moe_C::grouped_topk` op that CUDA uses, but both gates
guarding it test `is_cuda()`, so XPU always fell back to the eager
decomposition: 3 `aten::topk` launches plus ~10 elementwise ops per MoE
layer per step.

Measured on 1x BMG B70, arcee-ai/Trinity-Nano-Base (128 experts, topk=8,
n_group=1, sigmoid + noaux_tc, 54 MoE layers), bf16, TP=1, eager:

- routing device time 5.538 ms -> 2.469 ms over 3 steps (14.49% -> 7.25%
  of total device time), `aten::topk` disappears from the trace
- mean TPOT 58.79 ms -> 56.70 ms (-3.6%), median ITL -4.3%, against a
  0.5-0.65% run-to-run noise floor measured by repeating the baseline
- fp32 selection is bit-identical to the eager reference (max weight
  delta 8.9e-8); bf16 differs only on biased-score ties

The kernel's coverage matches vLLM's CUDA gate exactly (noaux_tc with a
non-None e_score_correction_bias, n_group <= 32, topk <= 32), so no
additional guard is needed on XPU.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Marceli Fylcek <marceli.fylcek@intel.com>
`_moe_C::grouped_topk` returns `(Tensor, Tensor)` and has no Meta kernel
on either backend, so Dynamo cannot fake-tensor it and splits the routing
graph around every call. Both backends allocate the outputs the same way
(`new_empty` on `scores`, `(num_tokens, topk)`, float32 values and int32
indices), so one Python fake covers CUDA and XPU.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Marceli Fylcek <marceli.fylcek@intel.com>
@mfylcek
mfylcek force-pushed the xpu/enable-fused-grouped-topk branch from 6fb1ad2 to b60a18d Compare September 2, 2026 08:12
@mfylcek

mfylcek commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@jikunshang 'verified' label is needed

@jikunshang jikunshang added the verified Run pre-commit for new contributors without triggering other tests label Sep 2, 2026
@jikunshang

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86958 for commit 5ecb103732ee.

@mfylcek

mfylcek commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #87217 for commit 64a613abaf8c.

@mfylcek

mfylcek commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@jikunshang

@jikunshang
jikunshang merged commit 9b85112 into vllm-project:main Sep 7, 2026
131 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

intel-gpu Related to Intel GPU verified Run pre-commit for new contributors without triggering other tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants