mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Batch/epoch number ambiguity in GPU/CPU cluster

Open mcxkarakoc opened this issue 9 years ago • 1 comments

I have such a code below.

mon = mx.mon.Monitor(1, stat_func=self.mean_abs, pattern='.*', sort=True);
modSolver = mx.mod.Module(self.stacks[i], context=[mx.gpu(0), mx.gpu(1), mx.gpu(2)])
modSolver.fit(data_iter_i,
                              kvstore=self.opts.kv,
                              optimizer=self.opts.ptOptimizer,
                              eval_metric=mx.metric.CustomMetric(self.opts.metric),
                              monitor=mon,
                              initializer=mx.initializer.Uniform(0.07),
                              num_epoch=self.opts.ptEpochs,
                              eval_batch_end_callback=self.evalBatchEnd, 
                              batch_end_callback=self.batchEnd,
                              epoch_end_callback=self.epochEnd)

I'm confused a little bit. In each call of self.batchEnd, all of parameters are printed 3 times like below:

Batch:       2 activation0_backward_data      3.29612e-06	
Batch:       2 activation0_backward_data      3.29322e-06	
Batch:       2 activation0_backward_data      3.26509e-06

This would be okay if self.batchEnd in 3 GPU clusters was called by 1/3 of self.batchEnd in 1 GPU. However, even if GPU count is 1, 2, 3 or more, the number of self.batchEnd calls is the same. I've confirmed this situation by watching when self.epochEnd is called. After the last self.batchEnd call, self.epochEnd is called.

Another option would be to share the same batch by GPU cluster. However, in that case, GPU cluster does not have any advantage over single GPU since single batch in 1 GPU takes 4 seconds but the single batch in 3 GPU takes 5.6 seconds

So could you clarify this point? If I use n GPU(s), each epoch in n GPU(s) contains n epochs in single GPU. Is it true?

Off-topic: Let's assume I have a PC with 2 CPUs. Is there any difference between context=[mx.cpu()] and context=[mx.cpu(0), mx.cpu(1)] in terms of time efficiency ? To my calculations and understandings from your help documentation, they are the same.

mcxkarakoc avatar Mar 11 '17 16:03 mcxkarakoc

Let me reply my own questions :)

  1. If there are multi GPUs, they take their slices from the batch according to work load list. For example, If work load list is [2 3 1], GPU 0 takes 2/6 of the batch, GPU 1 takes 3/6 of the batch and GPU 2 takes 1/6 of the batch in terms of the number of examples in the batch. The stats misleaded me since the batch size was very low comparing to the capacity of GPUs. After increasing the batch size, the speed results have become more consistent and reasonable.

  2. For multi-CPU case, in contrast to my claim in the question, there is a difference between single and two CPUs. However, the difference does not seem meaningful to me. I gave up deeper examination since I've decided not to use CPUs which are 5x-10x slower than GPUs.

mcxkarakoc avatar Mar 16 '17 15:03 mcxkarakoc