Skip to content

[Refact]Refact MLA/SFA weight prefetch to consist with moe weight prefetch#6629

Merged
wangxiyuan merged 8 commits intovllm-project:mainfrom
leo-pony:weight_prefetch_p2
Feb 10, 2026
Merged

[Refact]Refact MLA/SFA weight prefetch to consist with moe weight prefetch#6629
wangxiyuan merged 8 commits intovllm-project:mainfrom
leo-pony:weight_prefetch_p2

Conversation

@leo-pony
Copy link
Copy Markdown
Collaborator

@leo-pony leo-pony commented Feb 9, 2026

What this PR does / why we need it?

  1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight prefetch
  2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

Does this PR introduce any user-facing change?

NA

How was this patch tested?

  1. Performance result:
    Perf test data:
    *) MLA:
1st test 2nd test Output Token Throughput(Avg) Performance improvement percentage
o_proj duplicate prefetch 11.9669 token/s 12.0287 token/s 11.9978
o_proj no duplicate prefetch 12.5594 token/s 12.6216 token/s 12.5905 4.94%

single layer performace improve: 5%~8%

*) SFA:

1st test 2nd test Output Token Throughput(Avg) Performance improvement percentage
o_proj duplicate prefetch 13.0523 token/s 13.1084 token/s 13.08035
o_proj no duplicate prefetch 13.9844 token/s 14.1678 token/s 14.0761 7.6%
  1. Accuracy test result:
9ec9e8c3-e5b2-4bd6-a2ef-4b5e9cdd1abb
  1. Performance profiling record
    Profiling duplicated o_proj weight prefetch been removed:
    *) before:
f0fa60568ca19a69ec09393d4d37c21e *) After, duplicated o_proj weight prefetch has been remove: 0099cdc2720093c8aec6497ff9d4eeb4

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @leo-pony, 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 significantly refactors the weight prefetching architecture for MLA and SFA attention modules, bringing their implementation in line with the MoE weight prefetching strategy. The changes aim to streamline the prefetching logic by centralizing control and introducing a more robust, unified method for handling weight prefetch operations. This refactoring also includes specific optimizations, such as conditionally skipping prefetching for certain quantized weights, to improve overall efficiency and maintainability.

Highlights

  • Unified Weight Prefetching: Refactored MLA (Multi-Layer Attention) and SFA (Self-Attention) weight prefetching mechanisms to align with the existing MoE (Mixture of Experts) weight prefetch logic, centralizing control within the WeightPrefetchMethod class.
  • Centralized Prefetch Control: Removed individual enable_prefetch flags from MLAImpl and SFAImpl classes, consolidating the prefetch enablement into a single other_prefetch_enable attribute within WeightPrefetchMethod.
  • New Prefetch Method: Introduced a new method, maybe_prefetch_weight_in_current_stream, within WeightPrefetchMethod to encapsulate the general weight prefetching logic, replacing direct calls to the older maybe_npu_prefetch function.
  • Quantization-Aware Prefetching: Added a condition to skip output projection (o_proj) weight prefetching for models using AscendW8A8LinearMethod quantization in both MLA and SFA modules, optimizing performance for these specific configurations.
  • Improved MoE Prefetch Robustness: Enhanced the maybe_prefetch_moe_weight_preprocess method with null checks for forward_context and model_instance to prevent potential errors during MoE weight prefetching.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • vllm_ascend/attention/mla_v1.py
    • Updated imports to use get_weight_prefetch_method from vllm_ascend.utils and removed the import of maybe_npu_prefetch.
    • Removed the self.enable_prefetch attribute from the MLAImpl class constructor.
    • Replaced direct calls to maybe_npu_prefetch with weight_prefetch_method.maybe_prefetch_weight_in_current_stream for fused_qkv_a_proj and o_proj weights.
    • Added a conditional check to prevent o_proj weight prefetching when using AscendW8A8LinearMethod quantization.
  • vllm_ascend/attention/sfa_v1.py
    • Updated imports to use get_weight_prefetch_method from vllm_ascend.utils and removed the import of maybe_npu_prefetch.
    • Removed the self.enable_prefetch attribute from the SFAImpl class constructor.
    • Replaced direct calls to maybe_npu_prefetch with weight_prefetch_method.maybe_prefetch_weight_in_current_stream for fused_qkv_a_proj and o_proj weights.
    • Added a conditional check to prevent o_proj weight prefetching when using AscendW8A8LinearMethod quantization.
  • vllm_ascend/ops/weight_prefetch.py
    • Added self.other_prefetch_enable attribute to the WeightPrefetchMethod constructor to centralize the enable/disable flag for non-MoE prefetching.
    • Introduced null checks for forward_context and forward_context.model_instance in maybe_prefetch_moe_weight_preprocess for increased robustness.
    • Implemented a new method maybe_prefetch_weight_in_current_stream within WeightPrefetchMethod to handle general weight prefetching logic, utilizing the other_prefetch_enable flag.
Activity
  • The pull request was initiated by leo-pony.
  • All Continuous Integration (CI) tests have passed, indicating the changes are functional and do not introduce regressions.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

Signed-off-by: leo-pony <nengjunma@outlook.com>
Copy link
Copy Markdown
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 is a good refactoring that unifies the weight prefetch logic for MLA/SFA with the MoE implementation, improving code consistency and maintainability. I have one comment regarding a redundant import. Additionally, I've provided suggestions for the PR title and summary to align with the project's style guide.

Suggested PR Title:

[Attention][Refact] Unify MLA/SFA weight prefetch with MoE prefetch

Suggested PR Summary:

### What this PR does / why we need it?
This pull request refactors the weight prefetching mechanism for Multi-Head Latent Attention (MLA) and Sparse Flash Attention (SFA) to align with the implementation used for Mixture-of-Experts (MoE) models.

Key changes include:
- Centralizing the prefetching logic by introducing a new method `maybe_prefetch_weight_in_current_stream` in the `WeightPrefetchMethod` class.
- Replacing direct calls to `maybe_npu_prefetch` in `mla_v1.py` and `sfa_v1.py` with the new unified method.
- Adding an optimization to skip prefetching for `o_proj` weights when W8A8 quantization is used.
- Adding a defensive check in `maybe_prefetch_moe_weight_preprocess` to prevent potential `None` access errors.

These changes improve code consistency and maintainability by reducing code duplication and creating a single, unified path for weight prefetching.

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?
- vLLM version: v0.15.0
- vLLM main: https://github.com/vllm-project/vllm/commit/d7e17aaacd5ed1b4b4be6bcfef3a1b7cbc84fc9a

Comment thread vllm_ascend/attention/mla_v1.py Outdated
Signed-off-by: leo-pony <nengjunma@outlook.com>
Comment thread vllm_ascend/attention/sfa_v1.py Outdated
Comment thread vllm_ascend/attention/sfa_v1.py
Comment thread vllm_ascend/ops/weight_prefetch.py Outdated
Signed-off-by: leo-pony <nengjunma@outlook.com>
@leo-pony leo-pony requested a review from wangxiyuan as a code owner February 9, 2026 10:03
Signed-off-by: leo-pony <nengjunma@outlook.com>
Signed-off-by: leo-pony <nengjunma@outlook.com>
@leo-pony leo-pony added ready-for-test start test by label for PR ready read for review and removed ready read for review ready-for-test start test by label for PR labels Feb 9, 2026
Signed-off-by: leo-pony <nengjunma@outlook.com>
@leo-pony leo-pony added ready read for review ready-for-test start test by label for PR and removed ready read for review ready-for-test start test by label for PR labels Feb 9, 2026
@wangxiyuan wangxiyuan merged commit 66b60c9 into vllm-project:main Feb 10, 2026
27 checks passed
845473182 pushed a commit to 845473182/vllm-ascend that referenced this pull request Feb 11, 2026
…to qwen3next_rebase

* 'main' of https://github.com/vllm-project/vllm-ascend:
  [Feat] 310p support MoE W8A8 quantizaition (vllm-project#6641)
  [TEST]add a qwen3-30b acc case with mooncake mempool (vllm-project#6244)
  [MOE Refactor] Remove QuantType in prepare_finalize.py (vllm-project#6534)
  [EPLB] Avoiding eplb's dependency on a specified model (vllm-project#6528)
  [Doc][Misc] Restructure tutorial documentation (vllm-project#6501)
  implement batch invariant with ascendc (vllm-project#6590)
  [Refact]Refact MLA/SFA weight prefetch to consist with moe weight prefetch (vllm-project#6629)
  [Misc] upgrade to vllm main (vllm-project#6646)
  [main][Docs] Fix spelling errors across documentation (vllm-project#6649)
  [bugfix]Fix no attribute 'data' when MLAPO is enable  (vllm-project#6601)
  [DOC]Add Memcache Usage Guide (vllm-project#6476)
  [main][bugfix] Fix spec acceptance rate problem in vllm_0.15.0 (vllm-project#6606)
  [Test][LoRA] Add e2e test for base model inference (vllm-project#6624)
  [refactor]Optimized the kvcache usage of Deepseek v3.2 (vllm-project#6610)
  [Feat](sfa,dcp) support dcp for sfa (vllm-project#6563)
  [BugFix] Add support for rotary_dim parameter when using partial rope in rotary_embedding (vllm-project#6581)
  [fix bug] fix tensor mismatch bug in sigmoid operate test case (vllm-project#6619)
  [Kernel]: Optimize DispatchFFNCombine performance (vllm-project#6468)
  [MISC] Clean up useless env USE_OPTIMIZED_MODEL (vllm-project#6618)
chenchuw886 pushed a commit to chenchuw886/vllm-ascend that referenced this pull request Feb 12, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
Signed-off-by: momochenchuw <chenchuw@huawei.com>
banxiaduhuo pushed a commit to banxiaduhuo/vllm-ascend that referenced this pull request Feb 26, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
ZRJ026 pushed a commit to ZRJ026/vllm-ascend that referenced this pull request Feb 28, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
Signed-off-by: zrj026 <zhangrunjiang026@gmail.com>
maoxx241 pushed a commit to maoxx241/vllm-ascend that referenced this pull request Mar 2, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
ZRJ026 pushed a commit to ZRJ026/vllm-ascend that referenced this pull request Mar 4, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
Signed-off-by: zrj026 <zhangrunjiang026@gmail.com>
LCAIZJ pushed a commit to LCAIZJ/vllm-ascend that referenced this pull request Mar 7, 2026
…fetch (vllm-project#6629)

### What this PR does / why we need it?
1. [Refact] Refact MLA/SFA weight prefetch to consist with moe weight
prefetch
2. Remove duplicated o_proj weight prefetch in forward for MLA/SFA

### Does this PR introduce _any_ user-facing change?
NA

### How was this patch tested?

1) Performance result:
Perf test data:
*) MLA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 11.9669 token/s | 12.0287 token/s |
11.9978 |
| o_proj no duplicate prefetch | 12.5594 token/s | 12.6216 token/s |
12.5905 | 4.94%| |

single layer performace improve: 5%~8%

*) SFA:

| | 1st test | 2nd test | Output Token Throughput(Avg) | Performance
improvement percentage |
| --- | --- | --- | --- | --- |
| o_proj duplicate prefetch | 13.0523 token/s | 13.1084 token/s |
13.08035 | |
| o_proj no duplicate prefetch | 13.9844 token/s | 14.1678 token/s |
14.0761 | 7.6% |

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: leo-pony <nengjunma@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ops ready read for review ready-for-test start test by label for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants