clab / clab/dynet

autobatch is 10 times slower than manual batching?

Open
#1,038 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.4k
Forks
701
PR merge metrics
No merged PRs in 30d

Description

I am trying autobatch in mnist example as below:
#if 0 //Manual Mini-batching
for (unsigned idx = 0; idx < bsize; ++idx) {
cur_batch[idx] = input(cg, {N_INPUT}, mnist_train[id + idx]);
cur_labels[idx] = mnist_train_labels[id + idx];
}

// Reshape as batch (not very intuitive yet)
Expression x_batch = reshape(concatenate_cols(cur_batch), Dim({N_INPUT}, bsize));
Expression loss_expr = nn.get_nll(x_batch, cur_labels, cg); // Get negative log likelihood on batch
#else //Automatic Mini-batching
vector lossVec;
for (unsigned idx = 0; idx < bsize; ++idx) {
cur_batch[idx] = input(cg, {N_INPUT}, mnist_train[id + idx]);
cur_labels[idx] = mnist_train_labels[id + idx];
Expression lossExpr = nn.get_nll(cur_batch[idx], cur_labels[idx], cg);
lossVec.push_back(lossExpr);
}
Expression loss_expr = sum(lossVec);
#endif
cg.forward(loss_expr);
loss += as_scalar(loss_expr.value()); // Get scalar error for monitoring
num_samples += bsize;
cg.backward(loss_expr); // Compute gradient with backward pass
trainer.update();

I did autobatch with --dynet-mem 1024 --dynet-autobatch 1 and run it on CPU

But the autobatch is 10 times slower than manual batching!
What had I done wrong?

Thanks a lot!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the MNIST example and compare the manual and automatic mini-batching paths shown in the issue on CPU using --dynet-mem 1024 --dynet-autobatch 1. Measure where the automatic path incurs its extra time and verify whether the reported slowdown is reproducible; done means identifying the cause and recording or applying the appropriate correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.