ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SGD.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_SGD_H__
18#define __ONERT_BACKEND_TRAIN_OPTIMIZER_SGD_H__
19
21
23{
24
30{
31public:
33
34public:
35 struct Property
36 {
37 double momentum{0.0};
38 bool nesterov{false};
39 };
40
41public:
42 explicit SGD() : _props{}, _learning_rate{0.01} {}
43 explicit SGD(const Property &props) : _props{props}, _learning_rate{0.01} {}
44 explicit SGD(double lr) : _props{}, _learning_rate{lr} {}
45 explicit SGD(const Property &props, double lr) : _props{props}, _learning_rate{lr} {}
46
47public:
53 std::string name() const override { return std::string{"SGD"}; }
54
61 double getLearningRate(uint32_t iteration = 0) const override;
62
68 virtual uint32_t getVarCount() const override { return 0; };
69
75 void applyGradient(const UpdateFactors &factors) const override;
76
77private:
78 Property _props;
79 double _learning_rate;
80};
81
82} // namespace onert::backend::train::optimizer
83
84#endif // __ONERT_BACKEND_TRAIN_OPTIMIZER_SGD_H__
SGD(const Property &props, double lr)
Definition SGD.h:45
exec::train::optimizer::UpdateFactors UpdateFactors
Definition SGD.h:32
double getLearningRate(uint32_t iteration=0) const override
Get the Learning Rate.
Definition SGD.cc:26
std::string name() const override
Get the name of optimizer.
Definition SGD.h:53
SGD(const Property &props)
Definition SGD.h:43
void applyGradient(const UpdateFactors &factors) const override
Apply gradient to a trainable tensor.
Definition SGD.cc:32
virtual uint32_t getVarCount() const override
Get the number of optimizer variables s.
Definition SGD.h:68
Base class for all optimizers.
Definition Optimizer.h:37
std::tuple< const backend::IPortableTensor &, backend::train::ITrainableTensor &, size_t > UpdateFactors
Definition Optimizer.h:30