precision-verify

Compares PyPTO kernel and golden intermediate tensors to locate the first precision failure point.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill precision-verify-wangwindow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: precision-verify
Source: https://github.com/WangWindow/CANN-BatchMatMulMaxsum/tree/main/.agents/skills/pypto-precision-compare/precision-verify
Command: npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill precision-verify-wangwindow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, matplotlib, numpy, and includes scripts (resource) components.

What problem does it solve? When a PyPTO operator produces incorrect numerical results on Ascend NPU, developers struggle to pinpoint which computation step diverges from the golden reference. This Skill provides a systematic checkpoint-based comparison workflow that saves intermediate tensors from both kernel and golden implementations, then compares them file-by-file to locate the first failing operation. ## Core Features & Use Cases - Checkpoint Insertion: Uses pypto.pass_verify_save() in the kernel and torch.save() in the golden function to dump intermediate results, with conditional saving (cond=(idx == batch_size - 1)) for loop scenarios. - Automated Comparison Tool: The compare_accuracy.py script auto-detects output directories, matches jit .data files with golden .pt files, applies dtype-specific tolerances (FP16, FP32, BF16, FP8, INT types), and reports mismatch rates with bisection suggestions. - Precision Visualization: The plot_accuracy.py script parses verification logs and plots rtol/atol trends across checkpoints as PNG charts. - Use Case: While debugging a fused BatchMatmulMaxSum operator, insert checkpoints after the matmul, max-reduce, and sum-reduce stages, run the test, then run the comparison tool to discover the max-reduce stage is the first divergence point. ## Quick Start Ask the AI to insert pass_verify_save checkpoints into your PyPTO kernel and matching torch.save calls into the golden function, then run the compare_accuracy.py script to locate the first precision mismatch.

Frequently Asked Questions about precision-verify

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I locate precision errors in a PyPTO operator?

Insert checkpoints with pypto.pass_verify_save() in the kernel and torch.save() in the golden function at matching computation stages, run the test, then execute compare_accuracy.py. The tool compares checkpoints in order and identifies the first mismatching operation.

How to save intermediate results in PyPTO loop scenarios?

Use conditional saving with cond=(idx == batch_size - 1) in pass_verify_save so only the last tile is dumped, and mirror it in golden with if idx == batch_size - 1. For nested loops, multiply conditions like cond=((idx1 == end1) * (idx2 == end2)).

What tolerance does the comparison tool use for BF16 and FP32?

The tool sets tolerances automatically by dtype: FP32 uses rtol=1e-3 and atol=1e-4, BF16 uses rtol=5e-3 and atol=5e-2, FP16 uses 1e-3/1e-3, and FP8 uses 1e-1/1e-2. Custom values can be passed via --rtol and --atol flags.

Why does checkpoint comparison fail with FP8 or BOOL data types?

FP8 and BOOL tensors cannot be directly compared with arithmetic operations in PyTorch. Both kernel and golden sides must cast to a computable type first, such as FP32 for FP8 or INT8 for BOOL, using identical conversions on both sides before saving.

Why does the comparison report dtype or shape mismatch failures?

The kernel and golden must save tensors with identical data types and shapes, otherwise comparison fails immediately. This usually happens when golden computes full data while the kernel saves a tile, so rewrite golden to mirror the kernel's blocking logic.