graph-mode-adaptation

Adapt models to NPU graph mode acceleration with torch.compile.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

图模式适配技能帮助开发者将模型在 NPU 平台通过 torch.compile 的图模式进行加速,同时提供设计、调试与验证的系统性工作流,解决图中断、动态形状、后端差异等常见挑战。

Core Features & Use Cases

  • 提供 npugraph_ex 与 GE 两种图模式的适配指南与对比分析,帮助选择合适的后端。
  • 指导识别与修复 Graph Break、重编译及动态形状带来的问题,确保稳定性与性能。
  • 给出端到端的工作流模板,包括方案设计、方案确认、实现与验证,以及对 LLM 与通用模型的要点区分。

Quick Start

Describe a ready-to-implement plan to adapt a model to NPU graph mode with torch.compile and verify its correctness and performance.

Frequently Asked Questions about graph-mode-adaptation

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

FAQPage Schema
How do I use torch.compile to accelerate model inference on NPU?

You can accelerate model inference on NPU by adapting models to graph mode using torch.compile. This requires an NPU-enabled environment with torch_npu installed, addressing graph breaks, dynamic shapes, and backend-specific constraints to ensure both stability and performance.

What is the difference between npugraph_ex and GE graph modes for NPU?

The npugraph_ex and GE graph modes are two distinct backends for NPU acceleration. Choosing the right backend depends on your specific model requirements, as each handles graph compilation and execution differently, requiring a structured workflow for design and validation.

How do I fix graph breaks and recompilation issues during NPU graph mode adaptation?

To fix graph breaks and recompilation issues during NPU graph mode adaptation, you must identify and resolve unsupported operations and dynamic shape changes. A structured debugging workflow helps isolate these backend-specific constraints to ensure stable model execution.

Do I need to separate prefill and decode paths when adapting LLMs for NPU graph mode?

Yes, you must separate prefill and decode paths when adapting LLMs for NPU graph mode. This separation is a key requirement for LLM models to properly handle dynamic shapes and static graph considerations during torch.compile acceleration.

What are the limitations of using torch.compile with NPU for dynamic shapes?

Using torch.compile with NPU for dynamic shapes introduces limitations such as frequent recompilation and graph breaks. You must apply static graph considerations and backend-specific constraints to manage these issues and maintain inference performance.