PyTorch框架提供与算子编译相关的二进制配置参数,可设置模型编译时是否优先在线编译,以此优化模型训练性能。参数配置代码如下,可设置True或False,若不添加以下代码则默认为True。
torch_npu.npu.set_compile_mode(jit_compile=True)
用户在模型训练后,可根据模型训练为固定shape还是动态shape场景来选择如下配置:
torch_npu.npu.set_compile_mode(jit_compile=False)
if __name__ == '__main__': torch_npu.npu.set_compile_mode(jit_compile=False) main()
mp.spawn(main_worker,...) ... def main_worker(): torch_npu.npu.set_compile_mode(jit_compile=False)
if __name__ == '__main__': torch_npu.npu.set_compile_mode(jit_compile=False) main()
mp.spawn(main_worker,...) ... def main_worker(): torch_npu.npu.set_compile_mode(jit_compile=False)