• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_APPLY_MOMENTUM_H_
18 #define MINDSPORE_CORE_OPS_APPLY_MOMENTUM_H_
19 #include <vector>
20 #include <memory>
21 
22 #include "ops/primitive_c.h"
23 #include "abstract/abstract_value.h"
24 #include "utils/check_convert_utils.h"
25 
26 namespace mindspore {
27 namespace ops {
28 constexpr auto kNameApplyMomentum = "ApplyMomentum";
29 /// \brief Optimizer that implements the Momentum algorithm.
30 /// Refer to Python API @ref mindspore.ops.ApplyMomentum for more details.
31 class MS_CORE_API ApplyMomentum : public PrimitiveC {
32  public:
33   /// \brief Constructor.
ApplyMomentum()34   ApplyMomentum() : PrimitiveC(kNameApplyMomentum) {
35     InitIOName({"variable", "accumulation", "learning_rate", "gradient", "momentum"}, {"output"});
36   }
37   /// \brief Destructor.
38   ~ApplyMomentum() = default;
39   MS_DECLARE_PARENT(ApplyMomentum, PrimitiveC);
40   /// \brief Init. Refer to the parameters of Python API @ref mindspore.ops.ApplyMomentum for the inputs.
41   void Init(const bool use_nesterov = false, const bool use_locking = false, const float gradient_scale = 1.0);
42   /// \brief Set use_nesterov.
43   void set_use_nesterov(const bool use_nesterov);
44   /// \brief Set use_locking.
45   void set_use_locking(const bool use_locking);
46   /// \brief Set gradient_scale.
47   void set_gradient_scale(const float gradient_scale);
48   /// \brief Get use_nesterov.
49   ///
50   /// \return use_nesterov.
51   bool get_use_nesterov() const;
52   /// \brief Get use_locking.
53   ///
54   /// \return use_locking.
55   bool get_use_locking() const;
56   /// \brief Get gradient_scale.
57   ///
58   /// \return gradient_scale.
59   float get_gradient_scale() const;
60 };
61 AbstractBasePtr ApplyMomentumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
62                                    const std::vector<AbstractBasePtr> &input_args);
63 using PrimApplyMomentumPtr = std::shared_ptr<ApplyMomentum>;
64 }  // namespace ops
65 }  // namespace mindspore
66 
67 #endif  // MINDSPORE_CORE_OPS_APPLY_MOMENTUM_H_
68