Debug and fix Ascend NPU operator precision issues: golden comparison failures, error pattern analysis, root cause localization via binary search and pattern matching, and regression verification.
Ships in ops-direct-invoke-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.
references/tolerance.md)。patterns/——未检索不得读源码(历史会话已反复验证:跳过检索必然绕路)。references/verification.md)。两个入口:主路径是 Step 1 拿到机读判定(误差形态/verdict)后查表;暂无机读判定时,允许用直接观察到的现象(如"批量跑失败、单跑通过")直查本表——降级路径,事后仍须补齐机读依据。
| verdict / 现象 | 优先读 | 次选 |
|---|---|---|
| 大输入才错 / 出现 inf | patterns/fp16-overflow.md | patterns/numerical-stability.md |
| 仅极端输入系统性失败(常规值全对;subnormal 窗口 / ±FLT_MAX 级输入) | patterns/ftz-subnormal-boundary.md | patterns/numerical-stability.md |
| 出现 nan(golden 无 nan) | patterns/numerical-stability.md | patterns/uninitialized-memory.md |
| 误差集中尾部 / 非对齐 shape 才错 | patterns/tail-block-misaligned.md | patterns/broadcast-misalignment.md |
| 同一输入多次运行结果偶发不一致 | patterns/pipe-sync-missing.md | patterns/double-buffer-stomp.md |
| 结果不可复现、输入全 0 输出非 0 | patterns/uninitialized-memory.md | patterns/multi-core-atomic-order.md |
| 均匀小误差、随 reduce 维增长 | patterns/reduce-accumulation-order.md | patterns/multi-core-atomic-order.md |
| 特定 shape 组合全错 | patterns/broadcast-misalignment.md | patterns/tail-block-misaligned.md |
| aclnn 直调对,单算子或整网 om 错 | patterns/atc-compile-chain-diff.md | — |
| 单独跑 PASS、批量跑 FAIL、结果跨用例漂移 | patterns/executor-cache-scalar-attr.md | patterns/uninitialized-memory.md |
| 仅特定属性符号/数据模式组合暴露 | patterns/api-mode-semantics-misuse.md | patterns/numerical-stability.md |
根因类别四分:数值精度 / API 误用 / 框架机制 / 硬件行为(非算子 bug)。模式匹配时先归类再选卡;判为硬件行为的,只声明不修复。
修复红线(历史会话反复踩坑的通用纪律,全程有效):
references/hardware-precision-api.md 确认各运算指令的精度模式选项和默认舍入行为)。只有满足以上前提,才允许提示"容差定义可能有误,建议放宽"。bitwise_equal 但计算链路中存在浮点运算时(如 int32→fp32 精度丢失 + fp32 sqrt),bitwise_equal 从数学上不可能成立。此时应提示"容差定义可能有误,建议改为 max_relative 并给出 rtol/atol",交用户确认。API 检索门禁(首次使用):首次对 $ASCEND_HOME_PATH 执行 grep/find 之前,必须先调用一次 ascendc-docs-search skill(若环境中有;其覆盖范围即 Ascend C API 文档与参考实现)——历史会话实测,先查语义约束说明曾省去十余分钟边界实验。声明未命中后才允许以 grep 回退(回退路径 $ASCEND_HOME_PATH/opp/built-in/op_impl/ai_core/tbe/impl/);grep 时禁止凭 kernel 注释或单一 impl 目录的断言下"某模式不支持"的结论。
变体确认:dav_* 变体头文件按 __NPU_ARCH__ 宏分芯片并存,grep 命中的变体可能不是目标芯片的生效变体。读 dav_*/ 下的 impl/断言之前,先跑 scripts/lookup_arch_variant.sh 确认生效变体(ini 的 SoC_version→NpuArch/AIC_version);只在生效变体目录下取证,非生效变体的断言不构成证据。DESIGN/上下文出现 DAV_<N> 时,读头文件同理只走 __NPU_ARCH__ == <N> 分支。
references/tolerance.md)、输入分布;拿不到容差向用户索要。references/verification.md);未指定向用户索要。references/golden-standard.md 重建。--seed=42;自写脚本 torch.manual_seed(42))——否则跨次失败计数差异不可归因。--dump out,golden),逐位置计算误差并分析分布规律(误差位置、周期性、与 shape 轴/dtype 的关联),禁止仅凭 mere/mare 标量值下结论。references/dump-tools.md)。DISABLE_L2_CACHE=1 全量回归(约 3 分钟证伪缓存污染),再走 patterns/executor-cache-scalar-attr.md。references/dump-tools.md),找到首个发散 stage;禁止直接啃源码。patterns/ 卡片;高置信命中 → 严格按卡片"验证方法"确认,确认成立才允许修复。scripts/:lookup_arch_variant.sh(芯片生效变体确认)、batch_precision_check.py(逐 case 精度批检,见下)、error_analysis.py(误差分布分析)、gen_boundary_test.py(边界用例生成)patterns/:模式卡;规则冲突以 SKILL.md 为准references/:tolerance.md(容差来源)/ golden-standard.md(golden 规范)/ verification.md(回归工具规约)/ dump-tools.md(dump 方法与稳定性分流)/ aclnn-api-notes.md(ACLNN 缓存机制与宏速查)/ hardware-precision-api.md(硬件精度 API 表)references/(补充深度参考):ascendc-dumptensor.md(DumpTensor 插桩 7 步法,含 ascendc-dumptensor-refs/ API 材料)/ printf-debug.md(PRINTF 调试法)/ simt-precision-debug.md(SIMT 精度调试)/ diagnosis-workflow.md(完整诊断工作流程)/ binary-search-debug.md(二分定界详细指南)/ common-traps.md(常见精度陷阱)/ data-comparison.md(数据对比法)/ tools-reference.md(工具命令参考)/ best-practices.md / case-studies.md(实战案例)/ debug-summary-template.md(调试总结模板)scripts/batch_precision_check.py要对一批 case 做"逐个比 actual vs golden、给 PASS/FAIL 表"时,用这个脚本,别现写一次性比对脚本 (Rule 2 要的"机读输出"就是它;各自现写会让判定口径不一致,结果之间没法横比)。
分工:调用方只负责把每个 case 的实测输出与 golden 各存一个 .npy;
比对、容差判定、覆盖度校验、表格、退出码由脚本负责。
python3 {skill_path}/scripts/batch_precision_check.py \
--dump-dir <dir> --cases cases.csv \
--rtol 1e-3 --atol 1e-5 \
--label <方案标识> --out precision_report.md
dump 命名:<dir>/case<ID>.actual.npy + case<ID>.golden.npy(多输出加序号后缀 .1 .2…)。
容差没有默认值,必须显式传(符合 Rule 1「容差必须外部给定」),取值走
/ops-precision-standard 的决策树。整型/布尔输出忽略容差、要求逐位相等;
NaN/Inf 的位置(含 Inf 符号)必须与 golden 一一对应。
退出码:0 全 PASS;1 有 case 超差 / NaN-Inf 错位 / shape 不符;
2 有 case 没有 dump(根本没跑)。2 单独分出来,是因为"只测代表性用例"最常见的伪装
就是报告里全 PASS、但没跑的 case 压根不出现在表里 —— 覆盖度必须机器判。
evals/evals.json (opens in a new tab)patterns/api-mode-semantics-misuse.md (opens in a new tab)patterns/atc-compile-chain-diff.md (opens in a new tab)patterns/broadcast-misalignment.md (opens in a new tab)patterns/cast-overflow-saturation.md (opens in a new tab)patterns/double-buffer-stomp.md (opens in a new tab)patterns/executor-cache-scalar-attr.md (opens in a new tab)patterns/fp16-overflow.md (opens in a new tab)patterns/ftz-subnormal-boundary.md (opens in a new tab)patterns/multi-core-atomic-order.md (opens in a new tab)patterns/numerical-stability.md (opens in a new tab)patterns/pipe-sync-missing.md (opens in a new tab)patterns/reduce-accumulation-order.md (opens in a new tab)patterns/tail-block-misaligned.md (opens in a new tab)patterns/uninitialized-memory.md (opens in a new tab)references/aclnn-api-notes.md (opens in a new tab)references/ascendc-dumptensor-refs/api-reference.md (opens in a new tab)references/ascendc-dumptensor-refs/error-patterns.md (opens in a new tab)references/ascendc-dumptensor.md (opens in a new tab)references/best-practices.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ascend, npu, operator-debug, precision-analysis, golden-comparison
25 skills in this plugin
/ascendc-api-best-practicesAscend C API 使用最佳实践。提供算术、归约、数据搬运、Buffer管理、精度转换、通信接口等 API 的正确用法和限制说明。触发:用户询问具体 API 用法(如"DataCopy 怎么用"、"ReadNbi 怎么用")、遇到 API 参数错误或限制报错(如 repeatTimes、对齐问题)、需要查看 API 最佳实践或避坑指南、算子性能疑似受标量访问/单元素读写影响时。/ascendc-blaze-best-practice在 Ascend 950 / DAV_3510 平台上,基于 Blaze/tensor_api 开发 Basic、Batch、Grouped、Quantized、MX 等 MatMul 类算子或相关的融合算子时使用。不适用于纯 Vector 算子或 A2/A3 平台。/ascendc-blaze-migration评估并将 ops-nn、ops-transformer 等仓中 Ascend 950 / DAV_3510 的 AscendC Kernel 分支等价迁移到 ops-tensor Blaze/Tensor API。适用于 CMCT、CGMCT、单体或自定义分层 Kernel,以及 Cube、Vector、MIX、高阶 Matmul、手工 Buffer、数据搬运、自定义调度、VF 和同步路径;在隔离迁移工程中串行完成迁移合同冻结、Blaze 开发、验证资产生成、原始基线、Blaze 验收和双仓本地提交交付。/ascendc-code-reviewAscend C 代码检视技能。触发:检视代码、检视 PR、检查是否有问题、快速检视。支持文件检视、PR 检视、快速定向检视、设计一致性检查。自动识别代码侧别、提取适用条例、执行假设检验驱动的逐条检视。/ascendc-crash-debugAscend C 算子卡死/崩溃/内存错误调试路由技能。用于处理程序无法运行完或执行异常崩溃的场景:(1) 程序卡死/挂起/超时,Kernel 无响应,(2) 程序崩溃(Segmentation Fault、Abort),(3) Buffer 冲突/死锁导致的核心挂起,(4) 需要解析 plog 日志定位卡死/崩溃位置,(5) 偶发崩溃/结果异常(怀疑内存越界踩踏),需要主动检测内存错误。触发关键词:卡死、挂起、超时、崩溃、hang、crash、deadlock、Segmentation Fault、Abort、Kernel hang、内存越界、plog、memcheck、内存检查、内存错误、偶发崩溃、aic error、非法读写。/ascendc-direct-invoke-templateKernel直调工程模板,用于创建 Ascend C Kernel 直调工程项目。提供经过验证的 Vector 样例工程(add_custom)、Blaze Matmul 工程模板(纯 Matmul / 融合 / MX 量化 / GroupMatmul)和 Kirin Vector 模板。触发:当用户需要创建 Kernel 直调工程、学习 Ascend C 编程、快速原型验证、或提及"Kernel直调"、"<<<>>>内核调用"、"Blaze Matmul"、"matmul 模板"时使用本 skill。2 plugins ship this exact skill · first indexed Oct 20, 2026
/ops-direct-invoke-skills:ascendc-precision-debugfrom ops-direct-invoke-skills
npx claudepluginhub hicann/cannbot-skills --plugin ops-direct-invoke-skillsOther plugins' skills for the same job