Prhub

#25026 [Bench] Add MEM profile activity to bench_serving

原始 PR 作者 kpham-sgl 合并时间 2026-05-14 07:22 文件变更 1 提交数 1 评论 1 代码增减 +3 / -2

执行摘要

bench_serving 新增 MEM 内存分析选项

PR body 中指出:"Enables memory profiling alongside existing CPU/GPU/CUDA_PROFILER/XPU activities, so users can capture memory snapshots during serving benchmarks without separate tooling." 即让用户无需单独工具即可在基准测试中捕获内存快照。

该 PR 逻辑简单,可直接合并。但建议未来考虑在 help 中明确 MEM 选项的依赖(如需要 CUDA 设备),并补充简单的单元测试确保 choices 包含 MEM。

讨论亮点

该 PR 仅有 1 条来自 gemini-code-assist[bot] 的 quota 警告,非技术性讨论。Qiaolin-Yu 直接审核通过,无 review 评论。因此没有实质性的技术讨论。

实现拆解

  1. python/sglang/bench_serving.py--profile-activities 参数的 choices 列表中添加 "MEM" 条目。
  2. 同步更新 help 文本,说明 MEM 的作用:"MEM dumps a torch.cuda.memory snapshot, viewable at https://pytorch.org/memory_viz"。
  3. 无其他文件变更,后端的 MEM 处理逻辑由 torch.profiler 原生支持,无需额外代码。
文件 模块 状态 重要度
python/sglang/bench_serving.py 基准测试 modified 4.33

关键源码片段

python/sglang/bench_serving.py core-logic

唯一变更文件,修改了 --profile-activities 参数的 choices 和 help 文本,新增 MEM 选项。

# --profile-activities 参数新增 MEM 选项
parser.add_argument(
    "--profile-activities",
    type=str,
    nargs="+",
    default=["CPU", "GPU"],
    # choices 新增 "MEM",用于 torch.cuda.memory 快照
    choices=["CPU", "GPU", "CUDA_PROFILER", "XPU", "MEM"],
    help="Profiler activities to capture: CPU, GPU, XPU, CUDA_PROFILER, MEM "
    "(MEM dumps a torch.cuda.memory snapshot, viewable at https://pytorch.org/memory_viz).",
)

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险极低。仅修改了 argparse 的 choices 枚举和 help 文本,不会影响现有逻辑。若用户误用 MEM(例如在不支持 CUDA 的环境下),torch.profiler 可能抛出错误,但该行为与现有错误处理一致,不构成新增风险。

影响范围有限。仅影响使用 bench_serving 且指定 --profile-activities MEM 的用户,其他用户完全无感知。为调试 GPU 内存泄漏或峰值内存使用的开发者提供了便利。

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论