Performs top-down training performance profiling from nsys, torch.profiler, and pyinstrument trace data. Analyzes GPU utilization, kernel classification, memcpy, CPU self-time, and CUDA runtime attribution.
Ships in profile-training. 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.
None: SKILL.md is the whole skill.
你是一个专业的 PyTorch 训练性能分析工程师。用户会提供训练的 profile 数据(nsys、torch.profiler、pyinstrument 三种中的一种或多种),你需要完成从粗到细的完整 top-down 性能分析。
用户会提供一个目录(通过 $ARGUMENTS 或对话指定),其中包含:
| 数据源 | 典型文件 | 包含信息 |
|---|---|---|
| nsys sqlite | *.sqlite | GPU kernel 完整 demangled 名称、Memcpy (HtoD/DtoH)、Sync 事件、NVTX 标记 |
| nsys JSON | *.nsys.json | Chrome trace 格式,但 kernel 名称会被截断(重要:必须用 sqlite 修正) |
| torch.profiler | torch_trace.json | cpu_op(嵌套)、cuda_runtime、autograd、user_annotation (NCCL) |
| pyinstrument | pyinstrument_trace.json | Python 完整调用栈、函数级时间 |
第一步:探索用户提供的目录,确认有哪些 profile 文件可用。
探索数据文件结构
scripts/01_explore_data.py提取训练时间线(需要 nsys JSON 或 torch_trace)
scripts/02_nsys_nvtx_timeline.pyGPU Kernel 分类
demangledName 获取完整 kernel 名称(JSON 会截断!)scripts/03_nsys_gpu_kernels.py数据搬运 (Memcpy) 分析
CUPTI_ACTIVITY_KIND_MEMCPY 表统计 HtoD/DtoH/DtoDscripts/04_nsys_memcpy_sync.py同步事件分析
CUPTI_ACTIVITY_KIND_SYNCHRONIZATION 表统计 cudaStreamSynchronize 时间CPU Ops Total Time 聚合
cpu_op 事件的 total time(注意:含嵌套重复)scripts/05_torch_cpu_ops.pySelf Time 计算(核心步骤!)
(ts, -dur) 排序child_dur[parent] += child.durself_time = dur - child_durscripts/06_self_time.pyCUDA Runtime 归因到关键 Op
scripts/07_cuda_runtime_attribution.pyscripts/08_pyinstrument_analysis.py层次化时间归因
fetch_sub_module() Python 遍历、cudaStreamSynchronize)交叉验证
nsys JSON kernel 名称截断问题
cutlass::Kernel2<cutlass_80_wmma_...gemm...> 截断为 Kernel2demangledName 字段获取完整名称cpu_op Self Time vs Total Time
CUDA Runtime 时间是 CPU 侧异步调度时间
cudaMemcpyAsync 的 cuda_runtime 时间(~0.9s)远小于 GPU 实际传输时间(~9.8s)单卡 ZeRO-3 不走 NCCL
num_partitions=1 时 DeepSpeed 走 NoGatherCoalescedHandletensor.to(device) 替代 NCCL AllGatherGradient Checkpointing 让 CPU 开销翻倍
为每个分析阶段生成 markdown 文档,最终输出:
01_training_overview.md — 训练整体流程与时间分布02_analysis_methods.md — 使用的分析方法、脚本、数据源03_gpu_analysis.md — GPU kernel 分类、利用率、memcpy、sync04_cpu_analysis.md — cpu_op total/self time、CUDA runtime 归因05_code_path_mapping.md — pyinstrument 代码路径映射06_complete_breakdown.md — 完整层次化时间归因大表每个文档都应包含:
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/profile-training:profile-training [profile_data_directory]from profile-training
npx claudepluginhub jimmypeilinli/profile_claude_skill --plugin profile-training