ascendc-backward-gen

Generates backward gradient AscendC operators from differentiable PyTorch forward specs and verifies them on NPU.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing a backward (gradient) kernel for a custom AscendC operator by hand is slow and error-prone. This Skill takes a differentiable PyTorch forward operator specification and automatically generates, builds, and numerically verifies the corresponding backward AscendC operator on Ascend NPU hardware. ## Core Features & Use Cases - Forward-to-Backward Generation: Derives exact gradient ground truth with torch.autograd.grad on CPU in fp64, then generates the backward AscendC kernel and validates it against that truth. - Target Chip Normalization: Accepts natural-language chip targets such as a3/a5 or arch22/arch35 and normalizes them before launching the orchestrator engine. - NPU Verification Reporting: Reads verification.json customer-view criteria and only reports success when on-device precision verification passes. - Use Case: You have a forward spec file defining a differentiable GELU operator and need a matching gradient operator for Ascend 910C; invoke this Skill with the spec and target chip to get a verified backward kernel. ## Quick Start Generate the backward AscendC operator for my forward spec file gelu_spec.py targeting chip a5 and verify its precision on the NPU.

Frequently Asked Questions about ascendc-backward-gen

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

FAQPage Schema
How do I generate a backward AscendC operator from a PyTorch forward function?

Provide a forward spec .py file defining a differentiable forward function and a BACKWARD_SPEC dict with inputs, shapes, cases, dtypes, and seed. The Skill derives gradient ground truth with torch.autograd.grad, generates the backward AscendC kernel, builds it, and verifies precision on the NPU.

What input format does the forward spec file need?

The spec is a Python file containing a differentiable forward(**inputs) function plus a BACKWARD_SPEC dictionary with wrt, inputs (name and shape), cases, dtypes, and a seed. An example is provided in scripts/reference_provider/examples/gelu_spec.py.

Which Ascend chip targets are supported for backward operator generation?

You can specify targets in natural language such as a3 or a5, which are normalized to canonical targets: a3 maps to 910C/V220/arch22 and a5 maps to 950PR/V300/arch35. The normalized target is written into the engine workspace environment before launch.

How is the generated backward kernel verified for correctness?

The engine computes exact gradient ground truth on CPU in fp64 using torch.autograd.grad, then runs the generated AscendC kernel on the NPU and compares results against that truth. Success is only reported when the verification.json customer-view criteria show PASS.

Why does the backward generation console show no output?

The orchestrator must be launched with run_in_background enabled and without trailing ampersands, nohup, shell redirection, or truncating pipes like tail or grep. These detach or buffer the process output, hiding logs from the console and task tracking tools.