As an alternative, Chainer provides an evaluation mode of forward computation which does not store the computation history.
This is enabled by just passing
Single-GPU usage is very simple. What you have to do is transferring
model = FunctionSet( l1 = F.Linear(784, 100), l2 = F.Linear(100, 100), l3 = F.Linear(100, 10), ).to_gpu() optimizer = optimizers.SGD() optimizer.setup(model)
Note that this method returns the
Then, all we have to do is transferring each minibatch to the GPU:
batchsize = 100 datasize = len(x_train) for epoch in range(20): print('epoch %d' % epoch) indexes = np.random.permutation(datasize) for i in range(0, datasize, batchsize): x_batch = cuda.to_gpu(x_train[indexes[i : i + batchsize]]) y_batch = cuda.to_gpu(y_train[indexes[i : i + batchsize]]) optimizer.zero_grads() loss, accuracy = forward(x_batch, y_batch) loss.backward() optimizer.update()
This is almost identical to the code of the original example,
we just inserted a call to the
When you call a function with an invalid type of array, you sometimes receive no error, but get an unexpected result by broadcasting. When you use CUDA with an illegal type of array, it causes memory corruption, and you get a serious error. These bugs are hard to fix
Each implementation of
def check_type_forward(self, in_types):
When a function gets volatile variables as its inputs, the output variables do not hold references to the function. This acts like unchaining on every function application.
Artificial Intelligence + NLP + deep learning > AI > Machine Learning > Neural Networks > Deep Learning > python >