• 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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GPU_APPLY_MOMENTUM_WEIGHT_DECAY_SCALE_FUSION_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GPU_APPLY_MOMENTUM_WEIGHT_DECAY_SCALE_FUSION_H_
18 
19 #include <memory>
20 #include "backend/optimizer/common/optimizer.h"
21 
22 namespace mindspore {
23 namespace opt {
24 class ApplyMomentumWeightDecayScaleFusion : public PatternProcessPass {
25  public:
26   explicit ApplyMomentumWeightDecayScaleFusion(bool multigraph = true)
27       : PatternProcessPass("momentum_weightdecay_scale_fusion", multigraph) {
28     monad_ = std::make_shared<Var>();
29     weight_decay_ = std::make_shared<Var>();
30     scale_ = std::make_shared<CondVar>(IsScalar);
31     variable_ = std::make_shared<Var>();
32     accumulation_ = std::make_shared<Var>();
33     learning_rate_ = std::make_shared<Var>();
34     cast_gradient_ = std::make_shared<CondVar>(IsCast);
35     momentum_ = std::make_shared<Var>();
36     monad_state_ = std::make_shared<Var>();
37   }
38   ~ApplyMomentumWeightDecayScaleFusion() override = default;
39   const BaseRef DefinePattern() const override;
40   const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override;
41 
42  private:
43   static bool IsScalar(const BaseRef &n);
44   static bool IsCast(const BaseRef &n);
45 
46   VarPtr monad_;
47   VarPtr weight_decay_;
48   VarPtr scale_;
49   VarPtr variable_;
50   VarPtr accumulation_;
51   VarPtr learning_rate_;
52   VarPtr cast_gradient_;
53   VarPtr momentum_;
54   VarPtr monad_state_;
55 };
56 }  // namespace opt
57 }  // namespace mindspore
58 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GPU_APPLY_MOMENTUM_WEIGHT_DECAY_SCALE_FUSION_H_
59