SuperAPI AI 工具集

external-cannbot-model-model-infer-multi-stream

智能体与模型

查看项目

更新于 10-16 03:42

技能介绍

用途:解决昇腾 NPU 上 PyTorch 模型推理的整网多流优化问题,覆盖多流、双流、stream overlap、控核与 TorchAir 多流改造。

工作主线:先拆整网模块并画模块级 DAG,判断模块间哪些可并行;再对每个模块拆算子、画算子 DAG、判断模块内并行性;依赖关系明确后再做多流开发、调试与验收。分析结果落到 multi-stream-analysis/<network_or_case_name>.md,报告结构用 references/report-template.md。

路径定界:使用 torchair.CompilerConfig() + torchair.get_npu_backend() 时走 Ascend IR 路径,参考 cann-recipes-infer/docs/zh/ascend_ir/features/advanced/multi_stream.md,控核看同路径 limit_cores.md;使用 torch.compile(..., backend="npugraph_ex") 时走 npugraph_ex / aclgraph 路径,参考对应 npugraph_ex 目录下文档。不要把两种图内 API 混写。

主要 API:Ascend IR / GE 图模式优先用 npu_stream_switch,同步用 npu_wait_tensor,已有 tagged event 风格时沿用 npu_tagged_event_*;npugraph_ex / aclgraph 优先用 torch.npu.Stream() + torch.npu.stream(),同步用 torch.npu.Event()、record_event()、wait_event()。显式 stream 路径需检查短生命周期 tensor 跨流消费时的 record_stream()。

调试与验收:按依赖/同步错误、精度功能异常、性能无收益、图模式限制及 aclgraph 生命周期错误分类排查,不靠猜。验收覆盖功能一致、开关回退可用、同步完整、性能时延改善及 profiler 确认真实 overlap。

限制:具体效果、收益与平台支持情况资料未提供,需以实际 profiler 与基线对比为准;references 与 examples 相关内容按仓库实际为准。