Skip to content

[BugFix]Fix DSA multi-batch inference deployment#7252

Merged
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
chang-wenbin:DSA_FIX
Apr 8, 2026
Merged

[BugFix]Fix DSA multi-batch inference deployment#7252
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:developfrom
chang-wenbin:DSA_FIX

Conversation

@chang-wenbin
Copy link
Copy Markdown
Collaborator

@chang-wenbin chang-wenbin commented Apr 8, 2026

Motivation

Fix DSA multi-batch inference deployment

💡 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

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

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 Apr 8, 2026

Thanks for your contribution!

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.

🤖 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.pytests/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_headscu_seqlens_q 的语义可能不匹配

总体评价

PR 的核心修改逻辑是正确的,通过修改 decode 模式下的输出指针计算方式(从基于 bid 改为基于 batch_idaux_input[batch_id]),解决了 multi-batch 场景下的索引映射问题。删除冗余的 logits 重排逻辑是合理的优化。

但存在一个潜在的语义混淆问题:cu_seqlens_q 通常表示累积序列长度,而 kernel 中将其作为每个 batch 在输出中的偏移使用。虽然当前的实现可能在 DSA 的特定场景下工作正常,但建议在文档或注释中明确说明 cu_seqlens_q 在此处的具体语义。

Comment thread custom_ops/gpu_ops/sparse_indexer/indexer_topk.cuh
Comment thread custom_ops/gpu_ops/sparse_indexer/indexer_topk.cuh
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
fastdeploy/model_executor/models/deepseek_v3.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7252   +/-   ##
==========================================
  Coverage           ?   72.95%           
==========================================
  Files              ?      383           
  Lines              ?    53510           
  Branches           ?     8379           
==========================================
  Hits               ?    39039           
  Misses             ?    11746           
  Partials           ?     2725           
Flag Coverage Δ
GPU 72.95% <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 48d2bbe into PaddlePaddle:develop Apr 8, 2026
47 of 53 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.

5 participants