ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Adam.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ONERT_BACKEND_TRAIN_OPTIMIZER_ADAM_H__
18#define __ONERT_BACKEND_TRAIN_OPTIMIZER_ADAM_H__
19
21
23#include "ir/OperandIndexMap.h"
24
26{
27
33{
34public:
36
37public:
38 struct Property
39 {
40 double beta1{0.9};
41 double beta2{0.999};
42 double epsilon{1e-07};
43 };
44
45public:
46 explicit Adam() : _props{}, _learning_rate{0.001} {}
47 explicit Adam(const Property &props) : _props{props}, _learning_rate{0.001} {}
48 explicit Adam(double lr) : _props{}, _learning_rate{lr} {}
49 explicit Adam(const Property &props, double lr) : _props{props}, _learning_rate{lr} {}
50
51public:
57 std::string name() const override { return std::string{"Adam"}; }
58
65 double getLearningRate(uint32_t training_step) const override;
66
72 virtual uint32_t getVarCount() const override { return 2; };
73
79 void applyGradient(const UpdateFactors &factors) const override;
80
81private:
82 Property _props;
83 double _learning_rate;
84};
85
86} // namespace onert::backend::train::optimizer
87
88#endif // __ONERT_BACKEND_TRAIN_OPTIMIZER_ADAM_H__
void applyGradient(const UpdateFactors &factors) const override
Apply gradient to a trainable tensor.
Definition Adam.cc:33
virtual uint32_t getVarCount() const override
Get the number of optimizer variables s.
Definition Adam.h:72
exec::train::optimizer::UpdateFactors UpdateFactors
Definition Adam.h:35
std::string name() const override
Get the name of optimizer.
Definition Adam.h:57
Adam(const Property &props)
Definition Adam.h:47
double getLearningRate(uint32_t training_step) const override
Get the Learning Rate.
Definition Adam.cc:27
Adam(const Property &props, double lr)
Definition Adam.h:49
Base class for all optimizers.
Definition Optimizer.h:37
std::tuple< const backend::IPortableTensor &, backend::train::ITrainableTensor &, size_t > UpdateFactors
Definition Optimizer.h:30