How to calculate full gradient
I found there are codes to train whole data in one batch(gradient descent), could you tell me how to enable it?
if (IGradientMachineMode::trainWholeDataInOneBatch(mode_)) {
trainOnePassBatch(config_->getConfig().start_pass() + i);
} else {
...
@zuowang TrainWholeDataInOneBatch is only used for OWLQN method, which is not open sourced because this method is slow to optimize, and much worse than SGD with Adaptive Learning Method such as adagrad, adam, rmsprop in general. To support OWLQN will make multi-machine communication more complex.
But there are some legacy codes still in this repo.
Is trainWholeDataInOneBatch needed by you?
If you are trying to use batch gradient on the whole dataset, I suppose you could always set batch size to a number that is larger than your dataset size, if your dataset is small enough.
Just out of curiosity, what is your use case?
@zhouxiao-coder I want to use gradient descent. Is your amswer help on this use case?
@zuowang @zhouxiao-coder TrainWholeDataInOneBatch is not used for SGD or Async-SGD at all.
I want to use GD, that's train whole data to get gradient. Should zhouxiao-coder's answer help me?
@zuowang Currently, Paddle only support mini-batch SGD. If your data set is small, you could change batch_size to a very large number, and then Paddle will load all data in memory and calculate gradient in one batch. However, the memory consumption is very large. If your dataset is quite small, and can handle in your memory, zhouxiao-coder's answer is good.
To implement your idea, it should generally divide whole batch of data into many pieces. And calculate gradients for each pieces, then merge them together. And, THIS is not implement in Paddle C++ code right now. You can use Paddle swig API to compose it, but currently this part is lack of documentation.
But using gradient decent in whole batch is generally a bad idea. It will often slower than mini-batch training. So, could you tell us why do you want this feature? Is there some paper you want to implement? Or just have a try?
@reyoung I want to implement async-SVRG and see how it compared to mini-batch SGD

This optimization method saves lots of gradient copies. In my opinion, it is not good for Neural Network training, especially on GPU when memory is 4GB or 12GB.
The demo about how to calculate full gradient in Paddle swig will be added, but not be very soon. Because we should focus the nearest milestone now.
Thanks!