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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 MINDSPORE_HCCL_CONFIG_PATH"
  19. echo "for example: sh run_distribute_train.sh 8 150 coco /data/hccl.json"
  20. echo "It is better to use absolute path."
  21. echo "The learning rate is 0.4 as default, if you want other lr, please change the value in this script."
  22. echo "=============================================================================================================="
  23. # Before start distribute train, first create mindrecord files.
  24. python train.py --only_create_dataset=1
  25. echo "After running the scipt, the network runs in the background. The log will be generated in LOGx/log.txt"
  26. export RANK_SIZE=$1
  27. EPOCH_SIZE=$2
  28. DATASET=$3
  29. export MINDSPORE_HCCL_CONFIG_PATH=$4
  30. for((i=0;i<RANK_SIZE;i++))
  31. do
  32. export DEVICE_ID=$i
  33. rm -rf LOG$i
  34. mkdir ./LOG$i
  35. cp *.py ./LOG$i
  36. cd ./LOG$i || exit
  37. export RANK_ID=$i
  38. echo "start training for rank $i, device $DEVICE_ID"
  39. env > env.log
  40. python ../train.py \
  41. --distribute=1 \
  42. --lr=0.4 \
  43. --dataset=$DATASET \
  44. --device_num=$RANK_SIZE \
  45. --device_id=$DEVICE_ID \
  46. --epoch_size=$EPOCH_SIZE > log.txt 2>&1 &
  47. cd ../
  48. done