[Feature] Support MLA dummy load & optimize MLA value padding memory#7775
[Feature] Support MLA dummy load & optimize MLA value padding memory#7775Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for 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. |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 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.py、fastdeploy/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_proj 为 None 时若被调用会抛 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 描述。
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览CI 正在运行中,当前 Required 任务无失败(4 个运行中,1 个等待中);3 个 Optional 任务失败,不阻塞合并。
2 任务状态汇总2.1 Required任务 : 5/10 通过
2.2 可选任务 — 21/25 通过
3 失败详情(仅 required)无 required 失败任务。 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7775 +/- ##
==========================================
Coverage ? 71.51%
==========================================
Files ? 396
Lines ? 55828
Branches ? 8724
==========================================
Hits ? 39927
Misses ? 13152
Partials ? 2749
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Accuracy Tests
Checklist
[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]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.