-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[Model] New model support for microsoft/Phi-4-mini-flash-reasoning #20702
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
[Model] New model support for microsoft/Phi-4-mini-flash-reasoning #20702
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 @congcongchen123, 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 full support for the microsoft/Phi-4-mini-flash-reasoning
model, which utilizes a novel hybrid architecture integrating both FlashAttention and Mamba (State Space Model) layers. The changes involve implementing a new 'Differential FlashAttention' backend, integrating Mamba's selective scan and causal convolution operations, and enhancing the KV cache management system to support cross-layer sharing, optimizing memory usage for this complex model.
Highlights
- New Model Support: Adds comprehensive support for the
microsoft/Phi-4-mini-flash-reasoning
model, which features a hybrid architecture combining FlashAttention and Mamba (SSM) layers. - Differential FlashAttention Backend: Introduces a specialized attention backend (
DifferentialFlashAttentionBackend
) designed for the Phi-4 model, implementing a unique 'differential' attention mechanism with split QKV and KV cache handling. - Mamba (SSM) Integration: Implements the
Phi4Mamba
module to support the State Space Model components of the Phi-4 architecture, including causal convolution and selective scan operations, with specific handling for KV cache sharing (yoco_kv
,yoco_cross
). - Cross-Layer KV Cache Sharing: Enhances the KV cache management system to support cross-layer KV cache sharing, allowing certain attention layers to reuse the KV cache from other layers, which can lead to significant memory savings for the Phi-4 model's hybrid architecture.
- Dynamic SSM
z
Parameter: Modifies the Mamba selective scan CUDA kernel and its Python wrapper to dynamically handle thez
parameter, making it optional rather than a mandatory input, which improves flexibility. - Conditional Hidden State Pruning: Adds a new parameter to the
LogitsProcessor
to conditionally prune hidden states, enabling optimization for specific model architectures like Phi-4 where intermediate states might be truncated.
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
The pull request introduces a new model architecture, Phi4Flash, with a hybrid Mamba/Attention mechanism and cross-layer KV cache sharing. The changes involve modifications to CUDA kernels, attention backends, model layers, and configuration files. The review focuses on ensuring the correctness, maintainability, and performance of the new implementation, particularly concerning the handling of conditional logic, error conditions, and integration with existing vLLM features.
ssm_output = None | ||
for i in range(self.start_layer, self.end_layer): | ||
layer = self.layers[i] | ||
if i == self.config.num_hidden_layers // 2 + 2: |
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.
The condition if i == self.config.num_hidden_layers // 2 + 2:
is used to conditionally execute code during a profile run. Ensure that this condition accurately identifies the intended layer for profiling and that the profiling logic does not inadvertently affect the behavior of other layers or the overall model execution.
vllm/attention/layer.py
Outdated
# if not envs.VLLM_USE_V1: | ||
# raise NotImplementedError( | ||
# "Cross-layer KV sharing is not supported in V0.") |
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.
479eb8a
to
0e20e17
Compare
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.
I like the current kv sharing implementation. It is quite clean. But not sure whether cross_layer_shared_block_tables
is necessary.
Please add the required test as mentioned here https://docs.vllm.ai/en/latest/contributing/model/tests.html#required-tests
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
4e92996
to
1ff7eeb
Compare
LGTM, congrats on the model launch -- @heheda12345 is it good to land from your end? |
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.
Only some small comments.
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.
Where is the check for YOCO and chunk prefill now?
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.
LGTM! Thanks for your effort. Looking forward to v1 integration.
Took a look at the CI failures, they are unrelated to this PR, is it possible to merge this PR without rerunning the CIs? |
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com> Signed-off-by: Patrick von Platen <patrick.v.platen@gmail.com>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
New Model for https://huggingface.co/microsoft/Phi-4-mini-flash-reasoning
co-author: @aatkinson and @renll
Test Plan
Test Result
(Optional) Documentation Update