PaddlePaddle / models

Officially maintained, supported by PaddlePaddle, including CV, NLP, Speech, Rec, TS, big models and so on.
Apache License 2.0
6.92k stars 2.91k forks source link

使用DGC训练ResNet50出现NAN #3145

Open listenlink opened 5 years ago

listenlink commented 5 years ago

训练脚本如下:

#!/bin/bash
set -e

enable_dgc=True

while true ; do
  case "$1" in
    -enable_dgc) enable_dgc="$2" ; shift 2 ;;
    *)
       if [[ ${#1} > 0 ]]; then
          echo "not supported arugments ${1}" ; exit 1 ;
       else
           break
       fi
       ;;
  esac
done

case "${enable_dgc}" in
    True) ;;
    False) ;;
    *) echo "not support argument -enable_dgc: ${dgc}" ; exit 1 ;;
esac

export MODEL="DistResNet"
export PADDLE_TRAINER_ENDPOINTS="127.0.0.1:7160,127.0.0.1:7161,127.0.0.1:7162,127.0.0.1:7163,127.0.0.1:7164,127.0.0.1:7165,127.0.0.1:7166,127.0.0.1:7167"
# PADDLE_TRAINERS_NUM is used only for reader when nccl2 mode
export PADDLE_TRAINERS_NUM="8"

mkdir -p logs

# NOTE: set NCCL_P2P_DISABLE so that can run nccl2 distribute train on one node.

# You can set vlog to see more details' log.
# export GLOG_v=1
# export GLOG_logtostderr=1

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7160" \
PADDLE_TRAINER_ID="0" \
CUDA_VISIBLE_DEVICES="0" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg --update_method nccl2 --batch_size 32   &> logs/tr0.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7161" \
PADDLE_TRAINER_ID="1" \
CUDA_VISIBLE_DEVICES="1" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr1.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7162" \
PADDLE_TRAINER_ID="2" \
CUDA_VISIBLE_DEVICES="2" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125  --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr2.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7163" \
PADDLE_TRAINER_ID="3" \
CUDA_VISIBLE_DEVICES="3" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr3.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7164" \
PADDLE_TRAINER_ID="4" \
CUDA_VISIBLE_DEVICES="4" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr4.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7165" \
PADDLE_TRAINER_ID="5" \
CUDA_VISIBLE_DEVICES="5" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr5.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7166" \
PADDLE_TRAINER_ID="6" \
CUDA_VISIBLE_DEVICES="6" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr6.log &

PADDLE_TRAINING_ROLE="TRAINER" \
PADDLE_CURRENT_ENDPOINT="127.0.0.1:7167" \
PADDLE_TRAINER_ID="7" \
CUDA_VISIBLE_DEVICES="7" \
NCCL_P2P_DISABLE="1" \
python -u dist_train.py --enable_dgc ${enable_dgc} --lr 0.0125 --model $MODEL --data_dir /data/imagenet-jpeg/ --update_method nccl2 --batch_size 32  &> logs/tr7.log &
shippingwang commented 5 years ago

分布式训练可以参考下 PaddlePaddle/Fleet 分类中已经移除dist代码

listenlink commented 5 years ago

@shippingwang 是这份代码吗 https://github.com/PaddlePaddle/Fleet/tree/develop/benchmark/collective/resnet, 这份代码怎么开启DGC模式呢?

listenlink commented 5 years ago

@shippingwang dist代码单机8卡fp32可以跑,但是增加了enable_dgc 参数就出现了nan,这份带dgc的参考代码是否已经通过了精度验证?或者有其他可用的dgc 做resnet训练的参考代码?

wangxicoding commented 5 years ago

现在nan的问题已经修好了,还有些流程上的问题在修。这个PR跑DGC应该没啥问题了https://github.com/PaddlePaddle/Paddle/pull/20758

wangxicoding commented 5 years ago

@listenlink 抱歉现在develop分支还有个小问题,fuse模式下DGC会失效,需要关闭fuse dist_strategy.fuse_all_reduce_ops = False,之后会进行相应的修复