Skip to content

Commit

Permalink
Removed batch size division by number of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
cypof committed Jun 29, 2015
1 parent 9b10508 commit 6ea7f7d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
3 changes: 0 additions & 3 deletions include/caffe/parallel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class P2PSync : public GPUParams<Dtype>, public Solver<Dtype>::Callback,

static void run(shared_ptr<Solver<Dtype> > root, const vector<int>& gpus);

// Divide the batch size by the number of solvers
static void divide_batch_size(NetParameter* net);

protected:
void on_start(Timer* timer, ostringstream* timing);
void on_gradients_ready(Timer* timer, ostringstream* timing);
Expand Down
3 changes: 0 additions & 3 deletions src/caffe/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void Net<Dtype>::Init(const NetParameter& in_param) {
// the current NetState.
NetParameter filtered_param;
FilterNet(in_param, &filtered_param);
if (phase_ == TRAIN) {
caffe::P2PSync<Dtype>::divide_batch_size(&filtered_param);
}
if (Caffe::root_solver()) {
LOG(INFO) << "Initializing net from parameters: " << std::endl
<< filtered_param.DebugString();
Expand Down
56 changes: 0 additions & 56 deletions src/caffe/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,62 +435,6 @@ void P2PSync<Dtype>::run(shared_ptr<Solver<Dtype> > root,
}
}

template<typename Dtype>
void P2PSync<Dtype>::divide_batch_size(NetParameter* net) {
int solver_count = Caffe::solver_count();
for (int i = 0; i < net->layer_size(); ++i) {
string m = "Batch size must be divisible by the number of solvers (GPUs)";
if (net->layer(i).has_data_param()) {
if (net->layer(i).data_param().has_batch_size()) {
uint32_t total = net->layer(i).data_param().batch_size();
uint32_t batch = total / solver_count;
CHECK(batch * solver_count == total) << m;
net->mutable_layer(i)->mutable_data_param()->set_batch_size(batch);

// Also adjust the prefetch count, as it is shared by all solvers
uint32_t prefetch = net->layer(i).data_param().prefetch();
net->mutable_layer(i)->mutable_data_param()->set_prefetch(
prefetch * solver_count);
}
}
if (net->layer(i).has_hdf5_data_param()) {
if (net->layer(i).hdf5_data_param().has_batch_size()) {
uint32_t total = net->layer(i).hdf5_data_param().batch_size();
uint32_t batch = total / solver_count;
CHECK(batch * solver_count == total) << m;
net->mutable_layer(i)->mutable_hdf5_data_param()->set_batch_size(batch);
}
}
if (net->layer(i).has_image_data_param()) {
if (net->layer(i).image_data_param().has_batch_size()) {
uint32_t total = net->layer(i).image_data_param().batch_size();
uint32_t batch = total / solver_count;
CHECK(batch * solver_count == total) << m;
net->mutable_layer(i)->mutable_image_data_param()->set_batch_size(
batch);
}
}
if (net->layer(i).has_memory_data_param()) {
if (net->layer(i).memory_data_param().has_batch_size()) {
uint32_t total = net->layer(i).memory_data_param().batch_size();
uint32_t batch = total / solver_count;
CHECK(batch * solver_count == total) << m;
net->mutable_layer(i)->mutable_memory_data_param()->set_batch_size(
batch);
}
}
if (net->layer(i).has_window_data_param()) {
if (net->layer(i).window_data_param().has_batch_size()) {
uint32_t total = net->layer(i).window_data_param().batch_size();
uint32_t batch = total / solver_count;
CHECK(batch * solver_count == total) << m;
net->mutable_layer(i)->mutable_window_data_param()->set_batch_size(
batch);
}
}
}
}

INSTANTIATE_CLASS(Params);
INSTANTIATE_CLASS(GPUParams);
INSTANTIATE_CLASS(P2PSync);
Expand Down
3 changes: 2 additions & 1 deletion tools/caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ using std::ostringstream;

DEFINE_string(gpu, "",
"Optional; run in GPU mode on given device IDs separated by ','."
"Use '-gpu all' to run on all available GPUs.");
"Use '-gpu all' to run on all available GPUs. The effective training "
"batch size is multiplied by the number of devices.");
DEFINE_string(solver, "",
"The solver definition protocol buffer text file.");
DEFINE_string(model, "",
Expand Down

0 comments on commit 6ea7f7d

Please sign in to comment.