Model List

Note: The model list of this migration tool is for reference only. The code lines in the remarks are also for reference only.

Table 1 Supported PyTorch models

No.

Model

Reference Link to Original Training Project Code

Remarks

1

3D-Transformer-tr_spe

https://github.com/smiles724/Molformer/tree/f5cad25e037b0a63c7370c068a9c477f4004c5ea

-

2

3D-Transformer-tr_cpe

3

3D-Transformer-tr_full

4

AFM

https://github.com/shenweichen/DeepCTR-Torch/tree/b4d8181e86c2165722fa9331bc16185832596232

  • Except the DIN model, other models do not have corresponding training scripts. Before migrating such a model, copy the ./examples/run_din.py file, name it run_<model_name>.py, and modify it as follows:
    1. Import the model structure, for example, from deepctr_torch.models.ccpm import CCPM.
    2. Input different arguments based on the model structure to initialize the network, for example, model = CCPM(feature_columns, feature_columns, device=device).
    3. Modify the inputs of the network based on whether the network supports the dense_feature.
  • During multi-device training, the input value must be the same as the predicted length. To perform multi-device training after migration, configure as follows:
    1. Modify line 370 in the ./deepctr_torch/models/basemodel.py file.

      Before the modification:

      eval_result[name] = metric_fun(y, pred_ans)

      After the modification:

      eval_result[name] = metric_fun(y[:len(pred_ans)], pred_ans)
    2. Modify lines 78 and 79 in the ./examples/run_classification_criteo.py file.

      Before the modification:

      print("test LogLoss", round(log_loss(test[target].values, pred_ans), 4))
      print("test AUC", round(roc_auc_score(test[target].values, pred_ans), 4))

      After the modification:

      print("test LogLoss", round(log_loss(test[target].values[:len(pred_ans)], pred_ans), 4))
      print("test AUC", round(roc_auc_score(test[target].values[:len(pred_ans)], pred_ans), 4))

5

AutoInt

6

CCPM

7

DCN

8

DeepFM

9

DIN

10

FiBiNET

11

MLR

12

NFM

13

ONN

14

PNN

15

WDL

16

xDeepFM

17

AFN

https://github.com/shenweichen/DeepCTR-Torch/tree/2cd84f305cb50e0fd235c0f0dd5605c8114840a2

  • Because the model does not have a corresponding training script, before the migration, you need to change the DeepFM network in example/run_classification_criteo.py to the network to be tested.

    Modify line 54 in the run_classification_criteo.py file.

    Before the modification:

    model = DeepFM(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns,

    Input different arguments based on the model structure to initialize the network. For example, the following is the AFN model after being modified:

    model = AFN(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns,
  • During multi-device training, the input value must be the same as the predicted length. To perform multi-device training after migration, configure as follows:
    1. Modify line 370 in the ./deepctr_torch/models/basemodel.py file.

      Before the modification:

      eval_result[name] = metric_fun(y, pred_ans)

      After the modification:

      eval_result[name] = metric_fun(y[:len(pred_ans)], pred_ans)
    2. Modify lines 78 and 79 in the ./examples/run_classification_criteo.py file.

      Before the modification:

      print("test LogLoss", round(log_loss(test[target].values, pred_ans), 4))
      print("test AUC", round(roc_auc_score(test[target].values, pred_ans), 4))

      After the modification:

      print("test LogLoss", round(log_loss(test[target].values[:len(pred_ans)], pred_ans), 4))
      print("test AUC", round(roc_auc_score(test[target].values[:len(pred_ans)], pred_ans), 4))

18

DCNMix

19

DIFM

20

IFM

21

BERT

https://github.com/codertimo/BERT-pytorch/tree/d10dc4f9d5a6f2ca74380f62039526eb7277c671

  • After the migration, the project can be used only after being installed. The installation procedure is as follows:
    • Delete the torch item from the requirements.txt file.
    • Run the python3 setup.py install command.
  • For details, see the README.md file of the repository.

22

BEiT

https://github.com/microsoft/unilm/tree/9cbfb3e40eedad33a8d2f1f15c4a1e26fa50a5b1

  • Perform the following operations before the migration:
    • Download the model's source code and retain only the beit folder.
    • Download the open source code of pytorch-image-models0.3.3 and move the timm folder in the code to the beit folder.
  • After the migration, because the weight of the PyTorch model cannot be migrated to that of the MindSpore model, comment out the code in lines 550 and 560 of utils.py.

23

BiT-M-R101x1

https://github.com/google-research/big_transfer/tree/140de6e704fd8d61f3e5ea20ffde130b7d5fd065

24

BiT-M-R101x3

25

BiT-M-R152x2

26

BiT-M-R152x4

27

BiT-M-R50x1

28

BiT-M-R50x3

29

BiT-S-R101x1

30

BiT-S-R101x3

31

BiT-S-R152x2

32

BiT-S-R152x4

33

BiT-S-R50x1

34

BiT-S-R50x3

35

ADMMSLIM

https://github.com/RUCAIBox/RecBole/tree/6e66565347a71c6f9662f9e7366a55c35be4fa46

  • Before the migration of the BERT4REC, CASER, HGN, or REPEATNET model, create a run.py file by following instructions on the official website, add the model code, and migrate the run.py file separately.
  • After the migration, modify the following information:
    1. Comment out line 267 in the ./recbole/utils/utils.py file.
      # model = copy.deepcopy(model)
    2. Modify line 254 in the ./recbole/data/dataloader/general_dataloader.py file.

      Before the modification:

      uid_list = list(user_df[self.uid_field])

      After the modification:

      uid_list = list(user_df[self.uid_field].asnumpy())
    3. Modify line 140 in the ./recbole/data/interaction.py file.

      Before the modification:

      ret[k] = self.interaction[k][index]

      After the modification:

      if self.interaction[k][index].ndim == 0:
          ret[k] = self.interaction[k][index].reshape(1)
      else:
          ret[k] = self.interaction[k][index]
    4. Add the following content after line 41 in the ./recbole/quick_start/quick_start.py file.
      import mindspore.context as context
      from x2ms_adapter.core.context import x2ms_context
      if not x2ms_context.is_context_init:
          context.set_context(mode=context.PYNATIVE_MODE, pynative_synchronize=True)
          x2ms_context.is_context_init = True
    5. Perform this step only for the DGCF model. To meet the GPU memory requirements, set n_factors to 1 in the ./recbole /properties/model/DGCF.yaml file.
    6. Perform this step only for the FISM, DSSM, FFM, and FWFM models.

      Modify line 75 in the ./recbole/model/general_recommender/fism.py file. Under ./recbole/model/context_aware_recommender/, modify line 60 in the dssm.py file, line 78 in the ffm.py file, and line 64 in the fwfm.py file.

      Before the modification:

      self.bceloss = loss_wrapper.BCEWithLogitsLoss()

      After the modification:

      self.bceloss = loss_wrapper.BCELoss()

36

BERT4REC

37

BPR

38

CASER

39

CDAE

40

CFKG

41

CKE

42

CONVNCF

43

DGCF

44

DMF

45

DSSM

46

EASE

47

ENMF

48

FFM

49

FISM

50

FWFM

51

GCMC

52

HGN

53

KGCN

54

NCL

55

REPEATNET

56

SLIMELASTIC

57

CenterNet-ResNet50

https://github.com/bubbliiiing/centernet-pytorch/tree/91b63b9d0fef2e249fbddee8266c79377f0c7946

  • After the migration, process the dataset based on the README.md file of the repository.
  • No trained MindSpore model weight exists. You need to leave model_path in train.py empty.

58

CenterNet-HourglassNet

59

Conformer-tiny

https://github.com/pengzhiliang/Conformer/tree/815aaad3ef5dbdfcf1e11368891416c2d7478cb1

  • Before the migration, place the timm library (version 0.3.2 is recommended) in the root directory of the source code.
  • The framework does not support --repeated-aug currently. Use --no-repeated-aug during training.

60

Conformer-small

61

Conformer-base

62

DeiT-tiny

63

DeiT-small

64

DeiT-base

65

CvT-13

https://github.com/microsoft/CvT/tree/f851e681966390779b71380d2600b52360ff4fe1

  • Before the migration, place the timm (version 0.3.2 is recommended) and einops libraries in the root directory of the source code.
  • Modify the ./run.sh file before the migration as follows:
    • Change the training start mode (lines 4 to 10) in train() to python3 tools/train.py ${EXTRA_ARGS}.
    • Change the test start mode (lines 15 to 21) in test() to python3 tools/test.py ${EXTRA_ARGS}.

66

CvT-21

67

CvT-W24

68

albert-base-v1

https://github.com/huggingface/transformers/tree/49cd736a288a315d741e5c337790effa4c9fa689

  • Before the migration, remove the template files of the original repository. These files are not Python files but are suffixed with .py.
    mv templates ../  
  • After the migration, make the following modifications:
    • To avoid the 'list out of range' error, cancel the use of index in the d["torch_dtype"] = x2ms_adapter.tensor_api.split(str(d["torch_dtype"]), ".")[1] statement of src/transformers/configuration_utils.py.
      After the modification:
      d["torch_dtype"] = x2ms_adapter.tensor_api.split(str(d["torch_dtype"]), ".")
    • Cancel the use of index in the model_to_save.config.torch_dtype = x2ms_adapter.tensor_api.split(str(dtype), ".")[1] statement of src/transformers/modeling_utils.py.

      After the modification:

      model_to_save.config.torch_dtype = x2ms_adapter.tensor_api.split(str(dtype), ".")
    • Change the return value of is_torch_available() in ./src/transformers/utils/import_utils.py to True to follow the original PyTorch process.

      Before the modification:

      def is_torch_available():
          return _torch_available

      After the modification:

      def is_torch_available():
          return True

69

albert-large-v1

70

albert-xlarge-v1

71

albert-xxlarge-v1

72

albert-Text classification

73

albert-TokenClassification

74

albert-QA

75

albert-MultipleChoice

76

bert-base-uncased

77

bert-large-uncased

78

bert-base-QA

79

bert-base-Text classification

80

bert-base-Multiple Choice

81

bert-base-token-classification

https://github.com/huggingface/transformers/tree/49cd736a288a315d741e5c337790effa4c9fa689

82

distilbert-base-uncased

83

distilbert-base-QA

84

distilbert-base-Text classification

85

roberta-base

86

roberta-large

87

roberta-base-Multiple Choice

88

roberta-base-Text classification

89

roberta-base-token-classification

90

roberta-base-QA

https://github.com/huggingface/transformers/tree/49cd736a288a315d741e5c337790effa4c9fa689

91

xlm-mlm-en-2048

92

xlm-mlm-ende-1024

93

xlm-mlm-enro-1024

94

xlm-clm-enfr-1024

95

xlm-Text classification

96

xlm-Roberta-base

97

xlm-roberta-large

98

xlm-roberta-Text classification

99

Xlm-reberta-token-classification

100

xlm-roberta-QA

101

xlnet-base-cased

102

xlnet-large-cased

103

XLNet-base-Text classification

104

XLNet-base-token-classification

105

XLNet-base-Multiple Choice

106

XLNet-base-QA

107

DistilRoBERTa

https://github.com/huggingface/transformers/tree/49cd736a288a315d741e5c337790effa4c9fa689

After the migration, make the following modifications:

Modify the definition of is_torch_available() in the ./src/transformers/utils/import_utils.py file.

Before the modification:
def is_torch_available():
    return _torch_available

After the modification:

def is_torch_available():
    return True

108

Transform-XL

https://github.com/huggingface/transformers/tree/49cd736a288a315d741e5c337790effa4c9fa689

After the migration, make the following modifications:

  • Modify the definition of is_torch_available() in the ./src/transformers/utils/import_utils.py file.

    Before the modification:

    def is_torch_available():
        return _torch_available

    After the modification:

    def is_torch_available():
        return True
  • Because the structure after the dtype of MindSpore is cast to a character string is different from that of torch, you need to modify ./src/transformers/modeling_utils.py as follows:

    Before the modification:

    model_to_save.config.torch_dtype = x2ms_adapter.tensor_api.split(str(dtype), ".")[1]

    After the modification:

    model_to_save.config.torch_dtype = str(dtype) 

109

ConvLSTM

https://github.com/jhhuang96/ConvLSTM-PyTorch/tree/d44942983c05c66381eeb9f54e88c828e9e37cfc

  • Use the ./data/train-images-idx3-ubyte.gz dataset for training.
  • After the migration, replace all sigmoid functions in the ./ConvRNN.py file with tanh. The following is an example:

    Before the modification:

    z = x2ms_adapter.sigmoid(zgate)

    After the modification:

    z = x2ms_adapter.tanh(zgate)

110

DeepCTR-Deep & Cross Network

https://github.com/shenweichen/DeepCTR-Torch/tree/2cd84f305cb50e0fd235c0f0dd5605c8114840a2

  • Obtain the Criteo dataset, decompress the dataset, and use it for model training.
  • After the migration, modify the ./examples/run_classification_criteo.py file.
    1. Add the following content:
      from x2ms_adapter.torch_api.optimizers import optim_register
    2. Modify the dataset path. The following is an example:
      data = pd.read_csv('dataset_path')
    3. Change the model name to the model to be trained according to the following information in bold:
      model = DCN(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns,
                         task='binary',
                         l2_reg_embedding=1e-5, device=device)
      model.compile(optim_register.adagrad(x2ms_adapter.parameters(model),lr=1e-5, weight_decay=0.0001),
      "binary_crossentropy",metrics=["binary_crossentropy", "auc"], )
      history = model.fit(train_model_input, train[target].values, batch_size=512, epochs=10, verbose=2,validation_split=0.2)
      pred_ans = model.predict(test_model_input, 512)

111

DeepCTR-Deep & Wide

https://github.com/shenweichen/DeepCTR-Torch/tree/2cd84f305cb50e0fd235c0f0dd5605c8114840a2

  • Obtain the MovieLens dataset, decompress the dataset, and use it for model training.
  • After the migration, modify the ./examples/run_multivalue_movielens.py file.
    1. Modify the imported content.

      Before the modification:

      from tensorflow.python.keras.preprocessing.sequence import pad_sequences

      After the modification:

      from tensorflow.keras.preprocessing.sequence import pad_sequences
    2. Add the following content:
      from deepctr_torch.models import WDL
    3. Modify the dataset path. The following is an example:
      data = pd.read_csv('dataset_path')
    4. Change to the model to be trained according to the following information in bold:
      model = WDL(linear_feature_columns, dnn_feature_columns, task='regression', device=device)
      model.compile("adam", "mse", metrics=['mse'], )
      history = model.fit(model_input, data[target].values, batch_size=256, epochs=10, verbose=2, validation_split=0.2)

112

EfficientNet-B0

https://github.com/lukemelas/EfficientNet-PyTorch/tree/7e8b0d312162f335785fb5dcfa1df29a75a1783a

-

113

EfficientNet-B1

114

EfficientNet-B2

115

EfficientNet-B3

116

EfficientNet-B4

117

EfficientNet-B5

118

EfficientNet-B6

119

EfficientNet-B7

120

EfficientNet-B8

121

egfr-att

https://github.com/lehgtrung/egfr-att/tree/0666ee90532b1b1a7a2a179f8fbf10af1fdf862f

-

122

Faster R-CNN

https://github.com/AlphaJia/pytorch-faster-rcnn/tree/943ef668facaacf77a4822fe79331343a6ebca2d

  • The following backbone networks are supported:
    • MobileNet
    • ResNet-FPN
    • VGG16
    • HRNet
  • Before the migration, make the following modifications:
    • Because the MultiScaleRoIAlign operator of TorchVision 0.9.0 is used, you need to copy the torchvision/ops/poolers.py file where the operator is located to the root directory, and modify the content that uses the operator in ./utils/train_utils.py and ./utils/faster_rcnn_utils.py as follows:
      from poolers import MultiScaleRoIAlign
    • Because MindSpore does not have the API corresponding to torch.utils.data.Subset, you need to comment out the code related to the API in ./utils/coco_utils.py. The following is an example:
      # if isinstance(dataset, torch.utils.data.Subset):
      #     dataset = dataset.dataset
  • After the migration, make the following modifications:

    Because the BitwiseOr operator in MindSpore does not support UINT8 inputs, you need to modify the following expression in ./utils/roi_header_util.py:

    Before the modification:
    pos_inds_img | neg_inds_img
    After the modification:
    pos_inds_img.astype(mindspore.int32) | neg_inds_img.astype(mindspore.int32)

123

FCOS-ResNet50

https://github.com/zhenghao977/FCOS-PyTorch-37.2AP/tree/2bfa4b6ca57358f52f7bc7b44f506608e99894e6

After the migration, make the following modifications:

  • Because the VOC dataset is used, you need to change the dataset path in line 39 of the ./train_voc.py code to the actual path.
  • Because MindSpore does not have the corresponding scatter operator, you need to modify the ./model/loss.py file as follows:
    1. Replace lines 125 and 126 with the following code:
      min_indices = mindspore.ops.ArgMinWithValue(-1)(areas.reshape(-1, areas.shape[-1]))
      tmp = np.arange(0, batch_size * h_mul_w).astype(np.int32)
      indices = mindspore.ops.Concat(-1)((mindspore.ops.ExpandDims()(mindspore.Tensor(tmp), -1), mindspore.ops.ExpandDims()(min_indices[0], -1)))
      reg_targets = mindspore.ops.GatherNd()(ltrb_off.reshape(-1, m, 4), indices) 
    2. Replace line 130 with the following code:
      cls_targets = mindspore.ops.GatherNd()(classes.reshape(-1, m, 1), indices) 
    3. Import the corresponding package to line 7 of the file.
      import numpy as np 
  • Because no pre-trained MindSpore models exist, you need to change the values of pretrained, freeze_stage_1, and freeze_bn in ./model/config.py to False.

124

FCOS-ResNet101

125

MGN-strong

https://git.openi.org.cn/Smart_City_Model_Zoo/mgn-strong

  1. Because this model depends on TorchVision, you need to copy the models/ folder in the torchvision/ directory to the ./mgn-strong/model/ directory.
  2. Change the content of ./mgn-strong/model/models/__init__.py to the following:
    from .resnet import *
  3. Modify the import statement in line 7 of ./mgn-strong/model/mgn.py.

    Before the modification:

    from torchvision.models.resnet import resnet50, Bottleneck, resnet101

    After the modification:

    from .models.resnet import resnet50, Bottleneck, resnet101
  4. Modify the addmm_ call statement in line 83 of ./mgn-strong/loss/triplet.py.

    Before the modification:

    dist.addmm_(1, -2, inputs, inputs.t())
    After the modification:
    dist.addmm_(inputs, inputs.t(), beta=1, alpha=-2)
  5. Ensure that the model runs in MindSpore 1.7.0.

126

MobileNetV1 SSD

https://github.com/qfgaohao/pytorch-ssd/tree/f61ab424d09bf3d4bb3925693579ac0a92541b0d

In MindSpore, tensors cannot be used during dataset loading and models do not support slicing of ModuleList. Therefore, before the migration, modify the ./vision/ssd/ssd.py file in the original project folder as follows:

  • Change the for loop in line 57 to the following loop:
    for idx in range(start_layer_index, end_layer_index):
          layer = self.base_net[idx]
  • Insert the center_form_priors = center_form_priors.asnumpy() statement before the self.center_form_priors = center_form_priors statement in line 143.

127

MobileNetV1 SSD-Lite

128

MobileNetV2 SSD-Lite

129

MobileNetV3-Large SSD-Lite

130

MobileNetV3-Small SSD-Lite

131

SqueezeNet SSD-Lite

132

VGG16 SSD

133

SqueezeNet

https://github.com/weiaicunzai/pytorch-cifar100/tree/2149cb57f517c6e5fa7262f958652227225d125b

134

InceptionV3

135

InceptionV4

136

InceptionResNetV2

137

Xception

138

Attention56

139

StochasticDepth18

140

StochasticDepth34

141

StochasticDepth50

142

StochasticDepth101

143

VGG11

144

VGG13

145

VGG16

146

DenseNet161

147

DenseNet169

148

DenseNet201

149

PreActResNet34

150

PreActResNet50

151

PreActResNet101

152

PreActResNet152

153

ResNeXt152

154

SEResNet34

155

SEResNet50

156

SEResNet101

157

VGG19

https://github.com/kuangliu/pytorch-cifar/tree/49b7aa97b0c12fe0d4054e670403a16b6b834ddd

158

PreActResNet18

159

DenseNet121

160

ResNeXt29_2x64d

161

MobileNet

162

MobileNetV2

163

SENet18

164

ShuffleNetG2

165

GoogleNet

166

DPN92

167

RetineNet-ResNet34

https://github.com/yhenon/pytorch-retinanet/tree/0348a9d57b279e3b5b235461b472d37da5feec3d

  • Because the original code in the repository contains the code about the torch version and torch model loading, you need to modify the original project script ./train.py before the migration.
    • In backbone model selection in lines 77 to 88, set the pretrained parameter to False.
    • Delete assert torch.__version__.split('.')[0] == '1' from line 18.
  • After the migration, make the following modifications due to the restrictions on MindSpore backpropagation and dataset loading:
    Replace lines 25 and 26 in ./retinanet/losses.py with the following code:
    def print_grad_fn(cell_id, grad_input, grad_output):
        pass
    class FocalLoss(mindspore.nn.Cell):
        def __init__(self):
            super(FocalLoss, self).__init__()
            self.register_backward_hook(print_grad_fn)

168

RetineNet-ResNet50

169

Res2Net

https://github.com/Res2Net/Res2Net-ImageNet-Training/tree/d77c16ff111522c64e918900f100699acc62f706

Because the migration of torchvision.models APIs is not supported, you need to perform the following operations:

Modify the original project.

  1. Create the ./res2net_pami/models directory.
  2. In ./res2net_pami/main.py, change import torchvision.models as models to import models.

170

ResNet-18

https://github.com/pytorch/examples/tree/41b035f2f8faede544174cfd82960b7b407723eb/imagenet

Because the migration of torchvision.models APIs is not supported, you need to perform the following operations:

Modify the original project.

  1. Create the ./imagenet/models directory.
  2. Copy torchvision/models/resnet.py from the TorchVision library (version 0.6.0) to ./imagenet/models and delete the from .utils import load_state_dict_from_url statement.
  3. Create the ./imagenet/models/__init__.py file. The file content is as follows:
    from .resnet import *
  4. In ./main.py, change import torchvision.models as models to import models.

171

ResNet-34

172

ResNet-50

173

ResNet-101

174

ResNet-152

175

ResNeXt-50 (32x4d)

176

ResNeXt-101 (32x8d)

177

Wide ResNet-50-2

178

Wide ResNet-101-2

179

sparse_rcnnv1-resnet50

https://github.com/liangheming/sparse_rcnnv1/tree/65f54808f43c34639085b01f7ebc839a3335a386

After the migration, make the following modifications:
  • In ./x2ms_adapter.torch_api.nn_api.nn.py, manually change the values of batch_size, src_seq_length, and tgt_seq_length of the initialization function in the MultiheadAttention class.
  • In ./nets/common.py, change the if x.requires_grad: statement to if True:.
  • In ./losses/sparse_rcnn_loss.py, convert the item[i] variable of the linear_sum_assignment function to NumPy.
    indices = linear_sum_assignment(item[i].asnumpy())
  • Modify ./datasets/coco.py as follows:
    • Change the return statement return box_info of the __getitem__ definition module to return box_info.img,box_info.labels,box_info.boxes.
    • Modify the for loop of the collect_fn definition module.
      image,labels,boxes = item #Add
      img = (image[:, :, ::-1] / 255.0 - np.array(rgb_mean)) / np.array(rgb_std)# Change item.img to image.
      target = x2ms_np.concatenate([labels[:, None], boxes], axis=-1)# Change item.labels to labels, and item.boxes to boxes.

180

sparse_rcnnv1-resnet101

181

ShuffleNetV2

https://github.com/megvii-model/ShuffleNet-Series/tree/aa91feb71b01f28d0b8da3533d20a3edb11b1810

-

182

ShuffleNetV2+

183

SMSD

https://git.openi.org.cn/PCLNLP/Sarcasm_Detection/src/commit/54bae1f2306a4d730551b4508ef502cfdbe79918

Before the migration, perform the following operations:

  • Create the state_dict folder in ./SMSD/.
  • Add the following statement to ./SMSD/models/__init__.py to import the SMSD_bi model:
    from models.SMSD_bi import SMSD_bi

You can use the --repeat parameter in the migrated code to control the number of training repetitions (with the SMSD_bi model as an example).

python3 train.py --model_name SMSD_bi --repeat 1

184

SMSD_bi

185

Swin-Transformer

https://github.com/microsoft/Swin-Transformer/tree/5d2aede42b4b12cb0e7a2448b58820aeda604426

  • Before the migration, place the timm library code to the root directory of the source code.
  • The recommended timm library version is 0.4.12.
  • Currently, the --cfg parameter supports only the following configuration files:
    • swin_tiny_patch4_window7_224.yaml
    • swin_tiny_c24_patch4_window8_256.yaml
    • swin_small_patch4_window7_224.yaml
    • swin_base_patch4_window7_224.yaml

186

Transformer

https://github.com/SamLynnEvans/Transformer/tree/e06ae2810f119c75aa34585442872026875e6462

Migrate the torchtext library on which the scripts in the code repository depend and note the following:

  • Copy the migrated torchtext_x2ms to the script folder.
  • Rename torchtext_x2ms as torchtext to ensure that the migrated torchtext is called.
  • The recommended torchtext version is 0.6.0.

187

UNet

https://github.com/milesial/Pytorch-UNet/tree/e1a69e7c6ce18edd47271b01e4aabc03b436753d

Before static graph migration, perform the following operations:

  1. Modify line 14 in the ./utils/dice_score.py file.

    Before the modification:

    if sets_sum.item() == 0:

    After the modification:

    if sets_sum == 0:
  2. Change the value of net.n_classes in F.one_hot(true_masks, net.n_classes).permute(0, 3, 1, 2).float() in line 95 of the ./train.py file to the value of n_classes in line 171.

188

RCNN-Unet

https://github.com/bigmb/Unet-Segmentation-Pytorch-Nest-of-Unets/tree/c050f5eab6778cba6dcd8f8a68b74c9e62a698c8

Before the migration, perform the following operations:

  • Due to the syntax restrictions on MindSpore derivation, the comments in lines 249 and 252 in ./pytorch_run.py need to be aligned by a multiple of four spaces.
  • The model requires that the size of the input image be a multiple of 16. Therefore, if the size of a dataset image is not a multiple of 16, you need to remove the comments in lines 121, 122, 505, and 506 in ./pytorch_run.py to crop and scale the image to a multiple of 16.
  • If dataset label images have one channel, add .convert('RGB') to the end of line 293 in ./pytorch_run.py to convert the images to 3-channel images.
  • If ModuleList is used in MindSpore, the weight name of the sublayer changes. Therefore, you need to change torch.nn.ModuleList in line 350 of ./pytorch_run.py to list to prevent the failure to reload the checkpoint file after it is saved.

189

Attention Unet

190

RCNN-Attention Unet

191

Nested Unet

192

ViT-B_16

https://github.com/jeonsworld/ViT-pytorch/tree/460a162767de1722a014ed2261463dbbc01196b6

The cifar-10-bin dataset is required, which can be obtained from https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz.

193

ViT-B_32

194

ViT-L_16

195

ViT-L_32

196

ViT-H_14

197

R50-ViT-B_16

198

YOLOR-CSP

https://github.com/WongKinYiu/yolor/tree/462858e8737f56388f812cfe381a69c4ffca0cc7

After the migration, make the following modifications:

  1. Modify the ./utils/datasets.py file.

    Before the modification:

    if os.path.isfile(cache_path):

    After the modification:

    if False:
  2. Modify the create_module function in the ./models/models.py file.

    Before the modification:

    module_list[j][0].bias =
    mindspore.Parameter(bias_, ...)

    After the modification:

    module_list[j][0].bias =
    mindspore.Parameter(bias.reshape(bias_.shape), ...)
  3. Modify the build_targets function in the ./utils/loss.py file.

    Before the modification:

    gij = x2ms_adapter.tensor_api.long((...))
    gi, gj = gij.T
    ...
    tbox.append(...)

    After the modification:

    gij = x2ms_adapter.tensor_api.long((...)).T
    gi, gj = gij
    ...
    gij = gij.T
    tbox.append(...)
  4. Modify the ./train.py file.

    Before the modification:

    if '.bias' in k: 

    After the modification:

    if '.bias' in k or '.beta' in k:

199

YOLOR-CSP-X

200

YOLOR-P6

201

YOLOR-W6

202

YOLOv3

https://github.com/ultralytics/yolov3/tree/ae37b2daa74c599d640a7b9698eeafd64265f999

After the migration, make the following modifications:

  • Modify ./models/yolo.py.
    class Detect(mindspore.nn.Cell):
        stride = None #Delete
        onnx_dynamic = False 
        def __init__(self, …):
    ...
    	self.stride = None #Add
  • Modify the build_targets function in ./utils/loss.py.
    Before the modification:
    gij = x2ms_adapter.tensor_api.long((...))
    gi, gj = gij.T
    ...
    tbox.append(...)
    After the modification:
    gij = x2ms_adapter.tensor_api.long((…)).T
    gi, gj = gij
    ...
    gij = gij.T
    tbox.append(...)
  • Modify the run function in ./val.py.
    • Delete path, shape = Path(paths[si]), shapes[si][0].
    • Delete the calling position of the scale_coords function.
    • Delete callbacks.run('on_val_image_end',…).
  • Change every nn.* in the model configuration file {model_name}.yaml in the ./models/ directory to x2ms_adapter.torch_api.nn_api.nn.*.
  • In the multi-device scenario, change the value of rect in val_loader = create_dataloader (...) in train.py to False.

203

YOLOv3-Tiny

204

YOLOv3-SSP

205

YOLOv4

https://github.com/WongKinYiu/PyTorch_YOLOv4/tree/eb5f1663ed0743660b8aa749a43f35f505baa325

After the migration, make the following modifications:

  • Modify the create_module function in ./model/models.py.
    Before the modification:
    module_list[j][0].bias = mindspore.Parameter(bias_, ...)
    After the modification:
    module_list[j][0].bias = mindspore.Parameter(bias.reshape(bias_.shape), ...)
  • Modify ./utils/datasets.py.
    Before the modification:
    if os.path.isfile(cache_path): 
    After the modification:
     if False:
  • Modify the build_targets function in ./utils/loss.py.
    Before the modification:
    gij = x2ms_adapter.tensor_api.long((...))
    gi, gj = gij.T
    ...
    tbox.append(...)
    After the modification:
    gij = x2ms_adapter.tensor_api.long((…)).T
    gi, gj = gij
    ...
    gij = gij.T
    tbox.append(...)
  • Modify ./train.py.
    • Change if '.bias' in k: to if '.bias' in k or '.beta' in k:.
    • Change character string 'Conv2d.weight' to '.weight'.
  • In the multi-device scenario, change the value of rect in testloader = create_dataloader(…) in ./train.py to False.

206

YOLOv4-tiny

207

YOLOv4-pacsp

208

YOLOv4-paspp

209

YOLOv4-csp-leaky

210

YOLOv5l

https://github.com/ultralytics/yolov5/tree/8c420c4c1fb3b83ef0e60749d46bcc2ec9967fc5

After the migration, make the following modifications:

  • Modify ./models/yolo.py.
    class Detect(mindspore.nn.Cell):
        stride = None #Delete
    ...
        def __init__(self, …):
    ...
    	self.stride = None #Add
  • Modify the build_targets function in ./utils/loss.py.
    Before the modification:
    gij = x2ms_adapter.tensor_api.long((...))
    gi, gj = gij.T
    ...
    tbox.append(...)
    After the modification:
    gij = x2ms_adapter.tensor_api.long((…)).T
    gi, gj = gij
    ...
    gij = gij.T
    tbox.append(...)
  • Modify the run function in ./val.py.
    • Delete path, shape = Path(paths[si]), shapes[si][0].
    • Delete the calling position of the scale_coords function.
    • Delete callbacks.run('on_val_image_end',…).
  • Change every nn.* in the model configuration file {model_name}.yaml in the ./models/ directory to x2ms_adapter.torch_api.nn_api.nn.*.
  • In the multi-device scenario, change the value of rect in val_loader = create_dataloader (...) in ./train.py to False.

211

YOLOv5m

212

YOLOv5n

213

YOLOv5s

214

YOLOv5x

215

YOLOX

https://github.com/bubbliiiing/yolox-pytorch/tree/1448e849ac6cdd7d1cec395e30410f49a83d44ec

After the migration, make the following modifications:
  • Comment out the code in line 341 of ./train.py.
    #'adam'  : optim_register.adam(pg0, Init_lr_fit, betas = (momentum, 0.999))
  • Before training, run the following command to prevent HCCL timeout:
    export HCCL_CONNECT_TIMEOUT=3000

216

AAGCN-ABSA

https://git.openi.org.cn/PCLNLP/SentimentAnalysisNLP/src/commit/7cf38449dad742363053c4cc380ebfe33292184d

-

217

CAER-ABSA

  • This model depends on the third-party library pytorch-pretrained-bert. Download it and copy its subdirectory pytorch_pretrained_bert to the SentimentAnalysisNLP/ directory.
  • Move the definition of the BertLayerNorm class in line 158 of the ./SentimentAnalysisNLP/pytorch_pretrained_bert/modeling.py file out of the try-except block.

218

GIN-ABSA

  • This model depends on the third-party library pytorch-pretrained-bert. Download it and copy its subdirectory pytorch_pretrained_bert to the SentimentAnalysisNLP/ directory.
  • MindSpore does not support tensor creation during data processing. Therefore, you need to remove tensor creation during dataset initialization from ./GIN-ABSA/data_utils.py, including removing the torch.tensor() operation from line 147 and the torch.tensor() operation from line 234.

219

Scon-ABSA

  • Because this model depends on the pre-training weight of bert-base-uncased in Hugging Face, you need to download pytorch_model.bin, convert it to pytorch_model.ckpt in MindSpore format, and load the generated model weight in the script.
  • Because this model depends on the third-party library pytorch-pretrained-bert, you need to download it and copy its subdirectory pytorch_pretrained_bert to the SentimentAnalysisNLP directory.
  • Move the definition of the BertLayerNorm class in line 158 of the ./pytorch_pretrained_bert/modeling.py file out of the try-except block.

220

Trans-ECE

  • Because this model depends on the pre-training weight of bert-base-chinese in Hugging Face, you need to download bert-base-chinese to the current directory and convert the model weight file pytorch_model.bin to pytorch_model.bin.ckpt in MindSpore format.
  • Due to defects in the source code, you need to use a list to wrap the filter in lines 48 and 49 and delete the unnecessary trans_optimizer parameter from line 54 in ./Trans-ECE/Run.py.
  • Because custom optimizers are not supported, you need to change BertAdam in line 55 of ./Trans-ECE/Run.py to optim.Adam.

221

PyramidNet 101

https://github.com/dyhan0920/PyramidNet-PyTorch/tree/5a0b32f43d79024a0d9cd2d1851f07e6355daea2

Before the migration, make the following modifications:

  • Because the original code in the repository has restrictions on the Python and PyTorch versions, you need to make code adaptation according to https://github.com/dyhan0920/PyramidNet-PyTorch/issues/5.
  • Because the migrated code does not need the torchvision module, you need to comment out lines 23 to 25 in train.py.
    #model_names = sorted(name for name in models.__dict__
    #    if name.islower() and not name.startswith("__")
    #    and callable(models.__dict__[name]))

222

PyramidNet 164 bottleneck

223

PyramidNet 200 bottleneck

Table 2 TensorFlow 2 model list

No.

Model

Reference Link to Original Training Project Code

Remarks

1

ALBERT_base_v2

https://github.com/huggingface/transformers/tree/49cd736a28

  • Before the migration, remove the template files of the original repository. These files are not Python files but are suffixed with .py.
    mv templates ../  
  • After the migration, make the following modifications:
    • In ./examples/tensorflow/language-modeling/run_mlm.py:
      • Add the following package import statement:
        from x2ms_adapter.keras.losses import SparseCategoricalCrossentropy
      • Change the value of return_tensors in DataCollatorForLanguageModeling from tf to np.

        Before the modification:

        data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm_probability=data_args.mlm_probability, return_tensors="tf")

        After the modification:

        data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm_probability=data_args.mlm_probability, return_tensors="np")
      • Modify the parameter called by model.compile.

        Before the modification:

        model.compile(optimizer=optimizer)

        After the modification:

        model.compile(optimizer=optimizer, loss=SparseCategoricalCrossentropy(True))
    • Modify the dtype_byte_size method of ./src/transformers/modeling_tf_utils.py.

      Before the modification:

      bit_search = re.search("[^\d](\d+)$", dtype.name)

      After the modification:

      bit_search = re.search("[^\d](\d+)$", str(dtype))

2

ALBERT_large_v2

3

ALBERT_xlarge_v2

4

ALBERT_xxlarge_v2

5

ALBERT_base_v1

6

ALBERT_large_v1

7

ALBERT_xlarge_v1

8

ALBERT_xxlarge_v1

9

roberta-base

10

roberta-large

11

RBT6

12

RBT4

13

RBTL3

14

RBT3

15

CIFAR-VGG

https://github.com/dragen1860/TensorFlow-2.x-Tutorials/tree/9861a308283d17693d497fdfaab20b92c0b26d08

  • To reduce unnecessary migration time, you are advised to migrate only the 06-CIFAR-VGG folder.
  • Download the CIFAR-10 (Python version) dataset and decompress it.
  • After the migration, modify the ./06-CIFAR-VGG_x2ms/main.py file as follows:
    1. Modify the dataset path. The following is an example:

      Before the modification:

      (x,y), (x_test, y_test) = x2ms_ks_cifar10.load_data()
      After the modification:
      (x,y), (x_test, y_test) = x2ms_ks_cifar10.load_data(data_dir='dataset_path')
    2. Delete the map operation.

      Before the modification:

      train_loader = train_loader.map(prepare_cifar).shuffle(50000).batch(256)
      test_loader = test_loader.map(prepare_cifar).shuffle(10000).batch(256)

      After the modification:

      train_loader = train_loader.shuffle(50000).batch(256)
      test_loader = test_loader.shuffle(10000).batch(256)
    3. Specify the reduction of the loss function.

      Before the modification:

      criteon = x2ms_ks_losses.CategoricalCrossentropy(from_logits=True)

      After the modification:

      criteon = x2ms_ks_losses.CategoricalCrossentropy(from_logits=True, reduction='mean')

16

DenseNet_121

https://github.com/calmisential/Basic_CNNs_TensorFlow2/tree/f063c84451f12e904f9c91c51278be52afccb0c2

  • Configure epoch, batch_size, and the dataset path in ./configuration.py as required.
  • Before the migration, comment out the regnet.RegNet code line in the ./models/__init__.py file.
    #regnet.RegNet()

17

DenseNet_169

18

EfficientNet_B0

19

EfficientNet_B1

20

Inception_V4

21

MobileNet_V1

22

MobileNet_V2

23

MobileNet_V3_Large

24

MobileNet_V3_Small

25

ResNet_101

26

ResNet_152

27

ResNet_18

28

ResNet_34

29

ResNet_50

30

ResNext_101

31

ResNext_50

32

Shufflenet_V2_x0_5

33

Shufflenet_V2_x1_0

34

EfficientNet_B2

https://github.com/calmisential/Basic_CNNs_TensorFlow2/tree/f063c84451f12e904f9c91c51278be52afccb0c2

  • Before the migration, process the dataset according to the README.
  • Configure epoch, batch_size, dataset path, and class quantity in ./configuration.py as required.
  • Modify line 7 in the ./configuration.py file. For example, change the class quantity to 10 as follows:

    Before the modification:

    NUM_CLASSES = 5

    After the modification:

    NUM_CLASSES = 10
  • Before the migration, comment out line 21 in the ./models/__init__.py file.
    #regnet.RegNet()
  • Before migrating the DenseNet_201 and DenseNet_264 models, add the following code after shufflenet_v2.shufflenet_2_0x(), in line 20 of the ./models/__init__.py file:
    densenet.densenet_201(), densenet.densenet_264()

35

EfficientNet_B3

36

EfficientNet_B4

37

EfficientNet_B5

38

EfficientNet_B6

39

EfficientNet_B7

40

SE_ResNet_50

41

SE_ResNet_101

42

SE_ResNet_152

43

SE_ResNext_50

44

SE_ResNext_101

45

DenseNet_201

46

DenseNet_264

47

AFM

https://github.com/ZiyaoGeng/Recommender-System-with-TF2.0/tree/1d2aa5bf551873d5626539c196705db46d55c7b6

Because every network folder depends on the ./data_process/ directory, you need to directly migrate the Recommender-System-with-TF2.0/ directory or copy the ./data_process/ directory to the network folder before the migration.

48

Caser

49

DCN

50

Deep_Crossing

51

DeepFM

52

DNN

53

FFM

54

FM

55

MF

56

NFM

57

PNN

58

WDL

59

BiLSTM-CRF

https://github.com/kangyishuai/BiLSTM-CRF-NER/tree/84bde29105b13cd8128bb0ae5d043c4712a756cb

  • Training must be performed in MindSpore 1.7.
  • Download the complete dataset according to README.md of the original training project, decompress the dataset, and copy files in the dataset to ./data.
  • After the migration, decrease the values of batch_size, hidden_num, and embedding_size in ./main.py based on the training status. The following is an example:
    params = {
        "maxlen": 128,
        "batch_size": 140,
        "hidden_num": 64,
        "embedding_size": 64,
        "lr": 1e-3,
        "epochs": 10
    }

60

FCN

https://github.com/YunYang1994/TensorFlow2.0-Examples/tree/299fd6689f242d0f647a96b8844e86325e9fcb46/5-Image_Segmentation/FCN

The scipy.misc.imread method used in ./parser_voc.py is an API of SciPy earlier than 1.2.0. MindSpore is compatible with SciPy 1.5.2 or later. Therefore, use the imageio.imread recommended in the official deprecation warning of SciPy.

61

GoogleNet

https://github.com/marload/ConvNets-TensorFlow2/tree/29411e941c4aa72309bdb53c67a6a2fb8db57589

  • After the load_data() API is migrated, use the data_dir parameter to specify the dataset path or place the dataset in the default path ~/x2ms_datasets/cifar10/cifar-10-batches-py.
  • For the VGG16 model, modify line 9 in the ./utils.py file before the migration.

    Before the modification:

    if nets_name == 'VGG16':

    After the modification:

    if nets_name == 'vgg16':

62

SqueezeNet

63

Vgg11

64

VGG13

65

VGG16

66

VGG19

67

Unet

https://github.com/YunYang1994/TensorFlow2.0-Examples/tree/299fd6689f242d0f647a96b8844e86325e9fcb46/5-Image_Segmentation/Unet

Use Membrane as the dataset, which can be obtained from README.md of the training project.

68

U-Net_Med

https://github.com/monchhichizzq/Unet_Medical_Segmentation/tree/876d5adbeb17fa79dbf644dd1d6e91840f904e2d

  • Before the migration, modify the ./Preprocess/Data_Loader.py file.
    1. Add the following content to line 11:
      import random
    2. Change the shuffle function to random.shuffle.
      Before the modification:
      shuffle(self.train_lines)
      After the modification:
      random.shuffle(self.train_lines)
  • After the migration, download the Medical_Datasets dataset and place it in the root directory of the migrated model.
  • After the migration, modify the ./train.py file to specify the optimizer to be used.
    Before the modification:
    optimizer=x2ms_ks_optimizers.Adam(lr=lr),
    After the modification:
    optimizer=x2ms_ks_optimizers.SGD(lr=lr),

69

VAE

https://github.com/dragen1860/TensorFlow-2.x-Tutorials/tree/9861a308283d17693d497fdfaab20b92c0b26d08

To reduce unnecessary migration time, you are advised to migrate only the 12-VAE folder.

After the migration, make the following modifications:

  • Download the Fashion-MNIST dataset.
  • Modify the ./12-VAE_x2ms/main.py file.
  1. Delete the following content:
    assert tf.__version__.startswith('2.')
  2. Specify the dataset path.
    (x_train, y_train), (x_test, y_test) = x2ms_ks_mnist.load_fashion_data('dataset_path')
  3. Modify the training input in the original model.
    Before the modification:
    one_step_cell()
    After the modification:
    one_step_cell(x)

70

Vit

https://github.com/tuvovan/Vision_Transformer_Keras/tree/6a1b0959a2f5923b1741335aca5bc2f8dcc7c1f9

  • After the load() API is ported, use the data_dir parameter to specify the dataset path or place the dataset in the default path ~/x2ms_datasets/cifar10/cifar-10-batches-bin.
  • Delete the comma (,) from early_stop = tf.keras.callbacks.EarlyStopping(patience=10), in train.py to ensure that the callback object is a single instance instead of a tuple.

71

Yolov5-l-mish

https://github.com/LongxingTan/tfyolo/tree/df4fa04aa9ee10cb8147f04f63f1484a1fa926fa

  1. Modify and process the dataset based on the README.md of the original network.
  2. Before the migration, make the following modifications:
    1. Add the following content to line 11 in the ./yolo/model/yolo.py file:
      from tensorflow.keras.layers import Layer, Conv2D
    2. Modify lines 30 and 31 in the ./yolo/dataset/load_data.py file.

      Before the modification:

         dataset = dataset.map(self.transform, num_parallel_calls=tf.data.experimental.AUTOTUNE)
      dataset = dataset.batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE)

      After the modification:

          dataset = dataset.map(self.transform, output_nums=4)
      dataset = dataset.batch(batch_size)
    3. Modify line 36 in the ./yolo/dataset/load_data.py file.

      Before the modification:

      return image, label_encoder

      After the modification:

      return (image,) + label_encoder
  3. Perform the migration.
  4. Before the migration, make the following modifications:
    1. Modify line 106 in the ./yolo/train.py file.

      Before the modification:

      for step, (image, target) in enumerate(train_dataset): 

      After the modification:

      for step, (image, *target) in enumerate(train_dataset): 
    2. Modify line 145 in the ./yolo/train.py file.

      Before the modification:

      self.optimizer.lr.assign(lr)

      After the modification:

      self.optimizer.learning_rate = lr
    3. Modify line 178 in the ./yolo/train.py file.

      Before the modification:

      trainer.anchors,

      After the modification:

      trainer.anchors.asnumpy(),
    4. Modify line 7 in the ./yolo/dataset/label_anchor.py file.

      Before the modification:

      from x2ms_adapter import ops as x2ms_ops

      After the modification:

      from x2ms_adapter import numpy_ops as x2ms_ops
    5. Modify line 193 in the ./yolo/model/module.py file.

      Before the modification:

      return x2ms_transforms.resize_image(x, (x2ms_ops.get_shape(x)[1] * self.ratio, x2ms_ops.get_shape(x)[2] * self.ratio), method=self.method)

      After the modification:

      return x2ms_ops.to_tensor(x2ms_transforms.resize_image(x, (x2ms_ops.get_shape(x)[1] * self.ratio, x2ms_ops.get_shape(x)[2] * self.ratio), method=self.method))
    6. Perform this step only for the Yolov5-s-mish network. Change the stride value in the Detect class in line 88 of the ./yolo/model/yolo.py file.

      Before the modification:

      self.stride = np.array([8, 16, 32], np.float32)

      After the modification:

      self.stride = np.array([16, 32, 64], np.float32)
    7. Perform this step only for the Yolov5-x-mish network. Modify line 4 in the ./yolo/configs/yolo-x-mish.yaml file.

      Before the modification:

      width_multiple: 1.25

      After the modification:

      width_multiple: 1.0
  5. Perform post-migration training.

    The ./yolo/configs/ directory stores the configuration files of four models. When executing a training job, use the --yaml_dir parameter to specify the .yaml file of the corresponding model.

    An example command for starting a job is as follows:

    python3 yolo/train.py \
    --train_annotations_dir data/voc/voc_train.txt \
    --test_annotations_dir data/voc/voc_test.txt \
    --class_name_dir data/voc/voc.names \
    --yaml_dir yolo/configs/yolo-l-mish.yaml \
    --n_epochs 5

72

Yolov5-m-mish

73

Yolov5-s-mish

74

Yolov5-x-mish

Table 3 TensorFlow 1 model list

No.

Model

Reference Link to Original Training Project Code

Remarks

1

ALBERT-base-v2

https://github.com/google-research/ALBERT/tree/a36e095d3066934a30c7e2a816b2eeb3480e9b87

Before the migration, make the following modifications:

  • In ./classifier_utils.py, change the following statement:
    if t.dtype == tf.int64:

    To:

    if t.dtype == "int64":
  • Modify the ./optimization.py file as follows:
    • Before the modification:

      optimizer = AdamWeightDecayOptimizer(

      After the modification:

      optimizer = tf.keras.optimizers.Adam(
    • Before the modification:

      train_op = tf.group(train_op, [global_step.assign(new_global_step)])

      After the modification:

      train_op = tf.group(train_op, global_step)
  • If the Glue-MNLI dataset is used, the Record dataset needs to be generated based on the README file.

2

ALBERT-large-v2

3

ALBERT-xlarge-v2

4

ALBERT-xxlarge-v2

5

AFM

https://github.com/cheungdaven/DeepRec/tree/68a34cb495911e797d85cbd962526188f4aede12

After the migration, make the following modifications:

  • When using the NNMF, NRR, I-AutoRec, U-AutoRec, FM, NFM, AFM or DEEP-FM model, change the dataset path to the actual path as required. The following is an example:
    1. Change the dataset path in the ./test/test_rating_pred.py file. The following is an example:

      Before the modification:

      path="../Data/ml100k/movielens_100k.dat"

      After the modification:

      path="./data/ml100k/movielens_100k.dat"
    2. Change the dataset path in the ./utils/load_data/load_data_content.py file. The following is an example:

      Before the modification:

      train_file = "../Data/frappe/frappe.train.libfm"
      test_file = "../Data/frappe/frappe.test.libfm"

      After the modification:

      train_file = "./data/frappe/frappe.train.libfm"
      test_file = "./data/frappe/frappe.test.libfm"
  • When using the Caser, PRME, or AttRec model, change the dataset path in the ./test/testSeqRec.py file to the actual path as required. The following is an example:

    Before the modification:

    "../data/ml100k/temp/train.dat"
    "../data/ml100k/temp/test.dat"
    After the modification:
    "./data/ml100k/temp/train.dat"
    "./data/ml100k/temp/test.dat"
  • When using the NRR model, modify the ./models/rating_prediction/nrr.py file.

    Before the modification:

    input = x2ms_ops.matmul(user_latent_factor, W_User) + x2ms_ops.matmul(item_latent_factor, W_Item) + b

    After the modification:

    input = x2ms_ops.matmul(user_latent_factor, W_User) + x2ms_ops.matmul(item_latent_factor, W_Item) + b.value
  • When using the AFM model, modify the ./models/rating_prediction/afm.py file.
    1. Before the modification:
      self.train_features = x2ms_base_v1.placeholder(mstype.int32, shape=[None,None])
      self.y = x2ms_base_v1.placeholder(mstype.float32, shape=[None, 1])

      After the modification:

      self.train_features = x2ms_base_v1.placeholder(mstype.int32, shape=[valid_dim, valid_dim])
      self.y = x2ms_base_v1.placeholder(mstype.float32, shape=[valid_dim, 1])
    2. Before the modification:
      self.attention_relu = x2ms_ops.reduce_sum( x2ms_ops.multiply(self.attention_p, x2ms_ops.relu(self.attention_mul + self.attention_b)), 2, keep_dims=True)

      After the modification:

      self.attention_relu = x2ms_ops.reduce_sum( x2ms_ops.multiply(self.attention_p, x2ms_ops.relu(self.attention_mul + self.attention_b.value)), 2, keep_dims=True)
  • When using the Caser model, modify the ./models/seq_rec/Caser.py file.
    1. Change the values of learning_rate and epoch as required. The following is an example after the modification:
      def __init__(self, sess, num_user, num_item, learning_rate=0.00001, reg_rate=1e-2, epoch=100, batch_size=20000, show_time=False, T=1, display_step=1000, verbose=False):
    2. Before the modification:
      return params[0]

      After the modification:

      return params
  • When using the PRME model, modify the ./models/seq_rec/PRME.py file.
    1. Change the values of learning_rate, epoch, and batch_size as required. The following is an example after the modification:
      def __init__(self, sess, num_user, num_item, learning_rate=0.00001, reg_rate=1e-2, epoch=100, batch_size=20000, show_time=False, T=1, display_step=1000, verbose=False):
    2. Before the modification:
      return - self.sess.run([self.test_prediction], feed_dict={self.user_id: user_id,
      self.item_seq: self.test_sequences[user_id, :],
      self.item_id_test: item_id})[0]
      After the modification:
      return - self.sess.run([self.test_prediction], feed_dict={self.user_id: user_id,
      self.item_seq: self.test_sequences[user_id, :],
      self.item_id_test: item_id})
  • Due to operator differences, modify the ./models/seq_rec/AttRec.py file when using the AttRec model.

    Before the modification:

    signal = x2ms_ops.pad(signal, [[0, 0], [0, x2ms_ops.mod(channels, 2)]])

    After the modification:

    signal = x2ms_ops.pad(signal, [[0, 0], [0, int(x2ms_ops.mod(channels, 2))]])

6

AttRec

7

Caser

8

DEEP-FM

9

FM

10

I-AutoRec

11

NFM

12

NNMF

13

NRR

14

PRME

15

U-AutoRec

16

Attention-Based Bidirectional RNN

https://github.com/dongjun-Lee/text-classification-models-tf/tree/768ea13547104f56786c52f0c6eb99912c816a09

Because the training parameters have been processed by the dropout operator in MindSpore, you need to change the value of the self.keep_prob attribute in the model definition file to 0.5 without using the where statement.

17

Character-level CNN

18

RCNN

19

Very Deep CNN

20

Word-level Bidirectional RNN

21

Word-level CNN

22

BERT-Tiny

https://github.com/google-research/bert/tree/eedf5716ce1268e56f0a50264a88cafad334ac61

Before the migration, make the following modifications:

  • In ./run_classifier.py:
    • Delete .value from hidden_size = output_layer.shape[-1].value in line 592 of the source code.
      hidden_size = output_layer.shape[-1]
    • Comment out the following code in lines 869 and 870 of the source code:
      #file_based_convert_examples_to_features(
      #     train_examples, label_list, FLAGS.max_seq_length, tokenizer, train_file)
    • In the _decode_record function, change line 529 of the source code:
      if t.dtype == tf.int64:

      To:

      if t.dtype == 'int64'
  • In ./optimization.py:
    • Replace the instantiation code of AdamWeightDecayOptimizer with optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate).
      #optimizer = AdamWeightDecayOptimizer(
      #...
      #)
      optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate)
    • Before the modification:

      train_op = tf.group(train_op, [global_step.assign(new_global_step)])

      After the modification:

      train_op = tf.group(train_op, global_step)

23

BERT-Mini

24

BERT-Small

25

BERT-Medium

26

BERT-Base

27

Inception v1

https://github.com/tensorflow/models/tree/164bab98cc218f5c8cbd6ec1156cd6f364032a1b

After the migration, modify the ./models/research/slim_x2ms/train_image_classifier.py file as follows:

  1. Add argument crop_image=False to the image_preprocessing_fn function, for example:
    image = image_preprocessing_fn(image, train_image_size, train_image_size, crop_image=False)
  2. Add the following content before the train_tensor = x2ms_ops.identity(total_loss, name='train_op') statement:
    total_loss = x2ms_ops.depend(total_loss, update_op)

28

Inception v2

29

Inception v4

30

Inception-ResNet-v2

31

RBT6

https://github.com/bojone/bert4keras/tree/9c1c916def4d515a046c414

Before the migration, make the following modifications:

  • In ./examples/task_language_model.py:
    • Change the values of checkpoint_path, config_path, dict_path, input training data, and batch_size.
    • txt = open(txt, encoding='gbk').read()

      Changes to:

      txt = open(txt, encoding='utf8').read()
  • In ./bert4keras/layers.py, add the following import statement after the from keras.layers import * statement:
    from keras.layers import Input, Dropout, Lambda, Add, Dense, Activation
  • In ./bert4keras/models.py, add the following import statement after the from bert4keras.layers import * statement:
    from bert4keras.layers import Input, Dropout, Lambda, Add, K, Dense, Activation

32

RBT4

33

RBTL3

34

RBT3

35

RoBERTa-wwm-ext-large

36

RoBERTa-wwm-ext

37

Bi-LSTM-CRF

https://github.com/fzschornack/bi-lstm-crf-tensorflow/tree/5181106

  • Before the migration, create the ./bi-lstm-crf-tensorflow.py file and copy the code in the bi-lstm-crf-tensorflow.ipynb file to the newly created Python file.
  • After the migration, change the assignment statement value of the num_units variable in ./bi-lstm-crf-tensorflow.py based on the training status. The following example changes the value to 64:
    #num_units = 128
    num_units = 64

38

CNN-LSTM-CTC

https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/tree/6999cd19285e7896cfe77d50097b0d96fb4e53e8

  • Before the migration, comment out line 43 in utils.py.
    #tf.app.flags.DEFINE_string('log_dir', './log', 'the logging dir')
  • After the migration, decrease the value of validation_steps in ./utils.py to facilitate quick observation of the model convergence effect during training. The following example changes the value to 50:
    x2ms_FLAGS.define_integer('validation_steps', 50, 'the step to validation')
  • In the root directory of the project, create the ./imgs/train and ./imgs/val folders, and save the specified training and test data to the folders.

39

DCN

https://github.com/princewen/tensorflow_practice/tree/master/recommendation

Before the migration, modify the DCN model as follows:

  1. Modify line 63 in the DCN.py file.

    Before the modification:

    self.numeric_value = tf.placeholder(tf.float32,[None,None],name='num_value')

    After the modification:

    self.numeric_value = tf.placeholder(tf.float32,[None,9],name='num_value')
  2. Modify line 89 in the DCN.py file.

    Before the modification:

    self.y_deep = x2ms_nn.dropout(self.y_deep,self.dropout_keep_deep[i+1])

    After the modification:

    self.y_deep = x2ms_nn.dropout(self.y_deep,self.dropout_keep_deep[0])
  3. Modify lines 96 and 97 in the DCN.py file.

    Before the modification:

        x_l = tf.tensordot(tf.matmul(self._x0, x_l, transpose_b=True),
                            self.weights["cross_layer_%d" % l],1) + self.weights["cross_bias_%d" % l] + x_l

    After the modification:

        x_l = self.weights["cross_bias_%d" % l] + tf.tensordot(tf.matmul(self._x0, x_l, transpose_b=True),
                            self.weights["cross_layer_%d" % l],1) + x_l
  4. Comment out line 142 in the DCN.py file.
    #self.sess.run(init)
  5. Modify line 150 in the DCN.py file.

    Before the modification:

    variable_parameters *= dim.value

    After the modification:

    variable_parameters *= dim

40

MLR5

  • Before the migration, download the adults dataset and copy the files in it to the ./Basic-MLR-Demo/data directory (manually create the data directory).
  • Before the migration, change m=2 in the mlr.py file to m=5, m=10, m=15, or m=20 based on the type of the running model.

41

MLR10

42

MLR15

43

MLR20

44

PNN

Before the migration, modify the PNN model as follows:

  1. Modify line 109 in the PNN.py file.

    Before the modification:

    self.y_deep = x2ms_nn.dropout(self.y_deep,self.dropout_keep_deep[i+1])

    After the modification:

    self.y_deep = x2ms_nn.dropout(self.y_deep,self.dropout_keep_deep[0])
  2. Comment out line 141 in the PNN.py file.
    #self.sess.run(init)
  3. Modify line 149 in the PNN.py file.

    Before the modification:

    variable_parameters *= dim.value

    After the modification:

    variable_parameters *= dim
  4. Modify line 100 in the main.py file.

    Before the modification:

    y_train_pnn, y_test_pnn = run_base_model_pnn(dfTrain, dfTest, folds, pnn_params)

    After the modification:

    run_base_model_pnn(dfTrain, dfTest, folds, pnn_params)

45

LeNet

https://github.com/Jackpopc/aiLearnNotes/tree/7069a705bbcbea1ac24

  • After the migration, download the MNIST dataset and save it to the directory where commands are executed. Decompress all .gz files in MNIST and delete the original .gz files.
  • If the network convergence is poor, decrease the learning rate (LR) and increase the training epochs (EPOCHS).

46

AlexNet

47

ResNet-18

https://github.com/taki0112/ResNet-Tensorflow/tree/f395de3a53d

Before the migration, install the jedi dependency.

After the migration, perform the following adaptation:

  • After the load() API is migrated, use the data_dir parameter to specify the dataset path or place the required dataset in the default path.
    • ~/x2ms_datasets/cifar100/cifar-100-python
    • ~/x2ms_datasets/cifar10/cifar-10-batches-py
    • ~/x2ms_datasets/mnist.npz
    • ~/x2ms_datasets/fashion-mnist
  • MindSpore does not support the test of a large amount of data at a time.
    • You need to modify the code to test the test dataset in batches.
    • Change the first dimension of the shape of placeholders in the test dataset to 1.

48

ResNet-34

49

ResNet-50

50

ResNet-101

51

ResNet-152