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.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. echo "=============================================================================================================="
  17. echo "Please run the scipt as: "
  18. echo "bash run_distribute_train.sh MINDSPORE_HCCL_CONFIG_PATH DATA_PATH"
  19. echo "for example: bash run_distribute_train.sh MINDSPORE_HCCL_CONFIG_PATH DATA_PATH [PRETRAINED_CKPT_PATH](option)"
  20. echo "It is better to use absolute path."
  21. echo "=============================================================================================================="
  22. DATA_DIR=$2
  23. export MINDSPORE_HCCL_CONFIG_PATH=$1
  24. export RANK_TABLE_FILE=$1
  25. export RANK_SIZE=8
  26. PATH_CHECKPOINT=""
  27. if [ $# == 3 ]
  28. then
  29. PATH_CHECKPOINT=$3
  30. fi
  31. cores=`cat /proc/cpuinfo|grep "processor" |wc -l`
  32. echo "the number of logical core" $cores
  33. avg_core_per_rank=`expr $cores \/ $RANK_SIZE`
  34. core_gap=`expr $avg_core_per_rank \- 1`
  35. echo "avg_core_per_rank" $avg_core_per_rank
  36. echo "core_gap" $core_gap
  37. for((i=0;i<RANK_SIZE;i++))
  38. do
  39. start=`expr $i \* $avg_core_per_rank`
  40. export DEVICE_ID=$i
  41. export RANK_ID=$i
  42. export DEPLOY_MODE=0
  43. export GE_USE_STATIC_MEMORY=1
  44. end=`expr $start \+ $core_gap`
  45. cmdopt=$start"-"$end
  46. rm -rf LOG$i
  47. mkdir ./LOG$i
  48. cp *.py ./LOG$i
  49. cd ./LOG$i || exit
  50. echo "start training for rank $i, device $DEVICE_ID"
  51. mkdir -p ms_log
  52. CUR_DIR=`pwd`
  53. export GLOG_log_dir=${CUR_DIR}/ms_log
  54. export GLOG_logtostderr=0
  55. env > env.log
  56. taskset -c $cmdopt python ../train.py \
  57. --distribute="true" \
  58. --device_id=$DEVICE_ID \
  59. --checkpoint_url=$PATH_CHECKPOINT \
  60. --data_url=$DATA_DIR > log.txt 2>&1 &
  61. cd ../
  62. done