Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Update sgd_solver for LARS #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/caffe/solvers/sgd_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,13 @@ void SGDSolver<Dtype>::ApplyUpdate(int param_id) {

LOG_PARAM_BLOB(this->net_->learnable_params()[param_id], diff, param_id, "ApplyUpdate: delwt after Normalize:");

Regularize(param_id);

LOG_PARAM_BLOB(this->net_->learnable_params()[param_id], diff, param_id, "ApplyUpdate: delwt after Regularize:");
//In original intel-caffe code, only SGD(Not NESTEROV, ADAGRAD, RMSPROP, ADADELTA, ADAM) adapted LARS. So, we change only the flow of SGD.
//We execute Regularize process after GetLocalRate(LARS) when solver_type is "SGD".
if (this->param_.type().compare("SGD") != 0)
{
Regularize(param_id);
LOG_PARAM_BLOB(this->net_->learnable_params()[param_id], diff, param_id, "ApplyUpdate: delwt after Regularize:");
}

ComputeUpdateValue(param_id, rate);

Expand Down Expand Up @@ -413,7 +417,6 @@ void SGDSolver<Dtype>::SGDFusion(int param_id, Dtype rate) {

//ComputeUpdateValue initialization
Dtype momentum = this->param_.momentum();
Dtype local_rate = rate * GetLocalRate(param_id);
//#pragma endregion

//#pragma region 2. Common condition judgement
Expand Down Expand Up @@ -451,7 +454,10 @@ void SGDSolver<Dtype>::SGDFusion(int param_id, Dtype rate) {
net_params[param_id]->mutable_cpu_diff());
}
}

//#pragma endregion
//execute GetLocalRate(LARS) after Normalize stage
Dtype local_rate = rate * GetLocalRate(param_id);

//For most common topologies from BVLC, all skipped the Normalize stage, and use L2 regularization
//If prv_diff_condition_flag == true, then prv_data_condition_flag == true (1)
Expand Down Expand Up @@ -672,7 +678,8 @@ void SGDSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {
const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();
Dtype momentum = this->param_.momentum();
Dtype local_rate = rate * GetLocalRate(param_id);

Regularize(param_id);
LOG_PARAM_BLOB(this->net_->learnable_params()[param_id], diff, param_id, "ApplyUpdate: delwt after Regularize:");
if (this->param_.warmup_iter() > 0 &&
this->iter_ < this->param_.warmup_iter()) {
// Momentum correction during warmup stage
Expand Down