mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Low efficiency of variable lstm

Open feiyulv opened this issue 10 years ago • 16 comments

The gpu utilization of variable lstm is very low and unstable, it seems symbol construction causes this low efficiency. We don't use bucket strategy, so sym_gen is called every batch. 1 The blank between batches is very huge which cause gpu utilization to 0. And the cudamemset (green part) costs most of the compute time. So how to eliminate the blank between computations, and reduce the cudamemset times?

feiyulv avatar Sep 01 '16 02:09 feiyulv

It costs little on creating a new executor, the blank seemed to caused by the hot start of the new exectutor's first execution. Is there any way to avoid this? @tqchen

feiyulv avatar Sep 01 '16 07:09 feiyulv

@feiyulv Is it possible to share the executors?

sxjscience avatar Sep 01 '16 09:09 sxjscience

@sxjscience I use the executor_mangager api, different executors can share the same memory, but the operators and other resources are reconstructed. The phenomenon is very strange. Since the fully cnn also create a new executor every iteration, but it doesn't hurt the speed as I observed. For test, I use the same length in lstm for each batch, just create a new executor sharing memory with the previous, the speed still drops.

feiyulv avatar Sep 01 '16 11:09 feiyulv

Maybe because RNNs with long sequences are much larger graphs than a typical CNN. Graph construction speed should be improved once nnvm is in place.

pluskid avatar Sep 01 '16 20:09 pluskid

@pluskid The length does influence the speed, however construction is insiginifciant. I construct new executor each batch, but use the default executor to do forward/backward, the gpu utilization won't drop.(For test, the sentence length is the same). It seems the hot start of the new executor causes the drop of speed

feiyulv avatar Sep 02 '16 00:09 feiyulv

@feiyulv Could you get an example that uses dummy data to help us reproduce the behavior?

sxjscience avatar Sep 02 '16 03:09 sxjscience

@sxjscience You can reproduce this result with the rnn example.

  1. modify ltm_bucketing.py: set buckets=[100], batch_size=8 run lstm_bucketing.py, gpu utilization is about 80%
  2. modify python/mxnet/executor_manager.py
    def load_data_batch(self, data_batch):
        """ load data and labels into arrays """
        if self.sym_gen is not None:
            key = data_batch.bucket_key
            if key not in self.execgrp_bucket:
                # create new bucket entry
                symbol = self.sym_gen(key)
                execgrp = DataParallelExecutorGroup(symbol, self.arg_names,
                                                    self.param_names, self.ctx,
                                                    self.slices, data_batch,
                                                    shared_group=self.execgrp)
                self.execgrp_bucket[key] = execgrp

            self.curr_execgrp = self.execgrp_bucket[key]
        else:
           # added for test 
            self.execgrp = DataParallelExecutorGroup(self.symbol, self.arg_names,
                                                    self.param_names, self.ctx,
                                                    self.slices, data_batch,
                                                    shared_group=self.execgrp)
            self.curr_execgrp = self.execgrp

run lstm_bucketing.py again, gpu utilization and speed will drop

feiyulv avatar Sep 02 '16 07:09 feiyulv

The drop of efficiency was caused by two aspects:

  1. The construction of new graph
  2. The destruction of previous executor, since I bind a new executor for each iteration @pluskid Is NNVM support the on-the-fly graph construction now?

feiyulv avatar Oct 10 '16 11:10 feiyulv

nnvm will be merged into master soon (after v0.8 release). The semantics and APIs for graph construction will be similar, but should be faster. You can probably test the mxnet/nnvm branch directly or wait a bit until it merges into the master.

pluskid avatar Oct 10 '16 14:10 pluskid

@pluskid Thx for your reply. I tried the nnvm branch, but got no improvement in speed. Both are around 1150 samples/s. And the new api gpu memory is about 10 times bigger(8692M vs 962M). I think the construction and destruction time of graph can be hidden by some asynchronous methods. For example , we can construct a new graph, while training process of the last batch is not finished.

feiyulv avatar Oct 12 '16 07:10 feiyulv

Hi @feiyulv , I also observed the low efficiency of RNN, which includes low speed and unstable GPU util. I thought that it is because a new graph is always created for a new batch. But after checking the code, it seems that DataParallelExecutorManager will not create a new graph for a seen length key and I am getting more confused.

@pluskid Any idea about this issue? I tried several times to sell mxnet to others, however, for the current performance on RNN, it might be less convincing to encourage NLP people to use it.

magic282 avatar Oct 12 '16 08:10 magic282

@magic282 If you use the bucket, the gpu util will be unstable at the beginning, but after all the buckets are constructed, gpu util will be stable. In my case, I do't use bucket key, and create a new symbol for each batch. You can try the new nnvm, it will be faster. Bucket is a little ugly, it forces more padding, and has to calculate bucket keys and bucket size for different dataset. @pluskid The result I provided yesterday was wrong, nnvm is really faster than the original mxnet for variable length lstm(1400 vs 1150), but the gpu util is still unstable. I check the code in model.py, the forward and backward caller of executor is asynchronous, so theoretically the time of symbol construction/destruction can be overlapped by training. The drop of gpu util may be caused by the construction/destruction time is too long to be hidden. Is that possible to support dynamical graph construction as theano? Like @magic282 I met the same problem when spreading the use of mxnet in my colleagues.

feiyulv avatar Oct 13 '16 01:10 feiyulv

@feiyulv I did use buckets. But I still observed unstable GPU util for entire training phase.

magic282 avatar Oct 13 '16 02:10 magic282

@magic282 different length may also cause the fluctuation of gpu util. You can check the log, the speed at the beginning is lower than the speed when all buckets are constructed.

feiyulv avatar Oct 13 '16 05:10 feiyulv

@feiyulv I just noticed that @pluskid updated a time-major batch for RNN. I just realized maybe the poor performance is due to the batch-major indexing.

magic282 avatar Oct 14 '16 06:10 magic282

This issue is closed due to lack of activity in the last 90 days. Feel free to reopen if this is still an active issue. Thanks!

yajiedesign avatar Sep 28 '17 06:09 yajiedesign