Skip to content

Conversation

@ILikeIneine
Copy link
Contributor

@ILikeIneine ILikeIneine commented Sep 28, 2025

Purpose

add platform interface to support loading kernel
relate to: #25822

Test Plan

Test Result


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.

@mergify mergify bot added the tpu Related to Google TPUs label Sep 28, 2025
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 refactors kernel loading to be platform-specific by introducing import_general_kernels and import_moe_kernels methods in the Platform interface. The changes in _custom_ops.py now delegate kernel imports to the current platform. The default implementation is provided in interface.py, and TpuPlatform and XPUPlatform provide overrides.

My review identifies a couple of areas for improvement. The error logging in _custom_ops.py should be generalized to avoid confusion. Additionally, for consistency and correctness, the TpuPlatform and XPUPlatform should also override the import_moe_kernels method, similar to how import_general_kernels is handled.

Copy link
Collaborator

@NickLucche NickLucche left a comment

Choose a reason for hiding this comment

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

Clean change thank you @ILikeIneine !
Left a minor comment agreeing with @ProExpertProg .
I am not too enthusiastic with the import_general_kernels function name, but I am also not great with names. What do you think of:
-import_core_kernels
-import_base_kernels
-import_common_kernels

Other than that this is LGTM.

@ILikeIneine
Copy link
Contributor Author

ILikeIneine commented Sep 30, 2025

@NickLucche @ProExpertProg Changes are updated! Still I'm using import_core_kernels, need it being try_import_core_kernels? Though it should stop if import_core_kernels failed. I don't think we should give it a try😂

@NickLucche
Copy link
Collaborator

Though it should stop if import_core_kernels failed

I agree in principle, I think the try-except guard we have right now it's just for cases where vllm is compiled without a device (eg you just run benchmarks).
Let's wait for @ProExpertProg to ack here.

Copy link
Collaborator

@ProExpertProg ProExpertProg left a comment

Choose a reason for hiding this comment

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

Much cleaner, thanks! Name seems fine to me now

@ProExpertProg ProExpertProg enabled auto-merge (squash) October 1, 2025 15:08
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 1, 2025
@mergify
Copy link

mergify bot commented Oct 3, 2025

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

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 Oct 3, 2025
auto-merge was automatically disabled October 4, 2025 03:54

Head branch was pushed to by a user without write access

@mergify mergify bot removed the needs-rebase label Oct 4, 2025
@ILikeIneine
Copy link
Contributor Author

Hi, seems the pr tests are not blocked by this pr, could you take a look and re-trigger the CI? or merge directly? @NickLucche @ProExpertProg

Signed-off-by: Hank <hcc.mayday@gmail.com>
Signed-off-by: Hank <hcc.mayday@gmail.com>
@ILikeIneine ILikeIneine force-pushed the support-load-kernels-from-plugin branch from dee9eb8 to 0358999 Compare October 5, 2025 02:20
Signed-off-by: Hank <hcc.mayday@gmail.com>
@NickLucche NickLucche merged commit 17edd8a into vllm-project:main Oct 5, 2025
45 checks passed
import vllm._moe_C # noqa: F401
supports_moe_ops = True
current_platform.import_core_kernels()
supports_moe_ops = current_platform.try_import_moe_kernels()
Copy link
Member

Choose a reason for hiding this comment

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

this attribute is only used here:

if supports_moe_ops and hasattr(torch.ops._moe_C, "marlin_gemm_moe"):

I wonder if we can remove supports_moe_ops and just do:

if hasattr(torch.ops, "_moe_C") and hasattr(torch.ops._moe_C, "marlin_gemm_moe"):

then having a simple import_kernels interface for the platform class would sounds better.

cc @NickLucche

Copy link
Member

Choose a reason for hiding this comment

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

@ProExpertProg do you know why we don't use if hasattr(torch.ops, "_moe_C") and hasattr(torch.ops._moe_C, "marlin_gemm_moe"): in the first place? or maybe @tlrmchlsmth @bnellnm have better ideas.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Using hasattr seems reasonable to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah ++ that seems simpler

tomeras91 pushed a commit to tomeras91/vllm that referenced this pull request Oct 6, 2025
Signed-off-by: Hank <hcc.mayday@gmail.com>
Signed-off-by: Tomer Asida <57313761+tomeras91@users.noreply.github.com>
karan pushed a commit to karan/vllm that referenced this pull request Oct 6, 2025
Signed-off-by: Hank <hcc.mayday@gmail.com>
Signed-off-by: Karan Goel <3261985+karan@users.noreply.github.com>
southfreebird pushed a commit to southfreebird/vllm that referenced this pull request Oct 7, 2025
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 10, 2025
Signed-off-by: Hank <hcc.mayday@gmail.com>
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
lywa1998 pushed a commit to lywa1998/vllm that referenced this pull request Oct 20, 2025
alhridoy pushed a commit to alhridoy/vllm that referenced this pull request Oct 24, 2025
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 24, 2025
Signed-off-by: Hank <hcc.mayday@gmail.com>
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
rtourgeman pushed a commit to rtourgeman/vllm that referenced this pull request Nov 10, 2025
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 tpu Related to Google TPUs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants