-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
MLA - Flashinfer Ragged Prefill #20034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
👋 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. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run 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 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @alexm-redhat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces the initial integration of FlashInfer's ragged prefill functionality into the MLA backend. The aim is to leverage FlashInfer for prefill operations, with current benchmarks indicating a performance regression compared to the existing FlashAttention 2 implementation. The changes primarily involve setting up FlashInfer-specific metadata, managing its prefill wrappers, and adapting the attention computation logic to utilize the new backend, along with an updated example for testing.
Highlights
- FlashInfer Ragged Prefill Integration: I've integrated FlashInfer's
BatchPrefillWithRaggedKVCacheWrapper
to handle ragged prefill operations within the Multi-Layer Attention (MLA) backend. This involves setting up the necessary FlashInfer wrappers and planning their execution. - FlashInfer-Specific Metadata and Hyperparameter Management: I've introduced a new
FIPrefillMetadata
dataclass to store FlashInfer-specific prefill parameters and wrappers. Additionally, I've added logic to extract and validate attention layer hyperparameters (such as window size and scale) from the VLLM configuration, ensuring these are consistent and correctly passed to the FlashInfer kernels. - Attention Logic Adaptation for Prefill: The core attention computation paths for prefill (
_compute_prefill_context
and_forward_prefill
) have been updated. They now utilize a new_fi_prefill_run
method, which dispatches to the FlashInfer prefill kernel, replacing the previous FlashAttention 2 calls for these operations. - Model Update for Benchmarking: The
basic.py
offline inference example has been updated to use thedeepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
model. This change facilitates focused testing and benchmarking of the new FlashInfer ragged prefill integration with a specific model.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this 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 FlashInfer ragged prefill for the DeepSeek-Coder-V2-Lite-Instruct model. While the changes have correctness, there's a performance slowdown. The author is actively working on improvements like enabling CUDA graph and trace profiling. The review identifies areas for code cleanup, consistency, and verification of key logic.
cu_seqlens_q=attn_metadata.prefill.query_start_loc, | ||
cu_seqlens_k=attn_metadata.prefill.query_start_loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_seqlen_q=attn_metadata.prefill.max_query_len, | ||
max_seqlen_k=attn_metadata.prefill.max_query_len, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cu_seqlens_q=attn_metadata.prefill.query_start_loc, | ||
cu_seqlens_k=attn_metadata.prefill.query_start_loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_seqlen_q=attn_metadata.prefill.max_query_len, | ||
max_seqlen_k=attn_metadata.prefill.max_query_len, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -564,6 +564,8 @@ def forward( | |||
""" | |||
assert output is not None, "Output tensor must be provided." | |||
|
|||
print("kv_cache.shape = {}".format(kv_cache.shape)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
192, #head_dim_qk, | ||
causal=True, | ||
head_dim_vo=128, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
192, #head_dim_qk, | ||
causal=False, | ||
head_dim_vo=128, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# print("INSIDE forward") | ||
# print(" kv_cache.shape = {}".format(kv_cache.shape)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a draft PR that runs the flashinfer ragged prefill for deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct. It is in rough form but has correctness. Currently, there is a slowdown for using the flashinfer ragged prefill. For example:
Batch size 1 with FlashInfer Ragged Prefill
Batch size 1 with the original main - uses FA2 for prefill
Batch size 100 with FlashInfer Ragged Prefill
Batch size 100 with the original main - uses FA2 for prefill
Things I'm currently doing to improve this result: