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_train.sh 2.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env 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. run_ascend()
  17. {
  18. if [ $2 -lt 1 ] && [ $2 -gt 8 ]
  19. then
  20. echo "error: DEVICE_NUM=$2 is not in (1-8)"
  21. exit 1
  22. fi
  23. if [ ! -d $5 ] && [ ! -f $5 ]
  24. then
  25. echo "error: DATASET_PATH=$5 is not a directory or file"
  26. exit 1
  27. fi
  28. BASEPATH=$(cd "`dirname $0`" || exit; pwd)
  29. export PYTHONPATH=${BASEPATH}:$PYTHONPATH
  30. export MINDSPORE_HCCL_CONFIG_PATH=$4
  31. export RANK_TABLE_FILE=$4
  32. if [ -d "../train" ];
  33. then
  34. rm -rf ../train
  35. fi
  36. mkdir ../train
  37. cd ../train || exit
  38. python ${BASEPATH}/../src/launch.py \
  39. --nproc_per_node=$2 \
  40. --visible_devices=$3 \
  41. --training_script=${BASEPATH}/../train.py \
  42. --dataset_path=$5 \
  43. --pre_trained=$6 \
  44. --platform=$1 &> ../train.log & # dataset train folder
  45. }
  46. run_gpu()
  47. {
  48. if [ $2 -lt 1 ] && [ $2 -gt 8 ]
  49. then
  50. echo "error: DEVICE_NUM=$2 is not in (1-8)"
  51. exit 1
  52. fi
  53. if [ ! -d $4 ]
  54. then
  55. echo "error: DATASET_PATH=$4 is not a directory"
  56. exit 1
  57. fi
  58. BASEPATH=$(cd "`dirname $0`" || exit; pwd)
  59. export PYTHONPATH=${BASEPATH}:$PYTHONPATH
  60. if [ -d "../train" ];
  61. then
  62. rm -rf ../train
  63. fi
  64. mkdir ../train
  65. cd ../train || exit
  66. export CUDA_VISIBLE_DEVICES="$3"
  67. mpirun -n $2 --allow-run-as-root \
  68. python ${BASEPATH}/../train.py \
  69. --dataset_path=$4 \
  70. --platform=$1 \
  71. &> ../train.log & # dataset train folder
  72. }
  73. if [ $# -gt 6 ] || [ $# -lt 4 ]
  74. then
  75. echo "Usage:\n \
  76. Ascend: sh run_train.sh Ascend [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [MINDSPORE_HCCL_CONFIG_PATH] [DATASET_PATH] [CKPT_PATH]\n \
  77. GPU: sh run_train.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH]\n \
  78. "
  79. exit 1
  80. fi
  81. if [ $1 = "Ascend" ] ; then
  82. run_ascend "$@"
  83. elif [ $1 = "GPU" ] ; then
  84. run_gpu "$@"
  85. else
  86. echo "not support platform"
  87. fi;