4 #include <torch/nn/module.h> 5 #include <torch/optim/optimizer.h> 6 #include <torch/optim/serialize.h> 7 #include <torch/serialize/archive.h> 19 TORCH_ARG(
double, learning_rate);
20 TORCH_ARG(int64_t, max_iter) = 20;
21 TORCH_ARG(int64_t, max_eval) = 25;
22 TORCH_ARG(
float, tolerance_grad) = 1e-5;
23 TORCH_ARG(
float, tolerance_change) = 1e-9;
24 TORCH_ARG(
size_t, history_size) = 100;
29 template <
typename ParameterContainer>
33 ro(options.history_size_),
34 al(options.history_size_) {}
43 Tensor d{torch::empty({0})};
44 Tensor H_diag{torch::empty({0})};
45 Tensor prev_flat_grad{torch::empty({0})};
47 Tensor prev_loss{torch::zeros(1)};
48 std::vector<Tensor> ro;
49 std::vector<Tensor> al;
50 std::deque<Tensor> old_dirs;
51 std::deque<Tensor> old_stps;
52 int64_t func_evals{0};
53 int64_t state_n_iter{0};
56 LBFGS() : options(0) {}
61 template <
typename Self,
typename Archive>
62 static void serialize(Self&
self, Archive& archive) {
63 archive(
"d",
self.d,
true);
64 archive(
"t",
self.t,
true);
65 archive(
"H_diag",
self.H_diag,
true);
66 archive(
"prev_flat_grad",
self.prev_flat_grad,
true);
67 archive(
"prev_loss",
self.prev_loss,
true);
68 optim::serialize(archive,
"old_dirs",
self.old_dirs);
69 optim::serialize(archive,
"old_stps",
self.old_stps);
Optimizer that requires the loss function to be supplied to the step() function, as it may evaluate t...
std::function< Tensor()> LossClosure
A loss function closure, which is expected to return the loss value.