import torch, torch_npu
from mx_driving import scatter_max
updates = torch.tensor([[2, 0, 1, 3, 1, 0, 0, 4], [0, 2, 1, 3, 0, 3, 4, 2], [1, 2, 3, 4, 4, 3, 2, 1]], dtype=torch.float32).npu()
indices = torch.tensor([0, 2, 0], dtype=torch.int32).npu()
out = updates.new_zeros((3, 8))
out, argmax = scatter_max(updates, indices, out)为方便用户快速在NPU上跑通基于GPU生态开发的模型,Driving SDK 提供了一键迁移能力,用户仅需添加两行代码即可。
找到模型的训练脚本,通常命名为train.py,定位到它的入口函数,通常为:
if __name__ == '__main__':
main()from mx_driving.patcher import default_patcher_builder
#......
if __name__ == '__main__':
with default_patcher_builder.build() as patcher:
main()若模型训练报错,可进一步参考模型FAQ进行排查。若希望进一步了解一键patcher特性,可查阅一键Patcher文档。
若NPU上训练性能跟基线差距较大,可参考模型迁移优化指导和负载均衡优化进一步优化hostbound、快慢卡等性能瓶颈。
Driving SDK 支持单算子onnx导出,并提供了示例,用户若有诉求需自行参考训推一体示例开发。