Skip to content
cccskills
FreePublished on GitHub

nan-overflow-detection

多卡分布式训练中的 loss/gnorm 精度溢出检测与根因追溯。基于 MSProbe dump 数据,先跨 rank 定位首次出现 NaN 的源卡,再在源卡上追溯具体的溢出根因算子。

当用户需要:(1) 多卡分布式训练场景下的 NaN/Inf 溢出检测 (2) 找出首先出现 NaN 的源卡 (3) 追溯根因计算算子 (4) loss/gnorm NaN 问题定位 时使用此 skill。

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md4.1 KB
  • scripts/cross_rank_analyzer.py6.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

NaN 溢出检测与根因追溯

此 skill 分两步完成完整的 NaN 溢出分析:

  1. 跨 rank 源卡检测 — 分析所有 rank 的通信算子,定位源卡
  2. 单卡根因追溯 — 在已知源卡后,追溯该卡上产生 NaN 的计算算子

重要说明:执行顺序

dump.json 中算子的出现顺序即为执行顺序,无需根据算子名称中的数字来排序。

数据文件结构

input_path/
├── rank0/
│   ├── dump.json      # 算子输入输出数据
│   ├── construct.json # 算子调用链
│   └── stack.json     # 算子堆栈信息
├── rank1/
│   ├── dump.json
│   ├── construct.json
│   └── stack.json
└── ...

文件格式

dump.json — 算子数据:

{
  "framework": "pytorch",
  "data": {
    "Distributed.all_reduce_0_0": {
      "input": [...],
      "input_args": [...],
      "input_kwargs": {...},
      "output": {"0": {"Max": "inf", "Min": "inf"}}
    }
  }
}

construct.json — 调用链:

{
  "Torch.ops.aten.linear_0_0": "Torch.nn.functional.linear_0_0"
}

stack.json — 代码位置:

{
  "Torch.ops.aten.linear_0_0": ["linear", "forward.py", 123]
}

溢出判定规则

基于 output 字段中的 Max/Min 值:

  • NaN: "Max": "nan" 或 "Min": "nan"
  • Inf: "Max": "inf", "Min": "inf", "Max": "-inf", "Min": "-inf"

非计算算子过滤

以下算子产生 NaN/Inf 是正常现象,应被过滤:

  • torch.empty, torch.full, torch.zeros, torch.ones — 内存初始化
  • Tensor.to, Tensor.clone, Tensor.detach — 类型转换/复制
  • NPU.*_empty, NPU.*_full — NPU 初始化算子

合法 -Infinity 过滤

以下算子合法产生 -Infinity,不算溢出:

  • Tensor.masked_fill, Torch.masked_fill — MoE routing、attention mask
  • Tensor.where, Torch.where — 条件操作
  • Tensor.triu, Torch.triu, Tensor.tril, Torch.tril — 三角矩阵

分析流程

步骤 1:跨 rank 源卡检测

python3 "<skill_root>/scripts/cross_rank_analyzer.py" <input_path> [output_path]
  1. 遍历所有 rank 的 dump.json,识别通信算子(Distributed. 开头)
  2. 检查每个通信算子的输入/输出 NaN 状态
  3. 分类:
    • 源卡: 通信算子输入包含 NaN
    • 传播卡: 输入无 NaN,输出有 NaN(通过通信传播)
    • 正常卡: 输入输出均无 NaN
  4. 输出每个通信算子的源卡列表

步骤 2:单卡根因追溯

获取源卡后,追溯该卡上的根因算子:

  1. 保持 dump.json 中的执行顺序
  2. 过滤非计算算子和合法 -Infinity
  3. 遍历算子,找到第一个可能的异常节点
  4. 利用 construct.json 追溯完整调用链
  5. 利用 stack.json 获取代码位置
  6. 如果找到的第一个可能异常节点,被排除异常可能,则继续找后续可能是异常的节点,重复进行定位

异常节点判定逻辑

def is_anomaly(op_data):
    # 输入有异常或者输出有异常
    is_input_anomaly = check_anomaly(input_args)
    is_output_anomaly = check_anomaly(outputs)
    return is_input_anomaly or is_output_anomaly

输出

跨 rank 分析结果

每个通信算子的源卡、传播卡、正常卡列表。

单卡追溯结果

{
  "rank": 168,
  "first_anomaly": {
    "op_name": "Tensor.matmul.42.forward",
    "exec_order": 0,
    "output": {...},
    "input_info": [
      {"shape": [4096, 4096], "Max": "0.001", "dtype": "float16"}
    ],
    "construct_chain": ["Tensor.matmul.42.forward", "Torch.nn.functional.linear.12.forward", ...],
    "stack_info": ["linear", "forward.py", 123]
  }
}

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

当用户直接要求进行数据集压缩测评,或在量化调优过程中需要使用 AISBench 评测工具输出数据集精度等场景时使用。 本 Skill 负责:使用 AISBench 数据集压缩代码、用 RBF Kernel Herding 算法生成压缩后的数据子集(coreset),并按用户目标交付两种产物之一: ① 接入量化调优主流程:产出独立的 coreset 数据集配置(不覆盖原始数据),回传「全集 config_name + coreset config_name」给编排层,供 evaluation.yaml 切换; ② 仅数据集压缩测评(不做量化调优):基于 example 模板生成「全集测试脚本」和「子集测试脚本」两份 shell 脚本。 暂时支持 AIME 2025 和 GPQA,其他数据集需要再结合 aisbench tools目录下 herding_coreset_selector 源码进行分析。

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

Ascend cluster comparison tool. Invoke when user asks to compare two cluster datasets (DB or TEXT), or to generate cluster_analysis_output from raw profiling data via msprof-analyze and then compare.

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

专门用于 Ascend 集群 Profiling 性能数据的“快慢卡”诊断专家技能。当用户提供【集群性能数据目录/路径】并要求分析【快慢卡】、【慢节点】、【负载不均衡】或【集群瓶颈】时,必须触发此技能。该技能会自动接收集群路径,调度相关工具输出快慢卡的宏观定性与微观根因(如 Host 下发瓶颈、算子计算劣化)。

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

Analyze Ascend NPU collective communication profiling data with a DB-first workflow. Use when the user provides `cluster_analysis_output/cluster_analysis.db`, rank-level `analysis.db`, rank-level `ascend_pytorch_profiler_{rank_id}.db`, together with `profiler_info.json`, and asks about HCCL or hcom communication cost, collective communication TOP ops, wait time, slow rank/straggler, Notify Wait, bandwidth, retry, relay, SDMA/RDMA/HCCS links, communication matrix, or Ascend communication fault patterns.

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

Analyze Ascend NPU computation-side profiling data for single-card runs or a selected rank from multi-card runs. Use this skill when the user asks to diagnose computation bottlenecks, AI Core / AI Vector / AICPU hotspots, dynamic shape overhead, block dim issues, redundant TransData/Transpose/Cast, cross-stream waits, frequency/runtime-state issues, or fusion opportunities.

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

针对昇腾 NPU 上的 PyTorch 模型,识别可做融合算子替换的代码段、替换为 torch_npu 融合算子并做性能/精度验证。当用户提到融合算子、NPU 算子替换、RMSNorm/SwiGLU/RoPE/Attention 融合、torch_npu 亲和算子等关键词是,使用本 Skill。

The English summary is being prepared. Showing the original description.

kali20gakki/msAgent32Updated Oct 19, 2026

See all skills by kali20gakki

Report a problem with this skill