仅PyTorch 1.8.1版本及以上使用,自动迁移方式较简单,且修改内容最少,只需在训练脚本中导入库代码。
当前自动迁移工具不支持使用distributed parallel(DP)模式的模型迁移。若用户训练脚本中包含昇腾NPU平台不支持的torch.nn.parallel.DataParallel接口,需要手动修改成torch.nn.parallel.DistributedDataParallel接口执行多卡训练。
在脚本开头添加如下代码导入库。
import torch import torch_npu ..... from torch_npu.contrib import transfer_to_npu