Skip to content

🚨 Run MXFP4 GPT-OSS experts through ep_dispatch_experts - #49613

Merged
vasqu merged 3 commits into
mainfrom
ep-mxfp4-gpt-oss
Nov 12, 2026
Merged

vasqu merged 3 commits into
mainfrom
ep-mxfp4-gpt-oss

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

Depends on #49607.

MXFP4 GPT-OSS did not run under expert parallelism on main. Loading openai/gpt-oss-20b with DistributedConfig(tp_size=2, ep_size=2) fails twice:

  • The load: rank 1 gets no expert scales (IndexError in Mxfp4Deserialize), and rank 0 gets every expert's scales. The expert params were declared with the 4-D shape of the blocks. So the loader took the 3-D scales for one expert's slice.
  • The forward: the MXFP4 MLP calls the experts with Triton routing objects. ep_dispatch_experts expects (hidden_states, top_k_index, top_k_weights), so it fails with unexpected keyword argument 'scatter_idx'.

Changes

All in integrations/mxfp4.py:

  • Mxfp4GptOssExperts.forward takes (hidden_states, top_k_index, top_k_weights), like every other experts class. routing_from_top_k builds the Triton routing metadata from them. It skips ids outside [0, num_experts), which are other ranks' routes. So every ep_implementation works.
  • Under expert parallelism, the MLP calls the router, then the experts. It checks the experts module for the EP hook, as the EP plan installs on mlp.experts.
  • On a single device, the MLP keeps the fused Triton routing, through Mxfp4GptOssExperts.forward_routed.
  • The packed expert params are declared 3-D, (experts, rows, packed bytes). EP now shards the checkpoint's blocks and scales the same way, on the expert dim.
  • routing_torch_dist is removed. It picked the local experts from LOCAL_RANK and the world size, not from the EP mesh.

🚨 Breaking changes

  • Mxfp4GptOssExperts.forward takes (hidden_states, top_k_index, top_k_weights). The old Triton routing call is forward_routed.
  • routing_torch_dist is removed.
  • Mxfp4GptOssExperts.gate_up_proj and down_proj are declared (experts, rows, packed bytes) before loading, not (experts, rows, blocks, 16).

Tests

Test Result
openai/gpt-oss-20b on 2 GPUs, ep_size=tp_size=2, against 1 GPU: 2 prompts, 48 greedy tokens identical generations with "auto", "all_reduce" and "all_to_all"
The same with the old MLP hook check illegal memory access, as the local experts get global ids
main and the parent PR fail at load and at the first forward, as described above
tests/quantization/mxfp4 on 1 GPU 19 passed, 8 skipped

#49615 then removes the router-masked plan (ep_router).

🤖 Generated with Claude Code

@IlyasMoutawwakil IlyasMoutawwakil changed the title MXFP4 GPT-OSS on ep_dispatch_experts: experts take routed tokens MXFP4 GPT-OSS and Llama 4 experts take routed tokens, so they run on ep_dispatch_experts Oct 14, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@IlyasMoutawwakil IlyasMoutawwakil changed the title MXFP4 GPT-OSS and Llama 4 experts take routed tokens, so they run on ep_dispatch_experts MXFP4 GPT-OSS on ep_dispatch_experts: experts take routed tokens Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: llama4

@vasqu vasqu left a comment

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.

Yes fine for now, imo we should deprecate them all in a follow up with finegrained but better to fix for now indeed

@vasqu

vasqu commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Should be marked as 🚨 no?

@IlyasMoutawwakil IlyasMoutawwakil changed the title Run MXFP4 GPT-OSS experts through ep_dispatch_experts 🚨 Run MXFP4 GPT-OSS experts through ep_dispatch_experts Nov 2, 2026
@IlyasMoutawwakil

Copy link
Copy Markdown
Member Author

yes done, the desc also lists the breaking changes now

@vasqu vasqu left a comment

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.

As mentioned internally, just let's make sure it doesnt interfere with #50245

@IlyasMoutawwakil
IlyasMoutawwakil enabled stacked auto-merge November 12, 2026 15:02
@IlyasMoutawwakil
IlyasMoutawwakil added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Nov 12, 2026
@IlyasMoutawwakil
IlyasMoutawwakil added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Nov 12, 2026
@IlyasMoutawwakil
IlyasMoutawwakil enabled stacked auto-merge November 12, 2026 16:01
@IlyasMoutawwakil
IlyasMoutawwakil added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Nov 12, 2026
Base automatically changed from ep-move-router-plans to main November 12, 2026 16:12
IlyasMoutawwakil and others added 3 commits November 12, 2026 16:12
…on `ep_dispatch_experts`

`Mxfp4GptOssExperts.forward` takes `(hidden_states, top_k_index, top_k_weights)` like every other experts class and
builds the Triton routing metadata for its own experts from them (`routing_from_top_k`), skipping other ranks'
routes. Under expert parallelism the patched MLP calls the router, then the experts, so every `ep_strategy` applies;
single-device inference keeps the fused Triton routing through `forward_routed`. Replaces `routing_torch_dist`, which
picked the local experts from `LOCAL_RANK` and the world size rather than the EP mesh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ms 3-D so EP shards the scales

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vasqu
vasqu enabled stacked auto-merge November 12, 2026 16:14
@vasqu
vasqu added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 95e9b5f Nov 12, 2026
123 of 124 checks passed
@vasqu
vasqu deleted the ep-mxfp4-gpt-oss branch November 12, 2026 16:43
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.

3 participants