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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "sh run_distribute_train.sh DEVICE_NUM EPOCH_SIZE MINDRECORD_DIR IMAGE_DIR ANNO_PATH MINDSPORE_HCCL_CONFIG_PATH"
  19. echo "for example: sh run_distribute_train.sh 8 100 /data/Mindrecord_train /data /data/train.txt /data/hccl.json"
  20. echo "It is better to use absolute path."
  21. echo "The learning rate is 0.005 as default, if you want other lr, please change the value in this script."
  22. echo "=============================================================================================================="
  23. EPOCH_SIZE=$2
  24. MINDRECORD_DIR=$3
  25. IMAGE_DIR=$4
  26. ANNO_PATH=$5
  27. # Before start distribute train, first create mindrecord files.
  28. python train.py --only_create_dataset=1 --mindrecord_dir=$MINDRECORD_DIR --image_dir=$IMAGE_DIR \
  29. --anno_path=$ANNO_PATH
  30. echo "After running the scipt, the network runs in the background. The log will be generated in LOGx/log.txt"
  31. export MINDSPORE_HCCL_CONFIG_PATH=$6
  32. export RANK_SIZE=$1
  33. for((i=0;i<RANK_SIZE;i++))
  34. do
  35. export DEVICE_ID=$i
  36. start=`expr $i \* 12`
  37. end=`expr $start \+ 11`
  38. cmdopt=$start"-"$end
  39. rm -rf LOG$i
  40. mkdir ./LOG$i
  41. cp *.py ./LOG$i
  42. cd ./LOG$i || exit
  43. export RANK_ID=$i
  44. echo "start training for rank $i, device $DEVICE_ID"
  45. env > env.log
  46. taskset -c $cmdopt python ../train.py \
  47. --distribute=1 \
  48. --lr=0.005 \
  49. --device_num=$RANK_SIZE \
  50. --device_id=$DEVICE_ID \
  51. --mindrecord_dir=$MINDRECORD_DIR \
  52. --image_dir=$IMAGE_DIR \
  53. --epoch_size=$EPOCH_SIZE \
  54. --anno_path=$ANNO_PATH > log.txt 2>&1 &
  55. cd ../
  56. done