mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Synchronized Batch normalization in multi GPUs training

Open cccorn opened this issue 9 years ago • 19 comments

I found that Batch Norm dose not synchronize the mean and variance through multi-GPUs in training phase.But I want to train ResNet using big image, so i can only use a small batch in each device. I think it is not appropriate to use Batch Norm when the batch size is too small (5 images). Is there any way to easily solve this problem?

cccorn avatar Oct 28 '17 06:10 cccorn

Also need the Synchronized Batch normalization!!!!1

Yezipiaomu avatar Oct 29 '17 03:10 Yezipiaomu

@tqchen @pluskid @mli

Yezipiaomu avatar Oct 29 '17 06:10 Yezipiaomu

Actually all major framework does not synchronize mean and variance, since this will significantly slow down the training, if the cross bandwidth is low. That being said, i think this is a very useful feature. For semantic segmentation, especially reproducing PSPNet, synchronized batch norm is necessary.

Jerryzcn avatar Oct 30 '17 05:10 Jerryzcn

So, How to implement it ?! @Jerryzcn it seem that it's import for segmentation

Yezipiaomu avatar Oct 30 '17 06:10 Yezipiaomu

@Tommymhz I would suggest implement your own batchnorm in gluon, and sync across all gpus.

Jerryzcn avatar Oct 30 '17 06:10 Jerryzcn

However, My code are based on the symbol !!

Yezipiaomu avatar Oct 30 '17 07:10 Yezipiaomu

I need the Synchronized Batch normalization, too. My code is based on symbol. Any Suggestion?

zdwong avatar Dec 15 '17 06:12 zdwong

Could you share your code?

KeyKy avatar Dec 15 '17 09:12 KeyKy

@zhanghang1989

Jerryzcn avatar Dec 15 '17 23:12 Jerryzcn

There is no easy way to solve Sync BN. I have implemented it using PyTorch (http://hangzh.com/PyTorch-Encoding/notes/syncbn.html) by rewriting DataParallel and cross-GPU communication. I will implement MXNet Gluon version as well, probably release it early next year.

zhanghang1989 avatar Dec 16 '17 00:12 zhanghang1989

@zhanghang1989 : how about tensorflow. Could you also implement it? We are really need it in tensorflow

John1231983 avatar Jan 31 '18 13:01 John1231983

@John1231983 This repository is for MXNet and not tensor flow. Please refrain from requests regarding other frameworks.

marcoabreu avatar Jan 31 '18 15:01 marcoabreu

Hi, did someone implemented that yet?

oronanschel avatar Mar 19 '18 21:03 oronanschel

Implemented in PR https://github.com/apache/incubator-mxnet/pull/11502

zhanghang1989 avatar Mar 30 '18 02:03 zhanghang1989

@zhanghang1989 Thanks!

cccorn avatar Mar 30 '18 06:03 cccorn

@sandeep-krishnamurthy this issue can be closed now, thanks. further discussions should be on the PR https://github.com/apache/incubator-mxnet/pull/11502

thomelane avatar Jul 12 '18 18:07 thomelane

There is no easy way to solve Sync BN. I have implemented it using PyTorch (http://hangzh.com/PyTorch-Encoding/notes/syncbn.html) by rewriting DataParallel and cross-GPU communication. I will implement MXNet Gluon version as well, probably release it early next year.

HI Hang, I used your sync_bn implementation for mxnet symbol. However, it reduced the performance of my network. I wonder whether you have ever tried with symbol API with your sync_bn other than gluon. Thanks

pengwangucla avatar Apr 17 '19 03:04 pengwangucla

The SyncBN does reduce the speed due to synchronization for every BN layer during both forward and backward. Use it only when it is necessary, especially on computation intensive task such as semantic segmentation or object detection where the synchronization is not a huge bottleneck comparing to the computation.

zhanghang1989 avatar Apr 17 '19 03:04 zhanghang1989

The SyncBN does reduce the speed due to synchronization for every BN layer during both forward and backward. Use it only when it is necessary, especially on computation intensive task such as semantic segmentation or object detection where the synchronization is not a huge bottleneck comparing to the computation.

Thanks for the reply, I understand it reduces the speed as I observed, but it also reduces the accuracy from a pretrained se-net. I wonder whether you have tried it using symbol API ? Thanks

pengwangucla avatar Apr 21 '19 16:04 pengwangucla