run-eagerly功能
功能简介
TorchAir基于torch.compile提供了昇腾设备的图模式编译后端,对接到不同的图模式执行器(aclgraph和Ascend IR),如图1所示。
当模型执行出现问题,无法确定是源于TorchAir的图变换操作(IR converter、Cache compile等操作)还是图执行器导致的,建议启用本配置项。
本配置项提供了图模式执行之前以Eager模式执行FX graph的能力,通过对比前后模型执行效果,辅助问题定界。
使用约束
- max-autotune模式下所有功能均不支持与本功能同时开启,若开启无意义。
- reduce-overhead模式下FX Pass配置可以与本功能同时开启。
使用方法
该功能通过torchair.get_npu_backend中compiler_config配置,示例如下,仅供参考不支持直接拷贝运行,参数介绍参见表1。
- 对接到max-autotune(Ascend IR)模式的示例如下:
1 2 3 4 5
import torch_npu, torchair config = torchair.CompilerConfig() config.debug.run_eagerly = True npu_backend = torchair.get_npu_backend(compiler_config=config) opt_model = torch.compile(model, backend=npu_backend)
- 对接到reduce-overhead(aclgraph)模式的示例如下:
1 2 3 4 5 6
import torch_npu, torchair config = torchair.CompilerConfig() config.mode = "reduce-overhead" config.debug.run_eagerly = True npu_backend = torchair.get_npu_backend(compiler_config=config) opt_model = torch.compile(model, backend=npu_backend)
父主题: 基础功能