功能介绍
简介
该脚本转换工具可将PyTorch脚本转换成MindSpore代码。

- 脚本转换工具根据适配规则,对用户脚本进行转换,大幅度提高了脚本迁移速度,降低了开发者的工作量。该脚本转换工具支持对包括但不限于PyTorch模型支持列表列出的模型进行转换,转换成功后可直接运行,部分模型需要根据实际情况进行少量适配。
- 此脚本转换工具当前仅支持PyTorch训练脚本转换。
- 此脚本转换工具能支持PyTorch模型支持列表中的工程转换后训练成功且收敛,对最终精度和性能暂不做保证。
- 此脚本转换工具转换后的训练工程支持在MindSpore1.5及更新版本上运行。
使用限制
- MindSpore支持两种运行模式(Graph模式和PyNative模式),由于Graph模式存在Python语法限制,当前仅支持转换到PyNative模式,训练性能较Graph模式有所降低。具体差异详见MindSpore文档。
- 当前为了规避MindSpore中数据处理不支持创建Tensor的限制,将运行模式设置成了算子同步下发模式,可能存在训练性能的部分降低;用户可通过将context.set_context中的pynative_synchronize=True去除,使用算子异步下发模式提升性能;此时若报错,可检查数据处理部分代码,去除其中的创建Tensor行为,改为使用numpy的ndarray。
- 当前迁移结果不支持多卡运行。
PyTorch模型支持列表
序号 |
模型 |
原始训练工程代码链接 |
备注 |
|
---|---|---|---|---|
1 |
ResNet系列 |
ResNet18 |
https://github.com/pytorch/examples/tree/master/imagenet |
|
2 |
ResNet34 |
|||
3 |
ResNet50 |
|||
4 |
ResNet101 |
|||
5 |
ResNet152 |
|||
6 |
ResNeXt-50(32x4d) |
|||
7 |
ResNeXt-101(32x8d) |
|||
8 |
Wide ResNet-50-2 |
|||
9 |
Wide ResNet-101-2 |
|||
10 |
ShuffleNet系列 |
ShuffleNetV2 |
https://github.com/megvii-model/ShuffleNet-Series |
- |
11 |
ShuffleNetV2+ |
|||
12 |
BERT |
https://github.com/codertimo/BERT-pytorch |
||
13 |
UNet |
https://github.com/milesial/Pytorch-Unet |
MindSpore暂不支持ReduceLROnPlateau,需要替换成其他支持的scheduler。 |
|
14 |
ViT |
https://github.com/jeonsworld/ViT-pytorch |
||
15 |
Res2Net |
https://github.com/Res2Net/Res2Net-ImageNet-Training |
暂不支持torchvision.models相关接口的转换,需做以下操作。 修改原始工程:
|
|
16 |
EfficientNet系列 |
EfficientNet-B0 |
https://github.com/lukemelas/EfficientNet-PyTorch |
- |
17 |
EfficientNet-B1 |
|||
18 |
EfficientNet-B2 |
|||
19 |
EfficientNet-B3 |
|||
20 |
EfficientNet-B4 |
|||
21 |
EfficientNet-B5 |
|||
22 |
EfficientNet-B6 |
|||
23 |
EfficientNet-B7 |
|||
24 |
EfficientNet-B8 |
|||
25 |
pytorch-cifar系列 |
VGG19 |
https://github.com/kuangliu/pytorch-cifar |
|
26 |
PreActResNet18 |
|||
27 |
DenseNet121 |
|||
28 |
ResNeXt29_2x64d |
|||
29 |
MobileNet |
|||
30 |
MobileNetV2 |
|||
31 |
SENet18 |
|||
32 |
ShuffleNetG2 |
|||
33 |
GoogleNet |
|||
34 |
DPN92 |