[BugFix]Fix DSA multi-batch inference deployment#7252
[BugFix]Fix DSA multi-batch inference deployment#7252Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-08 18:02 CST
📋 Review 摘要
PR 概述:修复 DSA(DeepSeek Attention)multi-batch decode 推理部署问题,主要修改了 kernel 的 batch_id 计算和输出指针映射逻辑。
变更范围:custom_ops/gpu_ops/sparse_indexer/、fastdeploy/model_executor/models/deepseek_v3.py、tests/operators/
影响面 Tag:[OP] [Models]
📝 PR 规范检查
PR 标题:包含有效的 [BugFix] 标签 ✅
PR 描述:
- Motivation 部分填写了目的 ✅
- Modifications 部分未填写内容
⚠️ - Checklist 中的项目均未勾选
⚠️
建议补充:
描述模板(可直接复制):
## Modifications
1. `indexer_topk.cuh`:
- decode 模式下修改 batch_id 计算方式,从 `batch_id_per_token[bid / q_num_heads]` 改为直接使用 `bid / q_num_heads`
- 修改 dst 指针计算,从 `output + bid * top_k` 改为 `output + aux_input[batch_id] * top_k` 以支持 multi-batch 场景
2. `deepseek_v3.py`:
- prefill 路径:删除冗余的 logits 重排逻辑,直接使用原始 logits
- decode 路径:使用 `cu_seqlens_q` 作为 offsets,`cache_seqlens` 作为 `seq_len_decoder`
3. `test_radix_topk_accuracy.py`:
- 更新 decode 模式测试用例,使用 `cu_seqlens_q` 替代 `offsets`问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | indexer_topk.cuh:2061 |
注释语法错误(/ 应为 //) |
| ❓ 疑问 | indexer_topk.cuh:2068 |
decode 模式下 batch_id = bid / q_num_heads 与 cu_seqlens_q 的语义可能不匹配 |
总体评价
PR 的核心修改逻辑是正确的,通过修改 decode 模式下的输出指针计算方式(从基于 bid 改为基于 batch_id 的 aux_input[batch_id]),解决了 multi-batch 场景下的索引映射问题。删除冗余的 logits 重排逻辑是合理的优化。
但存在一个潜在的语义混淆问题:cu_seqlens_q 通常表示累积序列长度,而 kernel 中将其作为每个 batch 在输出中的偏移使用。虽然当前的实现可能在 DSA 的特定场景下工作正常,但建议在文档或注释中明确说明 cu_seqlens_q 在此处的具体语义。
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7252 +/- ##
==========================================
Coverage ? 72.95%
==========================================
Files ? 383
Lines ? 53510
Branches ? 8379
==========================================
Hits ? 39039
Misses ? 11746
Partials ? 2725
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
Fix DSA multi-batch inference deployment
Modifications
Modifications
indexer_topk.cuh:batch_id_per_token[bid / q_num_heads]改为直接使用bid / q_num_headsoutput + bid * top_k改为output + aux_input[batch_id] * top_k以支持 multi-batch 场景deepseek_v3.py:cu_seqlens_q作为 offsets,cache_seqlens作为seq_len_decodertest_radix_topk_accuracy.py:cu_seqlens_q替代offsetsUsage 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.