Tensorflow中的梯度重新包装是什么?

时间:2018-06-21 20:58:25

标签: tensorflow benchmarking

从终端运行tensorflow基准测试时,我们可以指定几个参数。有一个名为gradient_repacking的参数。它代表什么?如何设置它?

python tf_cnn_benchmarks.py --data_format=NCHW --batch_size=256 \
--model=resnet50 --optimizer=momentum --variable_update=replicated \
--nodistortions --gradient_repacking=8 --num_gpus=8 \
--num_epochs=90 --weight_decay=1e-4 --data_dir=${DATA_DIR} --use_fp16 \
--train_dir=${CKPT_DIR}

1 个答案:

答案 0 :(得分:1)

对于将来的搜索,gradient_repacking在复制模式下会影响全约。根据标志定义:

flags.DEFINE_integer('gradient_repacking', 0, 'Use gradient repacking. It'
                     'currently only works with replicated mode. At the end of'
                     'of each step, it repacks the gradients for more efficient'
                     'cross-device transportation. A non-zero value specifies'
                     'the number of split packs that will be formed.',
                     lower_bound=0)

关于最优,我已经看到gradient_repacking=8gradient_repacking=2一样。

我最好的猜测是该参数是指渐变被分解以供其他工作人员共享的碎片数量。在这种情况下,八个表示每个GPU彼此共享(即对所有num_gpus=8使用GPU),而两个则表示仅与邻居共享环形共享。

鉴于Horovod使用其自己的所有reduce算法,因此在gradient_repacking时设置--variable_update=horovod不起作用是有道理的。