基于 PyTorch 框架的昇腾 NPU 模型推理多流整网优化技能。用于分析和实施模型的多流优化、双流、stream overlap、控核与 TorchAir 多流改造。先做整网模块 DAG 与模块间并行性分析,再做每个模块的算子级分析、开发调试和验收。触发场景包括:多流优化、双流、stream overlap、控核、整网 DAG、模块拆解、NPU 多流、TorchAir 多流、limit_core_num、多流改造调试。
Ships in model-infer-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
面向本仓库的 NPU 多流整网优化任务,按“分析 → 开发调试 → 验收”推进。优先参考仓库内已有案例、代码模式和官方 API 索引。
本技能解决的是整网多流优化。
工作主线固定如下:
分析和实施结果统一落到:
multi-stream-analysis/<network_or_case_name>.md
报告结构使用 references/report-template.md。
event / wait / wait_stream / wait_tensor 关系。multi_stream.md,只有在 overlap 正确但出现资源争抢、拖尾或卡死风险时,再读同路径的 limit_cores.md。开始前先确认当前代码走哪条多流路径:
torchair.CompilerConfig() + torchair.get_npu_backend() + GE 图模式:走 Ascend IR 路径。先看 Ascend IR multi_stream,需要控核时再看 Ascend IR limit_cores。torch.compile(..., backend="npugraph_ex"):走 npugraph_ex / aclgraph 路径。先看 npugraph_ex multi_stream,需要控核时再看 npugraph_ex limit_cores。CompilerConfig 和 get_npu_backend() 定界,不要把 torch.compile(mode=...) 当成当前主入口写法。npugraph_ex 路径本质上是显式 stream / event / 生命周期管理;如果代码已经是这套风格,优先顺着现有实现继续,不要强改成 TorchAir 图内表达。profiler agent 当profiler agent存在时,可以通过profiler agent获取以下信息:
references/report-template.md,在 docs/common/multi-stream-analysis/<model_name> 下创建或更新结果文件。references/module-decomposition-spec.md 完成整网模块拆解:
prefill 还是 decodeexamples/README.md,按其中的“快速选型表”进入最接近的模式。torchair.CompilerConfig() + torchair.get_npu_backend():走 Ascend IR / GE 图模式路径torch.compile(..., backend="npugraph_ex"):走 npugraph_ex / aclgraph 路径npu_stream_switchnpugraph_ex / aclgraph:优先用 torch.npu.Stream() + torch.npu.stream()npu_wait_tensor,已有 tagged event 风格时沿用 npu_tagged_event_*npugraph_ex / aclgraph:优先用 torch.npu.Event()、record_event()、wait_event()record_stream()limit_core_num 或全局 config.ge_config.aicore_numnpugraph_ex / aclgraph:torch.npu.npugraph_ex.scope.limit_core_numset_stream_limit / get_stream_limitprofiler agent 当profiler agent存在时,可以通过profiler agent获取以下信息:
如果多流编排方式不唯一,多尝试不同的编排方式,选择性能最优的方案。调试时按下面 4 类问题分开处理,不要混在一起排查:
prefill/decode → 模块 → 算子 缩小范围record_stream()验收必须至少覆盖下面 4 类,并把结果回写报告:
优先使用:
torch.npu.Stream()record_event()wait_event()wait_stream()适用场景:
torch.npu.current_stream()优先使用:
npu_stream_switchnpu_wait_tensornpu_record_tagged_streamnpu_tagged_event_wait适用场景:
ge_graph / TorchAir 多流表达出现“已 overlap 但收益不稳定”时,再评估:
limit_core_numtorch_npu.set_stream_limittorch_npu.get_stream_limit使用顺序:
详细路由见 references/api-routing.md。
npugraph_exrecord_stream()按需读取。
references/module-decomposition-spec.mdreferences/api-routing.mdexamples/README.mdreferences/report-template.mdexamples/README.md (opens in a new tab)examples/hunyuanimage-moe-multi-stream.md (opens in a new tab)examples/indexer-prolog-multi-stream.md (opens in a new tab)examples/kvcache-offload-async-stream.md (opens in a new tab)examples/longcat-flash-afd-overlap.md (opens in a new tab)examples/longcat-flash-multi-stream-limit-core.md (opens in a new tab)examples/moe-shared-expert-dual-stream.md (opens in a new tab)examples/prefill-microbatch-dual-stream.md (opens in a new tab)examples/qwen3-next-moe-dual-stream-patch.md (opens in a new tab)references/analysis-template.md (opens in a new tab)references/api-routing.md (opens in a new tab)references/module-decomposition-spec.md (opens in a new tab)references/report-template.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
11 skills in this plugin
/model-infer-fusion基于 PyTorch 框架的昇腾 NPU 模型推理融合算子优化技能。分析模型代码,识别可替换为 torch_npu 融合算子的计算模式,生成替换方案。触发场景:torch_npu 融合算子替换、MoE/Attention/FFN/Norm 等模块的推理算子适配、torch_npu API 使用咨询。基于仓库已有模型的融合算子经验,按计算语义推荐最佳方案。/model-infer-graph-mode基于 PyTorch 框架的昇腾 NPU 模型推理图模式适配技能。将模型适配到 torch.compile 图模式以加速推理性能。触发场景:npugraph_ex 或 GE 图模式适配、torch.compile 在昇腾 NPU 上的使用、图中断(Graph Break)修复、aclgraph 图编译问题。LLM 模型的图模式适配优先阅读 LLM 模型改造指南。/model-infer-kvcache基于 PyTorch 框架的昇腾 NPU 模型推理 KVCache 优化技能。分析和优化 LLM 文本推理模型中的 KVCache 实现,包括连续缓存、分页注意力(Paged Attention)配合 FA 融合算子、MLA 压缩缓存。触发场景包括:KVCache 管理实现、paged attention、KV 压缩、FA 融合算子、OOM/性能问题、block_table/slot_mapping 构造。基于本仓库已有模型的 KVCache 实现经验,按模型类型和场景推荐最佳方案。/model-infer-skills:model-infer-multi-streamfrom model-infer-skills
npx claudepluginhub jieran-zhang/cannbot-skills --plugin model-infer-skills