Skip to content

[Misc][Refactor] Add FusedMoERouter object#30519

Merged
robertgshaw2-redhat merged 7 commits intovllm-project:mainfrom
neuralmagic:fused-moe-router
Jan 8, 2026
Merged

[Misc][Refactor] Add FusedMoERouter object#30519
robertgshaw2-redhat merged 7 commits intovllm-project:mainfrom
neuralmagic:fused-moe-router

Conversation

@bnellnm
Copy link
Collaborator

@bnellnm bnellnm commented Dec 11, 2025

Purpose

Add abstract FusedMoERouter class that provides select_experts. There's a concrete subclass that wraps FusedMoE._select_experts that is passed to all the quantization methods instead of calling FusedMoE._select_experts directly. This is a step on teasing out the routing logic from FusedMoE.apply.

See #28408

Test Plan

Existing CI

Test Result

cc @robertgshaw2-redhat


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 a FusedMoERouter abstraction to decouple the expert routing logic from the FusedMoE layer. This is a significant refactoring that touches many files across the Mixture-of-Experts (MoE) implementation, including various quantization methods. The changes are applied consistently, with the apply methods of FusedMoEMethodBase subclasses now accepting a router object. A default implementation, FusedMoERouterImpl, is provided to delegate routing calls back to the FusedMoE layer, ensuring no functional changes in this PR. This is a solid architectural improvement that paves the way for easier implementation of new routing strategies. The changes are well-executed and I found no issues.

@bnellnm bnellnm force-pushed the fused-moe-router branch 2 times, most recently from 40201d7 to 5fab8b3 Compare December 11, 2025 23:16
@bnellnm bnellnm changed the title [Kernels][MoE] Add FusedMoERouter object [Misc][Refactor] Add FusedMoERouter object Dec 12, 2025
@bnellnm bnellnm marked this pull request as ready for review December 12, 2025 17:54
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@mergify
Copy link

mergify bot commented Dec 18, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bnellnm.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify
Copy link

mergify bot commented Jan 6, 2026

Hi @bnellnm, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

1 similar comment
@mergify
Copy link

mergify bot commented Jan 6, 2026

Hi @bnellnm, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@mergify
Copy link

mergify bot commented Jan 6, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bnellnm.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Jan 6, 2026
@mergify mergify bot removed the needs-rebase label Jan 6, 2026
@mergify
Copy link

mergify bot commented Jan 6, 2026

Hi @bnellnm, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@@ -293,6 +294,23 @@ def maybe_roundup_hidden_size(
return hidden_size


class FusedMoERouterImpl(FusedMoERouter):
Copy link
Collaborator

@robertgshaw2-redhat robertgshaw2-redhat Jan 6, 2026

Choose a reason for hiding this comment

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

Is the idea that eventually we will have N of these, 1 for each routing_method_type?

And then that FusedMoERouter would not have the layer as an attr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, see #30623

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And also #30573 (which comes before #30623)

@robertgshaw2-redhat
Copy link
Collaborator

this generally looks good to me. The pre-commit is a real error

To confirm, the long term plan is something like this:

class DeepSeekV2MoELayer:
     - gate()
     - sharedexpert()
     - router() << so the "router" is not owned by the MoEMethod
     - experts()

@mergify
Copy link

mergify bot commented Jan 7, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bnellnm.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot removed the needs-rebase label Jan 7, 2026
@robertgshaw2-redhat robertgshaw2-redhat enabled auto-merge (squash) January 7, 2026 21:17
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 7, 2026
@robertgshaw2-redhat
Copy link
Collaborator

LGTM

@mergify
Copy link

mergify bot commented Jan 8, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bnellnm.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify
Copy link

mergify bot commented Jan 8, 2026

Hi @bnellnm, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@mergify
Copy link

mergify bot commented Jan 8, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bnellnm.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Jan 8, 2026
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: Bill Nell <bnell@redhat.com>
auto-merge was automatically disabled January 8, 2026 17:55

Head branch was pushed to by a user without write access

@mergify mergify bot removed the needs-rebase label Jan 8, 2026
@robertgshaw2-redhat robertgshaw2-redhat enabled auto-merge (squash) January 8, 2026 20:44
@robertgshaw2-redhat robertgshaw2-redhat merged commit e74698c into vllm-project:main Jan 8, 2026
61 checks passed
yugong333 pushed a commit to yugong333/vllm that referenced this pull request Jan 9, 2026
Signed-off-by: Bill Nell <bnell@redhat.com>
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Jan 16, 2026
Signed-off-by: Bill Nell <bnell@redhat.com>
dsuhinin pushed a commit to dsuhinin/vllm that referenced this pull request Jan 21, 2026
Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
ItzDEXX pushed a commit to ItzDEXX/vllm that referenced this pull request Feb 19, 2026
Signed-off-by: Bill Nell <bnell@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants