LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
adagrad.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_ADAGRAD_HPP_INCLUDED
28 #define LBANN_OPTIMIZERS_ADAGRAD_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 adagrad : public Cloneable<adagrad<TensorDataType>,
46  data_type_optimizer<TensorDataType>>
47 {
48  using BaseType =
50 
51 public:
53 
56  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
57 
59  using OptimizerType = data_type_optimizer<TensorDataType>;
60 
63 
65 
66 public:
67  adagrad(TensorDataType learning_rate, TensorDataType eps = 1e-8);
68  adagrad(const adagrad& other);
69  adagrad& operator=(const adagrad& other);
70  ~adagrad() override = default;
71 
73  template <class Archive>
74  void serialize(Archive& ar);
75 
77  std::string get_type() const override { return "AdaGrad"; }
79  description get_description() const override;
80 
82  void setup(WeightsType* w = nullptr) override;
83 
85  void write_proto(lbann_data::Optimizer& opt) const final;
86 
87 protected:
88  friend cereal::access;
89 
94  adagrad() : adagrad(El::To<TensorDataType>(1.f), El::To<TensorDataType>(1e-8))
95  {}
96 
98  void step_compute(AbsDistMatrixType& values,
99  const AbsDistMatrixType& gradient) override;
100 
101 private:
103  TensorDataType m_eps;
105  std::unique_ptr<AbsDistMatrixType> m_cache;
106 
108  void step_compute_cpu(AbsDistMatrixType& values,
109  const AbsDistMatrixType& gradient);
110 #ifdef LBANN_HAS_DNN_LIB
111 
112  void step_compute_gpu(AbsDistMatrixType& values,
113  const AbsDistMatrixType& gradient);
114 #endif // LBANN_HAS_DNN_LIB
115 };
116 
117 template <typename TensorDataType>
118 std::unique_ptr<optimizer>
119 build_adagrad_optimizer_from_pbuf(google::protobuf::Message const&);
120 
121 } // namespace lbann
122 
123 #endif // LBANN_OPTIMIZERS_ADAGRAD_HPP_INCLUDED
Inject polymorphic clone functions into hierarchies.
Definition: cloneable.hpp:94
TensorDataType m_eps
Definition: adagrad.hpp:103
std::unique_ptr< optimizer > build_adagrad_optimizer_from_pbuf(google::protobuf::Message const &)
void setup(weights *w) override
Must be called before training.
void step_compute(AbsDistMatrixType &values, const AbsDistMatrixType &gradient) override
Generates nicely formatted description messages.
Definition: description.hpp:49
description get_description() const override
std::string get_type() const override
Definition: adagrad.hpp:77
adagrad()
Default constructor.
Definition: adagrad.hpp:94
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
Definition: adagrad.hpp:56
void setup(WeightsType *w=nullptr) override
std::unique_ptr< AbsDistMatrixType > m_cache
Definition: adagrad.hpp:105
void step_compute_cpu(AbsDistMatrixType &values, const AbsDistMatrixType &gradient)
adagrad & operator=(const adagrad &other)
~adagrad() override=default
void serialize(Archive &ar)
void write_proto(lbann_data::Optimizer &opt) const final