MCPcopy Create free account
hub / github.com/BVLC/caffe / ComputeUpdateValue

Method ComputeUpdateValue

src/caffe/solvers/rmsprop_solver.cpp:14–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13template <typename Dtype>
14void RMSPropSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {
15 const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();
16 const vector<float>& net_params_lr = this->net_->params_lr();
17
18 // get the learning rate
19 Dtype delta = this->param_.delta();
20 Dtype rms_decay = this->param_.rms_decay();
21 Dtype local_rate = rate * net_params_lr[param_id];
22
23 switch (Caffe::mode()) {
24 case Caffe::CPU:
25 // compute square of gradient in update
26 caffe_powx(net_params[param_id]->count(),
27 net_params[param_id]->cpu_diff(), Dtype(2),
28 this->update_[param_id]->mutable_cpu_data());
29
30 // update history
31 caffe_cpu_axpby(net_params[param_id] -> count(),
32 Dtype(1-rms_decay), this->update_[param_id]->cpu_data(),
33 rms_decay, this->history_[param_id]-> mutable_cpu_data());
34
35 // prepare update
36 caffe_powx(net_params[param_id]->count(),
37 this->history_[param_id]->cpu_data(), Dtype(0.5),
38 this->update_[param_id]->mutable_cpu_data());
39
40 caffe_add_scalar(net_params[param_id]->count(),
41 delta, this->update_[param_id]->mutable_cpu_data());
42
43 caffe_div(net_params[param_id]->count(),
44 net_params[param_id]->cpu_diff(), this->update_[param_id]->cpu_data(),
45 this->update_[param_id]->mutable_cpu_data());
46
47 // scale and copy
48 caffe_cpu_axpby(net_params[param_id]->count(), local_rate,
49 this->update_[param_id]->cpu_data(), Dtype(0),
50 net_params[param_id]->mutable_cpu_diff());
51 break;
52 case Caffe::GPU:
53#ifndef CPU_ONLY
54 rmsprop_update_gpu(net_params[param_id]->count(),
55 net_params[param_id]->mutable_gpu_diff(),
56 this->history_[param_id]->mutable_gpu_data(),
57 rms_decay, delta, local_rate);
58#else
59 NO_GPU;
60#endif
61 break;
62 default:
63 LOG(FATAL) << "Unknown caffe mode: " << Caffe::mode();
64 }
65}
66
67INSTANTIATE_CLASS(RMSPropSolver);
68REGISTER_SOLVER_CLASS(RMSProp);

Callers

nothing calls this directly

Calls 8

caffe_add_scalarFunction · 0.85
countMethod · 0.80
cpu_diffMethod · 0.80
mutable_cpu_diffMethod · 0.80
mutable_gpu_diffMethod · 0.80
mutable_cpu_dataMethod · 0.45
cpu_dataMethod · 0.45
mutable_gpu_dataMethod · 0.45

Tested by

no test coverage detected