Skip to content

[Feature] Support MLA dummy load & optimize MLA value padding memory#7775

Merged
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
chang-wenbin:dummy_dsk
May 11, 2026
Merged

[Feature] Support MLA dummy load & optimize MLA value padding memory#7775
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
chang-wenbin:dummy_dsk

Conversation

@chang-wenbin
Copy link
Copy Markdown
Collaborator

@chang-wenbin chang-wenbin commented May 11, 2026

Motivation

MLA KV 投影层(MLAKVCombinedProjection)在 dummy 加载模式(load_choices == "dummy")下,k_b_proj_weightv_b_proj_weight 未在 __init__ 中创建,导致后续推理时访问未定义属性而报错。此外,当 qk_head_dim == v_head_dim 时,对 value 执行 0-padding 是无效操作,浪费内存带宽。

Modifications

  • fastdeploy/model_executor/layers/linear.py:在 __init__ 中,当 load_choices == "dummy" 时,创建形状分别为 [num_heads_per_partition, qk_nope_head_dim, kv_lora_rank][num_heads_per_partition, kv_lora_rank, v_head_dim] 的零初始化 k_b_proj_weight / v_b_proj_weight 参数。
  • fastdeploy/model_executor/models/deepseek_v3.py:MLA prefill 路径中,仅当 qk_head_dim != v_head_dim 时执行 value padding,避免零长度 pad 操作。

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 11, 2026

Thanks for your contribution!

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


chang-wenbin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 Paddle-CI-Agent | pr_review | 2026-05-11 17:50:04

📋 Review 摘要

PR 概述:为 MLA KV 投影层补充 dummy 加载模式下的权重初始化,并优化 DeepSeek V3 前向中 value padding 的无效内存操作。
变更范围fastdeploy/model_executor/layers/linear.pyfastdeploy/model_executor/models/deepseek_v3.py
影响面 Tag[Models] [OP] [Loader]


📝 PR 规范检查

标题缺少官方 Tag,描述各段落均为空(仅含模板占位注释)。

标题建议(可直接复制):

  • [Feature] Support MLA dummy load & optimize MLA value padding memory

PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):

## Motivation
MLA KV 投影层(`MLAKVCombinedProjection`)在 dummy 加载模式(`load_choices == "dummy"`)下,`k_b_proj_weight``v_b_proj_weight` 未在 `__init__` 中创建,导致后续推理时访问未定义属性而报错。此外,当 `qk_head_dim == v_head_dim` 时,对 value 执行 0-padding 是无效操作,浪费内存带宽。

## Modifications
- `fastdeploy/model_executor/layers/linear.py`:在 `__init__` 中,当 `load_choices == "dummy"` 时,创建形状分别为 `[num_heads_per_partition, qk_nope_head_dim, kv_lora_rank]``[num_heads_per_partition, kv_lora_rank, v_head_dim]` 的零初始化 `k_b_proj_weight` / `v_b_proj_weight` 参数。
- `fastdeploy/model_executor/models/deepseek_v3.py`:MLA prefill 路径中,仅当 `qk_head_dim != v_head_dim` 时执行 value padding,避免零长度 pad 操作。

## Usage or Command
N/A

## Accuracy Tests
N/A

## Checklist

- [x] Add at least a tag in the PR title.
  - Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
  - You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.

问题

级别 文件 概述
📝 PR 规范 标题缺 Tag;Motivation / Modifications / Usage / Accuracy Tests 段落为空
🟡 建议 linear.py process_weights_after_loading 未对 dummy 模式做早返回,self.kv_b_projNone 时若被调用会抛 AttributeError

process_weights_after_loading 建议修复

def process_weights_after_loading(self):
    if self.fd_config.load_config.dynamic_load_weight:
        return
    if self.fd_config.load_config.load_choices == "dummy":
        return  # k_b_proj_weight / v_b_proj_weight 已在 __init__ 零初始化,无需再处理
    w = (
        self.kv_b_proj.weight.transpose([1, 0])
        ...
    )

总体评价

逻辑改动简洁清晰,dummy 加载初始化与条件 padding 优化均方向正确。建议补充 process_weights_after_loading 的 dummy 守卫以提升健壮性,同时补全 PR 描述。

@PaddlePaddle-bot
Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-11 18:10:34

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

CI 正在运行中,当前 Required 任务无失败(4 个运行中,1 个等待中);3 个 Optional 任务失败,不阻塞合并。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
35(0) 35 26 3 4 2 0

2 任务状态汇总

2.1 Required任务 : 5/10 通过

必选任务阻塞合并,失败需优先处理。

状态 任务 耗时 根因 修复建议 日志 重跑
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage - 运行中 - Job -
Extracted partial CE model tasks to run in CI. / run_ce_cases - 运行中 - Job -
Run Four Cards Tests / run_4_cards_tests - 运行中 - Job -
xpu_4cards_case_test / run_xpu_4cards_cases - 运行中 - Job -
⏸️ xpu_8cards_case_test / run_xpu_8cards_cases - 等待中 - - -
其余 5 个必选任务通过 - - - - -

2.2 可选任务 — 21/25 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
Run iluvatar Tests / run_iluvatar_cases 10m29s Job -
Check PR Template 11s Job -
Trigger Jenkins for PR 21s Job -
⏸️ CI_HPU - - -
其余 21 个可选任务通过 - - -

3 失败详情(仅 required)

无 required 失败任务。

@chang-wenbin chang-wenbin changed the title support mla dummy load & optimize mla mem about value padding [Feature] Support MLA dummy load & optimize MLA value padding memory May 11, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@a620e91). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/model_executor/layers/linear.py 0.00% 2 Missing and 1 partial ⚠️
fastdeploy/model_executor/models/deepseek_v3.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7775   +/-   ##
==========================================
  Coverage           ?   71.51%           
==========================================
  Files              ?      396           
  Lines              ?    55828           
  Branches           ?     8724           
==========================================
  Hits               ?    39927           
  Misses             ?    13152           
  Partials           ?     2749           
Flag Coverage Δ
GPU 71.51% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit 173d6cd into PaddlePaddle:develop May 11, 2026
31 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants