以图模式方式调用算子时,如果存在多个View类算子,会带来冗余计算,增加计算耗时。TorchAir默认开启View类算子优化功能,以提升算子执行性能。如果用户需要进行算子调优,尤其是精度比对,建议关闭本功能。
设置config时使用下列开关进行配置,默认开启为True,如需关闭设为False。
import torch_npu import torchair as tng config = tng.CompilerConfig() # View类算子优化配置 config.experimental_config.enable_view_optimize = False npu_backend = tng.get_npu_backend(compiler_config=config) ... model = Model() model = torch.compile(model, backend=npu_backend, dynamic=False)