forked from huawei/mindspore2022
commit
74dfd46856
|
|
@ -94,14 +94,20 @@ After installing MindSpore via the official website, you can start training and
|
|||
#run data process
|
||||
bash scripts/run_download_dataset.sh
|
||||
|
||||
# run training example
|
||||
# run training example on Ascend
|
||||
bash scripts/run_train.sh
|
||||
|
||||
# run training example on GPU
|
||||
bash scripts/run_train_gpu.sh
|
||||
|
||||
# run distributed training example
|
||||
bash scripts/run_train.sh rank_table.json
|
||||
|
||||
# run evaluation example
|
||||
# run evaluation example on Ascend
|
||||
bash run_eval.sh
|
||||
|
||||
# run evaluation example on GPU
|
||||
bash run_eval_gpu.sh
|
||||
```
|
||||
|
||||
If you want to run in modelarts, please check the official documentation of [modelarts](https://support.huaweicloud.com/modelarts/), and you can start training and evaluation as follows:
|
||||
|
|
@ -158,9 +164,11 @@ If you want to run in modelarts, please check the official documentation of [mod
|
|||
│ ├──ascend_distributed_launcher
|
||||
│ ├──__init__.py // init file
|
||||
│ ├──get_distribute_pretrain_cmd.py // create distribute shell script
|
||||
│ ├──run_train.sh // shell script for train
|
||||
│ ├──run_train.sh // shell script for train on Ascend
|
||||
│ ├──run_distribute_train.sh // shell script for distribute train
|
||||
│ ├──run_eval.sh // shell script for evaluation
|
||||
│ ├──run_eval.sh // shell script for evaluation on Ascend
|
||||
│ ├──run_train_gpu.sh // shell script for train on GPU
|
||||
│ ├──run_eval_gpu.sh // shell script for evaluation on GPU
|
||||
│ ├──run_download_dataset.sh // shell script for dataget and process
|
||||
│ ├──run_transfer_ckpt_to_air.sh // shell script for transfer model style
|
||||
├── src
|
||||
|
|
@ -204,10 +212,18 @@ Parameters for both training and evaluation can be set in config.py.
|
|||
|
||||
### Training
|
||||
|
||||
- on Ascend
|
||||
|
||||
```python
|
||||
bash scripts/run_train.sh
|
||||
```
|
||||
|
||||
- on GPU
|
||||
|
||||
```python
|
||||
bash scripts/run_train_gpu.sh
|
||||
```
|
||||
|
||||
The python command above will run in the background, you can view the results through the file `train.log`. After training, you'll get some checkpoint files under the script folder by default. The loss value will be achieved as follows:
|
||||
|
||||
```python
|
||||
|
|
@ -240,6 +256,14 @@ Parameters for both training and evaluation can be set in config.py.
|
|||
HR:0.6846,NDCG:0.410
|
||||
```
|
||||
|
||||
- evaluation on ml-1m dataset when running on GPU
|
||||
|
||||
For details, see the above contents `evaluation on ml-1m dataset when running on Ascend`.
|
||||
|
||||
```python
|
||||
bash scripts/run_eval_gpu.sh
|
||||
```
|
||||
|
||||
## Inference Process
|
||||
|
||||
### [Export MindIR](#contents)
|
||||
|
|
@ -277,19 +301,19 @@ Inference result is saved in current path, you can find result like this in acc.
|
|||
|
||||
### Evaluation Performance
|
||||
|
||||
| Parameters | Ascend |
|
||||
| -------------------------- | ------------------------------------------------------------ |
|
||||
| Model Version | NCF |
|
||||
| Resource | Ascend 910; CPU 2.60GHz, 56cores; Memory 314G; OS Euler2.8 |
|
||||
| uploaded Date | 10/23/2020 (month/day/year) |
|
||||
| MindSpore Version | 1.0.0 |
|
||||
| Dataset | ml-1m |
|
||||
| Training Parameters | epoch=25, steps=19418, batch_size = 256, lr=0.00382059 |
|
||||
| Optimizer | GradOperation |
|
||||
| Loss Function | Softmax Cross Entropy |
|
||||
| outputs | probability |
|
||||
| Speed | 1pc: 0.575 ms/step |
|
||||
| Total time | 1pc: 5 mins |
|
||||
| Parameters | Ascend | GPU |
|
||||
| -------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| Model Version | NCF | NCF |
|
||||
| Resource | Ascend 910; CPU 2.60GHz, 56cores; Memory 314G; OS Euler2.8 | NV SMX2 V100-32G |
|
||||
| uploaded Date | 10/23/2020 (month/day/year) | 08/28/2021 (month/day/year) |
|
||||
| MindSpore Version | 1.0.0 | 1.4.0 |
|
||||
| Dataset | ml-1m | ml-1m |
|
||||
| Training Parameters | epoch=25, steps=19418, batch_size = 256, lr=0.00382059 | epoch=25, steps=19418, batch_size = 256, lr=0.00382059 |
|
||||
| Optimizer | GradOperation | GradOperation |
|
||||
| Loss Function | Softmax Cross Entropy | Softmax Cross Entropy |
|
||||
| outputs | probability | probability |
|
||||
| Speed | 1pc: 0.575 ms/step | 1pc: 2.5 ms/step |
|
||||
| Total time | 1pc: 5 mins | 1pc: 25 mins |
|
||||
|
||||
### Inference Performance
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -38,7 +38,7 @@ def run_eval():
|
|||
os.makedirs(config.output_path)
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE,
|
||||
device_target="Davinci",
|
||||
device_target=config.device_target,
|
||||
save_graphs=False,
|
||||
device_id=get_device_id())
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
echo "Please run the script as: "
|
||||
echo "bash scripts/run_eval_gpu.sh DATASET_PATH CKPT_FILE DEVICE_ID"
|
||||
echo "for example: bash scripts/run_eval_gpu.sh /dataset_path NCF-25_19418.ckpt 0"
|
||||
|
||||
data_path=$1
|
||||
ckpt_file=$2
|
||||
export CUDA_VISIBLE_DEVICES=$3
|
||||
python ./eval.py --data_path $data_path --dataset 'ml-1m' --eval_batch_size 160000 --output_path './output/' --eval_file_name 'eval.log' --checkpoint_file_path $ckpt_file --device_target=GPU --device_id=0
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
echo "Please run the script as: "
|
||||
echo "bash scripts/run_train_gpu.sh DATASET_PATH CKPT_FILE DEVICE_ID"
|
||||
echo "for example: bash scripts/run_train_gpu.sh /dataset_path /ncf.ckpt 0"
|
||||
|
||||
data_path=$1
|
||||
ckpt_file=$2
|
||||
export CUDA_VISIBLE_DEVICES=$3
|
||||
python ./train.py --data_path $data_path --dataset 'ml-1m' --train_epochs 25 --batch_size 256 --output_path './output/' --checkpoint_path $ckpt_file --device_target=GPU --device_id=0
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -63,14 +63,19 @@ class DenseLayer(nn.Cell):
|
|||
|
||||
self.activation = get_activation(activation)
|
||||
self.activation_flag = self.activation is not None
|
||||
self.is_ascend = context.get_context("device_target") == "Ascend"
|
||||
|
||||
def construct(self, x):
|
||||
"""
|
||||
dense layer construct method
|
||||
"""
|
||||
x = self.cast(x, mstype.float16)
|
||||
weight = self.cast(self.weight, mstype.float16)
|
||||
bias = self.cast(self.bias, mstype.float16)
|
||||
if self.is_ascend:
|
||||
x = self.cast(x, mstype.float16)
|
||||
weight = self.cast(self.weight, mstype.float16)
|
||||
bias = self.cast(self.bias, mstype.float16)
|
||||
else:
|
||||
weight = self.weight
|
||||
bias = self.bias
|
||||
|
||||
output = self.matmul(x, weight)
|
||||
if self.has_bias:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -79,8 +79,12 @@ def run_train():
|
|||
mlp_reg_layers=[0.0, 0.0, 0.0, 0.0],
|
||||
mf_dim=16)
|
||||
loss_net = NetWithLossClass(ncf_net)
|
||||
train_net = TrainStepWrap(loss_net, ds_train.get_dataset_size() * (epochs + 1))
|
||||
if config.device_target == "Ascend":
|
||||
loss_scale = 16384.0
|
||||
else:
|
||||
loss_scale = 1.0
|
||||
|
||||
train_net = TrainStepWrap(loss_net, ds_train.get_dataset_size() * (epochs + 1), sens=loss_scale)
|
||||
train_net.set_train()
|
||||
|
||||
model = Model(train_net)
|
||||
|
|
|
|||
Loading…
Reference in New Issue