MCPcopy Create free account
hub / github.com/apache/singa / Apply

Method Apply

src/model/optimizer/nesterov.cc:33–54  ·  view source on GitHub ↗

tmp = history; history = lr * grad + history * mom tmp = (1+mom) * history - tmp * mom; value = value - tmp;

Source from the content-addressed store, hash-verified

31// tmp = (1+mom) * history - tmp * mom;
32// value = value - tmp;
33void Nesterov::Apply(int epoch, float lr, const string& name, Tensor& grad,
34 Tensor& value, int step) {
35 if (grad.empty())
36 return;
37 ApplyRegularizerConstraint(epoch, name, value, grad, step);
38 if (learning_rate_multplier_.find(name) != learning_rate_multplier_.end())
39 lr *= learning_rate_multplier_.at(name);
40 if (momentum_generator_) {
41 float mom = momentum_generator_(step);
42 if (history_gradient_.find(name) == history_gradient_.end()) {
43 history_gradient_[name].ResetLike(value);
44 history_gradient_[name].SetValue(0.0f);
45 }
46 Tensor& history = history_gradient_[name];
47 Tensor tmp = history.Clone();
48 history *= mom;
49 Axpy(lr, grad, &history);
50 tmp *= -mom;
51 Axpy(1 + mom, history, &tmp);
52 value -= tmp;
53 }
54}
55} // namespace singa
56#endif // SRC_MODEL_OPTIMIZER_NESTEROV_H_

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.80
AxpyFunction · 0.50
endMethod · 0.45
SetValueMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected