Skip to content

support qkdim!=vdim#8023

Open
chang-wenbin wants to merge 8 commits into
PaddlePaddle:developfrom
chang-wenbin:qkdim_vdim
Open

support qkdim!=vdim#8023
chang-wenbin wants to merge 8 commits into
PaddlePaddle:developfrom
chang-wenbin:qkdim_vdim

Conversation

@chang-wenbin

Copy link
Copy Markdown
Collaborator

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Modifications

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.

@codecov-commenter

codecov-commenter commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
fastdeploy/model_executor/layers/linear.py 57.69% 10 Missing and 1 partial ⚠️
...l_executor/layers/attention/append_attn_backend.py 50.00% 2 Missing and 2 partials ⚠️
...astdeploy/model_executor/ops/triton_ops/do_rope.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #8023   +/-   ##
==========================================
  Coverage           ?   67.67%           
==========================================
  Files              ?      471           
  Lines              ?    66360           
  Branches           ?    10217           
==========================================
  Hits               ?    44912           
  Misses             ?    18576           
  Partials           ?     2872           
Flag Coverage Δ
GPU 77.73% <52.77%> (?)
XPU 6.99% <0.00%> (?)

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

☔ View full report in Codecov by Harness.
📢 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.

PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot

PaddlePaddle-bot commented Jun 9, 2026

Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-06-17 22:03:35

CI报告基于以下代码生成(30分钟更新一次):
PR commit: 94fa1f9 | Merge base: edc885d (branch: develop)


1 Required任务 : 8/10 通过

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
42(0) 42 37 5 0 0 0
任务 错误类型 置信度 日志
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage 未知 Job
Extracted partial CE model tasks to run in CI. / run_ce_cases 未知 Job

2 失败详情

🔴 Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — 未知(置信度: 低)

错误类型: 未知 | 置信度: 低
分析器: 通用分析(fallback)
失败用例: 分析不可用

用例 错误摘要
未提取到具体失败用例 深度日志未返回 log_file_pathunittest_detailsstep_log;仅有 Process completed with exit code 8.

关键日志:

[FAILURE]: Process completed with exit code 8.
深度日志返回:日志获取失败,无法提取错误信息
  • 根因摘要: 分析不可用,缺少可定位日志
    深度日志接口没有返回可读取的单测日志或 traceback,无法确认是否由本 PR 的 qkdim/vdim 相关改动触发。PR 变更涉及 append_attn_backend.pylinear.pydo_rope.pytests/model_executor/test_linear.py,但当前日志不足以建立直接因果关系。

修复建议:

  1. 先 rerun 或重新拉取该 job 日志;拿到具体失败用例/traceback 后再定位源码。
  2. 若重现,请重点检查 PR 修改的 q/k/v cache shape、qk_rmsnorm_fused/do_rope 调用参数和 QKV/Gate 权重分片 offset。

关联变更: fastdeploy/model_executor/layers/attention/append_attn_backend.py, fastdeploy/model_executor/layers/linear.py, fastdeploy/model_executor/ops/triton_ops/do_rope.py, tests/model_executor/test_linear.py

🔴 Extracted partial CE model tasks to run in CI. / run_ce_cases — 未知(置信度: 低)

错误类型: 未知 | 置信度: 低
分析器: 通用分析(fallback)
失败用例: 分析不可用

用例 错误摘要
未提取到具体失败用例 深度日志未返回 log_file_pathunittest_detailsstep_log;仅有 Process completed with exit code 123.

关键日志:

[FAILURE]: Process completed with exit code 123.
深度日志返回:日志获取失败,无法提取错误信息
  • 根因摘要: 分析不可用,缺少 CE 失败详情
    深度日志接口没有返回 CE case 的具体命令、失败模型或 traceback;因此无法判断失败是否与本 PR 的 q/k/v 维度支持改动直接相关。当前只能确认该 required job 在 PR Build and Test workflow 中失败。

修复建议:

  1. 先 rerun 或补充该 job 的完整日志;拿到失败模型和错误堆栈后再定位。
  2. 若 CE case 与新增 v_head_dim 场景相关,请优先核对 QKV 输出维度、KV cache value shape 和权重加载分片 offset 是否一致。

关联变更: fastdeploy/model_executor/layers/attention/append_attn_backend.py, fastdeploy/model_executor/layers/linear.py, fastdeploy/model_executor/ops/triton_ops/do_rope.py

PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

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-06-11 02:07:41 Asia/Shanghai

📋 Review 摘要

PR 概述:为 attention/QKV 路径补充 qkdim != vdim 支持。
变更范围:AppendAttention backend、QKV/QKVG linear loader、Triton RoPE、线性层单测。
影响面 Tag[OP] [KVCache] [Loader]

问题

级别 文件 概述
🔴 Bug fastdeploy/model_executor/layers/attention/append_attn_backend.py:324 v_head_dim != head_dim 会无条件执行 q/k RMSNorm,未启用 qk norm 的模型会把 None 传进 Triton kernel
🟡 建议 tests/model_executor/test_linear.py:291 新增测试仍使用 v_head_dim == head_dim,没有覆盖本 PR 的核心维度不等分支

📝 PR 规范检查

标题缺少官方 Tag,且 PR 描述的 Motivation / Modifications / Usage or Command / Accuracy Tests 仍未填写。

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

  • [OP] Support qkdim != vdim in attention and QKV loading
PR 描述建议(点击展开,可直接复制)
## Motivation
Support models whose Q/K head dimension differs from V head dimension (`qkdim != vdim`) in FastDeploy attention and QKV projection paths.

## Modifications
- Add `v_head_dim` to attention backend constructors and use it for value cache shape.
- Pass `model_config.v_head_dim` from GPU model runner to the selected attention backend.
- Update QKV/QKVG parallel linear output sizing and V shard placement to use `v_head_dim`.

## Usage or Command
N/A

## Accuracy Tests
N/A. Current PR does not include accuracy or regression test results.

## 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.
- [x] 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.


if getattr(layer, "only_do_attn", False):
if self.external_norm_rope:
qk_rmsnorm_fused(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

这里把 external_norm_rope 只和 v_head_dim != head_dim 绑定后,会对所有 qk/v 维度不同的层执行 qk_rmsnorm_fused。但 Attention 默认 use_qk_norm=False,只有开启时才会创建 q_norm_weight / k_norm_weight;现有多处 Attention(...) 构造没有传 use_qk_norm。这些模型一旦配置 v_head_dim != head_dim,这里会把 None 作为 Triton 指针传入,qk_rmsnorm_fused_kernel 随后 tl.load(q_weight_ptr + ...) 会直接失败。建议把“需要外部 rope/write_cache”和“需要 q/k norm”拆开:只有权重存在或 layer.use_qk_norm 为真时才跑 fused norm;没有 q/k norm 的模型仍应只做 RoPE/write_cache。

kv_num_heads_per_rank=1,
num_kv_head_replicas=2,
head_dim=2,
v_head_dim=2,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

这个新增用例仍然设置 v_head_dim=2head_dim=2,因此不会覆盖本 PR 最关键的 qkdim != vdim 分支:V shard size、param offset、shared KV slice 等仍按旧路径通过。建议至少加入 v_head_dim != head_dim(例如 head_dim=2, v_head_dim=3)的 fused/split load 断言,验证 V 段和后续 offset/gate 不重叠。

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.

3 participants