LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
rmsprop.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_RMSPROP_HPP_INCLUDED
28 #define LBANN_OPTIMIZERS_RMSPROP_HPP_INCLUDED
29 
30 #include "lbann/io/persist.hpp"
32 #include "lbann/proto/optimizers.pb.h"
33 #include <sys/stat.h>
34 
35 namespace lbann {
36 
42 template <typename TensorDataType>
43 class rmsprop : public Cloneable<rmsprop<TensorDataType>,
44  data_type_optimizer<TensorDataType>>
45 {
46  using BaseType =
48 
49 public:
51 
54  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
55 
57  using OptimizerType = data_type_optimizer<TensorDataType>;
58 
61 
63 
64 public:
65  rmsprop(TensorDataType learning_rate,
66  TensorDataType decay_rate,
67  TensorDataType eps = 1e-8);
68  rmsprop(const rmsprop& other);
69  rmsprop& operator=(const rmsprop& other);
70  ~rmsprop() override = default;
71 
73  template <class Archive>
74  void serialize(Archive& ar);
75 
77  std::string get_type() const override { return "RMSprop"; }
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 
95  : rmsprop(El::To<TensorDataType>(1.f),
96  El::To<TensorDataType>(1.f),
97  El::To<TensorDataType>(1e-8))
98  {}
99 
101  void step_compute(AbsDistMatrixType& values,
102  const AbsDistMatrixType& gradient) override;
103 
104 private:
106  TensorDataType m_decay_rate;
108  TensorDataType m_eps;
110  std::unique_ptr<AbsDistMatrixType> m_cache;
111 
113  void step_compute_cpu(AbsDistMatrixType& values,
114  const AbsDistMatrixType& gradient);
115 #ifdef LBANN_HAS_GPU
116 
117  void step_compute_gpu(AbsDistMatrixType& values,
118  const AbsDistMatrixType& gradient);
119 #endif // LBANN_HAS_GPU
120 };
121 
122 template <typename TensorDataType>
123 std::unique_ptr<optimizer>
124 build_rmsprop_optimizer_from_pbuf(google::protobuf::Message const&);
125 
126 } // namespace lbann
127 
128 #endif // LBANN_OPTIMIZERS_RMSPROP_HPP_INCLUDED
Inject polymorphic clone functions into hierarchies.
Definition: cloneable.hpp:94
void setup(weights *w) override
Must be called before training.
TensorDataType m_decay_rate
Definition: rmsprop.hpp:106
Generates nicely formatted description messages.
Definition: description.hpp:49
description get_description() const override
std::unique_ptr< AbsDistMatrixType > m_cache
Definition: rmsprop.hpp:110
void write_proto(lbann_data::Optimizer &opt) const final
void step_compute_cpu(AbsDistMatrixType &values, const AbsDistMatrixType &gradient)
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
Definition: rmsprop.hpp:54
rmsprop & operator=(const rmsprop &other)
rmsprop()
Default constructor.
Definition: rmsprop.hpp:94
TensorDataType m_eps
Definition: rmsprop.hpp:108
void setup(WeightsType *w=nullptr) override
std::unique_ptr< optimizer > build_rmsprop_optimizer_from_pbuf(google::protobuf::Message const &)
void step_compute(AbsDistMatrixType &values, const AbsDistMatrixType &gradient) override
~rmsprop() override=default
void serialize(Archive &ar)
std::string get_type() const override
Definition: rmsprop.hpp:77