• 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_LAYER_NORM_H_
18 #define MINDSPORE_CORE_OPS_LAYER_NORM_H_
19 #include <string>
20 #include <vector>
21 #include <memory>
22 
23 #include "ops/primitive_c.h"
24 #include "abstract/abstract_value.h"
25 #include "utils/check_convert_utils.h"
26 
27 namespace mindspore {
28 namespace ops {
29 constexpr auto kNameLayerNorm = prim::kLayerNorm;
30 /// \brief Applies the Layer Normalization to the input tensor.
31 /// Refer to Python API @ref mindspore.ops.LayerNorm for more details.
32 class MS_CORE_API LayerNorm : public PrimitiveC {
33  public:
34   /// \brief Constructor.
LayerNorm()35   LayerNorm() : PrimitiveC(kNameLayerNorm) {}
LayerNorm(const std::string k_name)36   explicit LayerNorm(const std::string k_name) : PrimitiveC(k_name) {}
37   /// \brief Destructor.
38   ~LayerNorm() = default;
39   MS_DECLARE_PARENT(LayerNorm, PrimitiveC);
40   /// \brief Init. Refer to the parameters of Python API @ref mindspore.ops.LayerNorm for the inputs.
41   void Init(const int64_t begin_norm_axis = 1, const int64_t begin_params_axis = 1, const float epsilon = 1e-7);
42   /// \brief Set begin_norm_axis.
43   void set_begin_norm_axis(const int64_t begin_norm_axis);
44   /// \brief Set begin_params_axis.
45   void set_begin_params_axis(const int64_t begin_params_axis);
46   /// \brief Set epsilon.
47   void set_epsilon(const float epsilon);
48   /// \brief Get begin_norm_axis.
49   ///
50   /// \return begin_norm_axis.
51   int64_t get_begin_norm_axis() const;
52   /// \brief Get begin_params_axis.
53   ///
54   /// \return begin_params_axis.
55   int64_t get_begin_params_axis() const;
56   /// \brief Get epsilon.
57   ///
58   /// \return epsilon.
59   float get_epsilon() const;
60 };
61 
62 AbstractBasePtr LayerNormInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
63                                const std::vector<AbstractBasePtr> &input_args);
64 using PrimLayerNormPtr = std::shared_ptr<LayerNorm>;
65 
66 }  // namespace ops
67 }  // namespace mindspore
68 
69 #endif  // MINDSPORE_CORE_OPS_LAYER_NORM_H_
70