torch-npu-fusion-optimizer

Analyze PyTorch model code to generate torch_npu fusion-operator replacement blueprints.

Updated Apr 11, 2026
One-click install
npx skills add https://github.com/tuliang1024/cann-recipes-infer --skill torch-npu-fusion-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: torch-npu-fusion-optimizer
Source: https://github.com/tuliang1024/cann-recipes-infer/tree/main/.agent/skills/torch-npu-fusion-optimizer
Command: npx skills add https://github.com/tuliang1024/cann-recipes-infer --skill torch-npu-fusion-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill analyzes PyTorch model code to identify and optimize compute patterns by mapping them to torch_npu fusion operators, reducing inference time and resource usage.

Core Features & Use Cases

  • Pattern discovery: detects common fusion opportunities in QKV, RoPE, KV cache, and FFN paths.
  • Replacement blueprint: generates a plan for operator substitutions with validation hooks for safety.
  • Use Case: optimize an existing Transformer model to leverage fused Torch-NPU kernels for faster inference on Ascend hardware.

Quick Start

Provide a PyTorch model and let the skill analyze it to propose and generate fusion-operator replacements.

Frequently Asked Questions about torch-npu-fusion-optimizer

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

FAQPage Schema
How do I optimize PyTorch models with torch_npu fusion operators for inference?

To optimize PyTorch models with torch_npu fusion operators, this skill analyzes your model code to identify compute patterns in QKV, RoPE, KV cache, and FFN paths, generating a validated replacement blueprint for faster Ascend hardware inference.

What is torch_npu fusion-operator replacement and when do I need it?

Torch_npu fusion-operator replacement maps standard PyTorch compute patterns to fused NPU kernels. You need it when optimizing Transformer models on Ascend hardware to reduce inference time and resource usage across Attention and MoE modules.

Can I use this to optimize Attention and MoE modules on Ascend hardware?

Yes, you can optimize Attention and MoE modules on Ascend hardware. The skill detects fusion opportunities specific to these scenarios and applies substitutions respecting data types and layouts for deterministic automated replacement.

What's the best way to identify QKV and RoPE fusion opportunities in PyTorch code?

The best way to identify QKV and RoPE fusion opportunities is automated pattern discovery. The skill scans your PyTorch model code to detect these common paths and proposes substitutions mapping to official torch_npu interfaces.

How to generate a validated replacement plan for torch_npu fusion operators?

To generate a validated replacement plan, the skill produces a blueprint with validation hooks for safety. It maps substitutions to official torch_npu interfaces and generates deterministic replacement steps for automated application.