GE 图模式使用指南
【免费下载链接】cannbot-skills CANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体,本仓库为其提供可复用的 Skills 模块。
项目地址: https://gitcode.com/cann/cannbot-skills
GE图模式通过 TorchAir 的 CompilerConfig 开启,将 FX 图转换为 Ascend IR 图,并通过 GE 图引擎实现图编译和执行。
适用场景
- 生产环境:稳定性优先
- 通用场景:功能丰富,支持广泛
- 复杂模型:需要更多配置选项
与 npugraph_ex 对比
| 特性 |
npugraph_ex 后端 |
GE 图模式 |
| 启用方式 |
backend="npugraph_ex" |
torchair.get_npu_backend() |
| 实现原理 |
捕获模式 (Capture & Replay) |
FX图转换为Ascend IR,GE引擎编译执行 |
| 默认模式 |
需显式指定 |
系统默认模式 mode="max-autotune" |
| 成熟度 |
试验特性,暂不支持商用 |
更成熟稳定 |
| PyTorch版本 |
需要 2.6.0+ |
无特殊要求 |
| 支持场景 |
在线推理 |
通用场景 |
| 配置方式 |
options={} 参数 |
CompilerConfig 对象 |
快速上手
# 导包(必须先导 torch_npu 再导 torchair)
import torch
import torch_npu
import torchair
# Patch方式实现集合通信入图(可选)
from torchair import patch_for_hcom
patch_for_hcom() # 集合通信入图(有 TP/EP 并行时需调用)
model = YourModel().npu()
# 图执行模式默认为 max-autotune
config = torchair.CompilerConfig()
npu_backend = torchair.get_npu_backend(compiler_config=config)
# 基于 TorchAir backend 进行 compile
opt_model = torch.compile(model, backend=npu_backend)
# 执行编译后的 Model
output = opt_model(input_tensor)
完整示例见 GE 图模式快速上手
CompilerConfig 配置
config = torchair.CompilerConfig()
# debug 类功能
config.debug.xxx = ...
# export 类功能(离线导图)
config.export.xxx = ...
# dump_config 类功能
config.dump_config.xxx = ...
# fusion_config 类功能
config.fusion_config.xxx = ...
# experimental_config 类功能
config.experimental_config.xxx = ...
# inference_config 类功能
config.inference_config.xxx = ...
# ge_config 类功能
config.ge_config.xxx = ...
核心 API
功能文档索引
在线文档:gitcode.com/Ascend/torchair/docs/zh/ascend_ir
概述
基础功能
高级功能
API 参考
相关文档
- LLM 模型改造指南:
llm-model-guide.md(LLM 适配优先阅读)
- npugraph_ex 指南:
npugraph_ex-guide.md
【免费下载链接】cannbot-skills CANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体,本仓库为其提供可复用的 Skills 模块。
项目地址: https://gitcode.com/cann/cannbot-skills
所有评论(0)