LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
hypergradient_adam.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_OPTIMIZERS_HYPERGRADIENT_ADAM_HPP_INCLUDED
28 #define LBANN_OPTIMIZERS_HYPERGRADIENT_ADAM_HPP_INCLUDED
29 
30 #include "lbann/io/persist.hpp"
32 #include "lbann/proto/optimizers.pb.h"
33 
34 namespace lbann {
35 
44 template <typename TensorDataType>
45 class hypergradient_adam : public Cloneable<hypergradient_adam<TensorDataType>,
46  data_type_optimizer<TensorDataType>>
47 {
50 
51 public:
53 
56  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
57 
60 
63 
65 
66 public:
80  TensorDataType init_learning_rate = El::To<TensorDataType>(1e-3),
81  TensorDataType hyper_learning_rate = El::To<TensorDataType>(1e-7),
82  TensorDataType beta1 = El::To<TensorDataType>(0.9),
83  TensorDataType beta2 = El::To<TensorDataType>(0.99),
84  TensorDataType eps = El::To<TensorDataType>(1e-8));
87  ~hypergradient_adam() override = default;
88 
90  template <class Archive>
91  void serialize(Archive& ar);
92 
94  std::string get_type() const override { return "hypergradient Adam"; }
96  description get_description() const override;
97 
99  void setup(WeightsType* w = nullptr) override;
100 
102  void write_proto(lbann_data::Optimizer& opt) const final;
103 
104 protected:
106  void step_compute(AbsDistMatrixType& values,
107  const AbsDistMatrixType& gradient) override;
108 
109 private:
111  TensorDataType m_hyper_learning_rate;
113  TensorDataType m_beta1;
115  TensorDataType m_beta2;
117  TensorDataType m_eps;
119  TensorDataType m_current_beta1;
121  TensorDataType m_current_beta2;
123  std::unique_ptr<AbsDistMatrixType> m_moment1;
125  std::unique_ptr<AbsDistMatrixType> m_moment2;
127  std::unique_ptr<AbsDistMatrixType> m_old_gradient;
128 };
129 
130 template <typename TensorDataType>
131 std::unique_ptr<optimizer>
132 build_hypergradient_adam_optimizer_from_pbuf(google::protobuf::Message const&);
133 
134 } // namespace lbann
135 
136 #endif // LBANN_OPTIMIZER_HYPERGRADIENT_ADAM_HPP_INCLUDED
TensorDataType m_beta1
Update factor for first moment estimate.
Inject polymorphic clone functions into hierarchies.
Definition: cloneable.hpp:94
void step_compute(AbsDistMatrixType &values, const AbsDistMatrixType &gradient) override
Computation for an optimization step.
void setup(weights *w) override
Must be called before training.
hypergradient_adam(TensorDataType init_learning_rate=El::To< TensorDataType >(1e-3), TensorDataType hyper_learning_rate=El::To< TensorDataType >(1e-7), TensorDataType beta1=El::To< TensorDataType >(0.9), TensorDataType beta2=El::To< TensorDataType >(0.99), TensorDataType eps=El::To< TensorDataType >(1e-8))
Construct a Hypergradient Adam optimizer object.
Generates nicely formatted description messages.
Definition: description.hpp:49
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
TensorDataType m_hyper_learning_rate
Hypergradient learning rate.
void write_proto(lbann_data::Optimizer &opt) const final
TensorDataType m_eps
Small factor to avoid division by zero.
std::unique_ptr< optimizer > build_hypergradient_adam_optimizer_from_pbuf(google::protobuf::Message const &)
description get_description() const override
Human-readable description.
Hypergradient Adam optimizer.
TensorDataType m_beta2
Update factor for second moment estimate.
std::unique_ptr< AbsDistMatrixType > m_old_gradient
Gradient estimate from the prior step (for hypergradient).
std::unique_ptr< AbsDistMatrixType > m_moment1
First moment estimates.
std::unique_ptr< AbsDistMatrixType > m_moment2
Second moment estimates.
hypergradient_adam & operator=(const hypergradient_adam &other)
TensorDataType m_current_beta2
beta2 ^ iteration.
void setup(WeightsType *w=nullptr) override
std::string get_type() const override
Human-readable type name.
TensorDataType m_current_beta1
beta1 ^ iteration.
~hypergradient_adam() override=default