-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[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-reasoningmodel, 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
Phi4Mambamodule 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
zParameter: Modifies the Mamba selective scan CUDA kernel and its Python wrapper to dynamically handle thezparameter, making it optional rather than a mandatory input, which improves flexibility. - Conditional Hidden State Pruning: Adds a new parameter to the
LogitsProcessorto 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.
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
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>
|
After installing vllm through source code and starting it with the following command, the following error still occurs. |
|
Hi @ZV-Liu , you need to set VLLM_ATTENTION_BACKEND to be DIFFERENTIAL_FLASH_ATTN. |
|
@ccongcong321 should that not have happened automatically? I see it being set in this PR |
|
@hmellor , it is not selected automatically for |
When using vllm, is there a switch similar to the enable_thinking of the Qwen3 series models when calling the API? |
|
Ah my mistake, it's only auto-selected in the test in |
|
AssertionError: Phi4Flash currently does not support prefix cachingI have set "Phi4Flash currently does not support prefix caching." |
Unfortunately, we do not support prefix caching because of Mamba layers. And we currently only support V0 engine. cc. @congcongchen123 |
|
@congcongchen123 @renll is V1 support planned? |
|
@sarckk , yes, we are planning to support v1 once we get more bandwidth. |
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com> Signed-off-by: x22x22 <wadeking@qq.com>
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
…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: Jinzhen Lin <linjinzhen@hotmail.com>
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com> Signed-off-by: Paul Pak <paulpak58@gmail.com>
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com> Signed-off-by: Diego-Castan <diego.castan@ibm.com>
…llm-project#20702) Signed-off-by: Congcong Chen <congcongchen@microsoft.com>
|
@ccongcong321 Was there a specific reason why this model didn't re-use |
|
Good point. Likely because development of this model pre-dated Bamba when MambaMixer2 was introduced. Rebasing was more approachable than reimplementing everything and ensured parity. Though there may be other reasons. |
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor 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