执行摘要
本PR修复了bench_one_batch性能分析工具中DP-Attention并行元数据传递错误,通过使用get_attention_tp_size函数并添加attn_cp_size参数,确保在启用DP-Attention时性能分析路径与正常调度器路径一致,从而提升分析准确性。
功能与动机
动机源于bench_one_batch在启用DP-Attention时未正确传递注意力并行元数据,导致性能分析不一致。PR body明确指出:“attn_tp_size is hardcoded to 1 and attn_cp_size is not forwarded, which makes the DP-Attention preparation path inconsistent with the normal scheduler path”。这在使用GLM-4.7-Flash等模型进行性能分析时会造成问题。
实现拆解
仅修改了python/sglang/bench_one_batch.py文件,具体改动在_maybe_prepare_mlp_sync_batch函数中:
- 将
attn_tp_size从硬编码1改为调用get_attention_tp_size()动态获取。
- 添加
attn_cp_size=model_runner.attn_cp_size参数传递。
关键代码变更如下:
prepare_mlp_sync_batch_raw(
batch,
dp_size=model_runner.server_args.dp_size,
attn_tp_size=get_attention_tp_size(), # 修正为动态获取
attn_cp_size=model_runner.attn_cp_size, # 新增参数
...
)
评论区精华
review讨论中,alexnails建议使用现有函数简化代码:
“can't this just be an import and use: get_attention_tp_size”
作者lviy回应并测试后更新,采纳了这一建议,体现了对代码设计和一致性的重视。
风险与影响
风险较低,修复了已知错误,但需确保get_attention_tp_size函数在bench_one_batch上下文中正常工作。影响限于性能分析工具用户,提升分析准确性,对系统其他部分无影响。
关联脉络
与PR #21840(调度器批次修复)可能共享并行计算逻辑,反映了项目对调度和性能分析一致性的持续优化。近期历史PR中多见run-ci标签,表明CI测试是重要环节,本PR也通过run-ci确保改动稳定性。
参与讨论