triton-npu-convert

Convert PyTorch operators into Triton Ascend NPU kernel-backed operators with validated correctness.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, triton.

What problem does it solve? Rewriting PyTorch operators to run on Ascend NPU hardware requires writing Triton kernels, preserving the original API contract, and proving numerical correctness — a process that is error-prone when done ad hoc. This Skill provides a disciplined conversion workflow with mandatory validation gates. ## Core Features & Use Cases - PyTorch-to-Triton Conversion: Transforms a PyTorch operator file into a Triton Ascend NPU kernel-backed operator while keeping the public PyTorch-facing API intact. - Enforced Validation Gate: Requires differential or standalone validation through the triton-npu-optimize skill's run-eval commands, forbidding ad-hoc comparison scripts or self-declared passes. - Strict Kernel Purity Rules: Ensures all computation lives inside @triton.jit kernels, with forward() limited to buffer allocation and kernel launches. - Use Case: Given a PyTorch operator implementing a fused reduction, convert it to a Triton NPU kernel file, preserve its input-helper block, and validate it differentially against the original implementation. ## Quick Start Convert my PyTorch operator file into a Triton NPU-backed operator and validate it with differential testing against the original.

Frequently Asked Questions about triton-npu-convert

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

FAQPage Schema
How do I convert a PyTorch operator to a Triton NPU kernel?

Provide the original PyTorch operator file, an output path, and a validation mode. The conversion writes a Triton Ascend NPU kernel-backed operator that keeps the PyTorch-facing API, then validates it using differential or standalone testing through the prescribed CLI commands.

How is correctness validated after converting an operator to Triton?

Validation must run through cli.py run-test-optimize for differential mode or run-test-baseline for standalone mode. Only output containing PASS or All tests passed counts as success; ad-hoc torch.allclose scripts and self-declared passes are forbidden.

Can the converted operator keep some PyTorch compute in forward()?

No. The forward() method may only allocate buffers, perform shape operations, read metadata, and launch kernels. All computation including torch functions, tensor operators, and nn.Module calls must happen inside @triton.jit kernels.

Does Triton NPU conversion support CUDA or CPU fallback backends?

No. The conversion targets Ascend NPU only and does not add CUDA, CPU, MPS, or generic multi-backend fallback logic unless the source file already requires shared import structure around the public API.

Why does the converted operator avoid input validation with .item() calls?

Calling .min().item() or similar reductions on NPU tensors forces a device-to-host synchronization on every forward call, destroying performance. Input validation is limited to zero-cost metadata checks like dtype, shape, and device.