1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 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 MINDSPORE_CORE_OPS_SGD_H_ 18 #define MINDSPORE_CORE_OPS_SGD_H_ 19 #include <memory> 20 #include <vector> 21 22 #include "ops/base_operator.h" 23 24 namespace mindspore { 25 namespace ops { 26 constexpr auto kNameSGD = "SGD"; 27 /// \brief Computes the stochastic gradient descent. 28 /// Refer to Python API @ref mindspore.ops.SGD for more details. 29 class MIND_API SGD : public BaseOperator { 30 public: 31 MIND_API_BASE_MEMBER(SGD); 32 /// \brief Constructor. SGD()33 SGD() : BaseOperator(kNameSGD) { 34 InitIOName({"parameters", "gradient", "learning_rate", "accum", "momentum", "stat"}, {"output"}); 35 } 36 /// \brief Init. Refer to the parameters of Python API @ref mindspore.ops.SGD for the inputs. 37 void Init(const float dampening = 0.0, const float weight_decay = 0.0, const bool nesterov = false); 38 /// \brief Set dampening. 39 void set_dampening(const float dampening); 40 /// \brief Set weight_decay. 41 void set_weight_decay(const float weight_decay); 42 /// \brief Set nesterov. 43 void set_nesterov(const bool nesterov); 44 /// \brief Get dampening. 45 /// 46 /// \return dampening. 47 float get_dampening() const; 48 /// \brief Get weight_decay. 49 /// 50 /// \return weight_decay. 51 float get_weight_decay() const; 52 /// \brief Get nesterov. 53 /// 54 /// \return nesterov. 55 bool get_nesterov() const; 56 }; 57 MIND_API abstract::AbstractBasePtr SGDInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 58 const std::vector<abstract::AbstractBasePtr> &input_args); 59 using PrimSGD = std::shared_ptr<SGD>; 60 } // namespace ops 61 } // namespace mindspore 62 #endif // MINDSPORE_CORE_OPS_SGD_H_ 63