1 #include <torch/optim/adagrad.h> 3 #include <torch/csrc/autograd/variable.h> 4 #include <torch/serialize/archive.h> 5 #include <torch/utils.h> 14 AdagradOptions::AdagradOptions(
double learning_rate)
15 : learning_rate_(learning_rate) {}
19 void Adagrad::step() {
20 for (
size_t i = 0; i < parameters_.size(); ++i) {
21 Tensor p = parameters_.at(i);
22 if (!p.grad().defined()) {
26 if (
options.weight_decay_ > 0) {
27 p.grad() = p.grad() +
options.weight_decay_ * p;
30 buffer_at(step_buffers, i) += 1.0;
31 const auto clr =
options.learning_rate_ /
32 (1.0 + (buffer_at(step_buffers, i) - 1.0) *
options.lr_decay_);
34 auto& sum = buffer_at(sum_buffers, i);
35 sum.addcmul_(p.grad(), p.grad(), 1.0);
36 const auto std = buffer_at(sum_buffers, i).sqrt().add_(1e-10);
39 p.addcdiv_(p.grad(),
std, -clr);
44 serialize(*
this, archive);
48 serialize(*
this, archive);
LinearOptions options
The options used to configure this module.