reference-generation

Generates reference PyTorch nn.Module implementations from operator description JSON files.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, and includes references (resource) components.

What problem does it solve? Writing correct reference PyTorch implementations for custom NPU operators is error-prone, especially when evaluation frameworks create multiple model instances that must produce identical weights. This Skill automates the generation of reference code that faithfully reproduces the Golden definition from operator description documents. ## Core Features & Use Cases - Golden Definition Extraction: Copies reference code directly from the operator's API description document rather than inventing new implementations, ensuring semantic fidelity. - Evaluation-Safe Initialization: Enforces fixed-seed parameter initialization (torch.manual_seed) so Model and ModelNew instances produce identical weights during evaluation. - Standardized Output Structure: Produces nn.Module classes with get_inputs() and get_init_inputs() helpers matching the evaluation harness contract. - Use Case: After generating an operator description JSON for a custom Ascend NPU operator like BatchMatmulMaxSum, use this Skill to produce the reference PyTorch implementation saved to output/{op_name}/{op_name}_reference.py. ## Quick Start Generate the reference PyTorch implementation for the operator described in batchmatmulmaxsum_op_desc.json using its API description document.

Frequently Asked Questions about reference-generation

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

FAQPage Schema
How do I generate a reference PyTorch implementation for a custom NPU operator?

Provide the operator description JSON file and its API description document. The Skill extracts the Golden definition code verbatim, wraps it in an nn.Module class, and adds get_inputs() and get_init_inputs() helpers matching the evaluation framework contract.

Why do Model and ModelNew produce different weights during evaluation?

The evaluation framework creates two model instances sequentially, so random initialization consumes different random numbers for each. Fix this by calling torch.manual_seed(42) at the start of __init__ and creating nn.Parameter tensors directly instead of using nn.Linear.

Should I write my own reference code or copy from the API description?

Always copy the reference code verbatim from the Golden definition section of the API description document. Writing new implementations risks semantic divergence from the official operator behavior used for correctness checking.

How should get_inputs handle different dtypes like float16 or int32?

Use torch.rand() for float32, torch.randint() for int32 or int64, and torch.rand() cast to the target dtype for float16 or bfloat16. Shapes must come from the shape_info field in the operator description JSON.

How do I implement gradient operators in the reference model?

Manually implement the gradient computation in the forward function instead of relying on autograd. If the gradient needs the original forward output, compute it in get_inputs() and pass it as an input to forward.