ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
25namespace onert
26{
27namespace backend
28{
29namespace train
30{
31namespace optimizer
32{
33
39{
40public:
42
43public:
44 struct Property
45 {
46 double beta1{0.9};
47 double beta2{0.999};
48 double epsilon{1e-07};
49 };
50
51public:
52 explicit Adam() : _props{}, _learning_rate{0.001} {}
53 explicit Adam(const Property &props) : _props{props}, _learning_rate{0.001} {}
54 explicit Adam(double lr) : _props{}, _learning_rate{lr} {}
55 explicit Adam(const Property &props, double lr) : _props{props}, _learning_rate{lr} {}
56
57public:
63 std::string name() const override { return std::string{"Adam"}; }
64
71 double getLearningRate(uint32_t training_step) const override;
72
78 virtual uint32_t getVarCount() const override { return 2; };
79
85 void applyGradient(const UpdateFactors &factors) const override;
86
87private:
88 Property _props;
89 double _learning_rate;
90};
91
92} // namespace optimizer
93} // namespace train
94} // namespace backend
95} // namespace onert
96
97#endif // __ONERT_BACKEND_TRAIN_OPTIMIZER_ADAM_H__
void applyGradient(const UpdateFactors &factors) const override
Apply gradient to a trainable tensor.
Definition Adam.cc:39
virtual uint32_t getVarCount() const override
Get the number of optimizer variables s.
Definition Adam.h:78
exec::train::optimizer::UpdateFactors UpdateFactors
Definition Adam.h:41
std::string name() const override
Get the name of optimizer.
Definition Adam.h:63
Adam(const Property &props)
Definition Adam.h:53
double getLearningRate(uint32_t training_step) const override
Get the Learning Rate.
Definition Adam.cc:33
Adam(const Property &props, double lr)
Definition Adam.h:55
Base class for all optimizers.
Definition Optimizer.h:43
std::tuple< const backend::IPortableTensor &, backend::train::ITrainableTensor &, size_t > UpdateFactors
Definition Optimizer.h:36