You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_distribute_train.sh 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # Copyright 2020 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. if [ $# != 4 ] && [ $# != 5 ]
  17. then
  18. echo "Usage: sh run_distribute_train.sh [resnet50|resnet101] [cifar10|imagenet2012] [MINDSPORE_HCCL_CONFIG_PATH] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
  19. exit 1
  20. fi
  21. if [ $1 != "resnet50" ] && [ $1 != "resnet101" ]
  22. then
  23. echo "error: the selected net is neither resnet50 nor resnet101"
  24. exit 1
  25. fi
  26. if [ $2 != "cifar10" ] && [ $2 != "imagenet2012" ]
  27. then
  28. echo "error: the selected dataset is neither cifar10 nor imagenet2012"
  29. exit 1
  30. fi
  31. if [ $1 == "resnet101" ] && [ $2 == "cifar10" ]
  32. then
  33. echo "error: training resnet101 with cifar10 dataset is unsupported now!"
  34. exit 1
  35. fi
  36. get_real_path(){
  37. if [ "${1:0:1}" == "/" ]; then
  38. echo "$1"
  39. else
  40. echo "$(realpath -m $PWD/$1)"
  41. fi
  42. }
  43. PATH1=$(get_real_path $3)
  44. PATH2=$(get_real_path $4)
  45. if [ $# == 5 ]
  46. then
  47. PATH3=$(get_real_path $5)
  48. fi
  49. if [ ! -f $PATH1 ]
  50. then
  51. echo "error: MINDSPORE_HCCL_CONFIG_PATH=$PATH1 is not a file"
  52. exit 1
  53. fi
  54. if [ ! -d $PATH2 ]
  55. then
  56. echo "error: DATASET_PATH=$PATH2 is not a directory"
  57. exit 1
  58. fi
  59. if [ $# == 5 ] && [ ! -f $PATH3 ]
  60. then
  61. echo "error: PRETRAINED_CKPT_PATH=$PATH3 is not a file"
  62. exit 1
  63. fi
  64. ulimit -u unlimited
  65. export DEVICE_NUM=8
  66. export RANK_SIZE=8
  67. export MINDSPORE_HCCL_CONFIG_PATH=$PATH1
  68. export RANK_TABLE_FILE=$PATH1
  69. for((i=0; i<${DEVICE_NUM}; i++))
  70. do
  71. export DEVICE_ID=$i
  72. export RANK_ID=$i
  73. rm -rf ./train_parallel$i
  74. mkdir ./train_parallel$i
  75. cp ../*.py ./train_parallel$i
  76. cp *.sh ./train_parallel$i
  77. cp -r ../src ./train_parallel$i
  78. cd ./train_parallel$i || exit
  79. echo "start training for rank $RANK_ID, device $DEVICE_ID"
  80. env > env.log
  81. if [ $# == 4 ]
  82. then
  83. python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=$DEVICE_NUM --dataset_path=$PATH2 &> log &
  84. fi
  85. if [ $# == 5 ]
  86. then
  87. python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=$DEVICE_NUM --dataset_path=$PATH2 --pre_trained=$PATH3 &> log &
  88. fi
  89. cd ..
  90. done