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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_pretrain.sh DEVICE_NUM EPOCH_SIZE DATA_DIR SCHEMA_DIR MINDSPORE_HCCL_CONFIG_PATH"
  19. echo "for example: bash run_distribute_pretrain.sh 8 40 /path/zh-wiki/ /path/Schema.json /path/hccl.json"
  20. echo "It is better to use absolute path."
  21. echo "=============================================================================================================="
  22. EPOCH_SIZE=$2
  23. DATA_DIR=$3
  24. SCHEMA_DIR=$4
  25. export MINDSPORE_HCCL_CONFIG_PATH=$5
  26. export RANK_TABLE_FILE=$5
  27. export RANK_SIZE=$1
  28. cores=`cat /proc/cpuinfo|grep "processor" |wc -l`
  29. echo "the number of logical core" $cores
  30. avg_core_per_rank=`expr $cores \/ $RANK_SIZE`
  31. core_gap=`expr $avg_core_per_rank \- 1`
  32. echo "avg_core_per_rank" $avg_core_per_rank
  33. echo "core_gap" $core_gap
  34. for((i=0;i<RANK_SIZE;i++))
  35. do
  36. start=`expr $i \* $avg_core_per_rank`
  37. export DEVICE_ID=$i
  38. export RANK_ID=$i
  39. export DEPLOY_MODE=0
  40. export GE_USE_STATIC_MEMORY=1
  41. end=`expr $start \+ $core_gap`
  42. cmdopt=$start"-"$end
  43. rm -rf LOG$i
  44. mkdir ./LOG$i
  45. cp *.py ./LOG$i
  46. cd ./LOG$i || exit
  47. echo "start training for rank $i, device $DEVICE_ID"
  48. mkdir -p ms_log
  49. CUR_DIR=`pwd`
  50. export GLOG_log_dir=${CUR_DIR}/ms_log
  51. export GLOG_logtostderr=0
  52. env > env.log
  53. taskset -c $cmdopt python ../run_pretrain.py \
  54. --distribute="true" \
  55. --epoch_size=$EPOCH_SIZE \
  56. --device_id=$DEVICE_ID \
  57. --device_num=$RANK_SIZE \
  58. --enable_save_ckpt="true" \
  59. --enable_lossscale="true" \
  60. --do_shuffle="true" \
  61. --enable_data_sink="true" \
  62. --data_sink_steps=100 \
  63. --load_checkpoint_path="" \
  64. --save_checkpoint_steps=10000 \
  65. --save_checkpoint_num=1 \
  66. --data_dir=$DATA_DIR \
  67. --schema_dir=$SCHEMA_DIR > log.txt 2>&1 &
  68. cd ../
  69. done