precision-binary-search

Locates the first precision-failing operator in PyPTO kernels via checkpoint-based binary search.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When a PyPTO operator's on-device output mismatches the golden reference, it is hard to tell which intermediate operation caused the divergence. This Skill provides a systematic binary-search method that inserts checkpoint tensors into the kernel to compare intermediate results against the golden implementation and pinpoint the first failing op. ## Core Features & Use Cases - Checkpoint Injection: Add checkpoint tensors as kernel input parameters with declared shape and dtype, writing intermediate results in place via pypto.assemble or slicing. - Golden Alignment: Modify the golden function to return matching intermediate values, ensuring identical checkpoint count, shape, dtype, and computation stage. - Binary Localization: Start from a few key computation nodes and iteratively narrow down until the first precision-failing op is found. - Use Case: A fused operator on Ascend NPU produces wrong results; insert a checkpoint after the matmul stage, compare with golden, then bisect the remaining stages until the faulty op is isolated. ## Quick Start Ask the assistant to apply the precision-binary-search method to locate the first precision-failing op in your PyPTO kernel by adding checkpoint tensors and comparing intermediate results with the golden function.

Frequently Asked Questions about precision-binary-search

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

FAQPage Schema
How do I locate the first precision-failing op in a PyPTO kernel?

Insert checkpoint tensors as kernel input parameters at key computation nodes, write intermediate results into them with pypto.assemble or slicing, then compare each checkpoint against the golden function's corresponding return value. Bisect the computation flow until the first mismatching checkpoint identifies the faulty op.

How to add checkpoint tensors to a PyPTO kernel function?

Declare checkpoint tensors as input parameters in the kernel signature with explicit shape and dtype, initialize them with torch.empty() in the test function, and write intermediate results in place using pypto.assemble or view-based slicing. The kernel should not return values; outputs are written via out parameters.

Why does pypto.assemble fail with dtype mismatch errors?

pypto.assemble requires source and destination tensors to have identical dtypes, otherwise compilation fails with a dtype error. Insert an explicit cast before assembling, and when comparing with golden, convert both sides to float32 for consistent comparison.

How do I handle checkpoints inside loops in PyPTO kernels?

Create a large tensor outside the loop and use view or pypto.assemble inside the loop to store each iteration's intermediate result. For complex multi-level loops where kernel and golden implementations match, comparing only the in-loop temporary variables is acceptable.

Why does my checkpoint comparison show mismatches on the last data block?

PyPTO's final block can contain dirty data in non-aligned tail cases, causing false assertion failures. Compare the first block's data instead, or ensure shapes are aligned so tail blocks do not introduce invalid values.