用途:当整体 trace 摘要过于粗糙时,用该技能读取 Chrome-trace JSON,通过层边界锚点 kernel 把 kernel 归组到 forward pass 和层,输出可用于 Perfetto 导航或详细耗时分析的表格。
主要能力:layer_timeline_analyzer.py 输出每层墙钟时间、总时长与类别占比(MLA、MoE、GEMM、NCCL、MHC、Hadamard),并按层类型聚类统计,支持 --show-all-passes 查看冷启动到稳态变化;layer_kernel_breakdown.py 输出单层 kernel 明细,支持 --format text/compute-flow/json,可用 --compare-layer 对比两层;perfetto_time_mapper.py 输出 forward pass 与层的 Perfetto 相对时间范围。
使用方式:需准备 torch.profiler 的 Chrome-trace JSON(.json 或 .json.gz)和模型 config.json。运行前需确认模型名、profile、config 路径、GPU 类型、TP/EP、服务模式(decode/prefill)。示例:python3 scripts/layer_timeline_analyzer.py --trace /path/to/TP-0.trace.json.gz --config /path/to/config.json --show-all-passes;python3 scripts/layer_kernel_breakdown.py --trace /path/to/TP-0.trace.json.gz --config /path/to/config.json --fwd-pass 5 --layer 3 --format compute-flow;python3 scripts/perfetto_time_mapper.py --trace /path/to/TP-0.trace.json.gz --config /path/to/config.json --fwd-pass 5 --layers 2,3,38,42。
适用场景:需要知道哪些层贡献最大、模型含交替层类型(如 compress_ratios 的 DeepSeek-V4 NSA 或混合 GDN/GQA 栈)、比较冷启动与稳态、在 Perfetto 中定位特定层、挑选代表性层做深入分析。
限制:trace 必须包含可识别的层边界锚点 kernel;缺少 config.json 时需显式指定 --profile;内置 profile 未覆盖的模型需用 --profile generic --anchor-kernel YOUR_KERNEL;自动稳态选择要求连续两次 layer-0 耗时变化在 5% 内,否则需手动指定 --fwd-pass。