1 /** 2 * Copyright 2020-2021 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_LITE_TOOLS_OPTIMIZER_FUSION_TF_LSTM_CELL_FUSION_H_ 17 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_FUSION_TF_LSTM_CELL_FUSION_H_ 18 #include <vector> 19 #include <memory> 20 #include <string> 21 #include "schema/inner/model_generated.h" 22 #include "tools/optimizer/fusion/tflite_lstm_cell_fusion.h" 23 #include "include/backend/optimizer/optimizer.h" 24 #include "include/common/utils/utils.h" 25 #include "include/errorcode.h" 26 27 namespace mindspore { 28 namespace opt { 29 class TfLstmCellFusion : public TfliteLstmCellFusion { 30 public: 31 explicit TfLstmCellFusion(const std::string &name = "TfLstmCellFusion", bool multigraph = true); 32 ~TfLstmCellFusion() override = default; 33 34 private: 35 AnfNodePtr GetBodyGraphPattern(const PrimitiveVarMapPtr &primitive_vars) const override; 36 CNodePtr CreateLSTMNode(const FuncGraphPtr &func_graph, const EquivPtr &equiv, const EquivPtr &body_equiv, 37 const std::string &base_name, float zoneout_cell, float zoneout_hidden) const override; 38 39 static lite::STATUS SplitWeights(const AnfNodePtr &weight, const ParameterPtr &weight_i, const ParameterPtr &weight_c, 40 int hidden_size); 41 static lite::STATUS SetWeightAbstractAndDefault(const ParameterPtr &weight, const std::vector<int64_t> &shape, 42 const float *data_ptr, int hidden_size); 43 lite::STATUS PopulateBiasNode(const EquivPtr &body_equiv, const ParameterPtr &new_bias, const AnfNodePtr &old_bias, 44 int hidden_size) const; 45 46 private: 47 mutable VarPtr forget_bias_ = nullptr; 48 }; 49 } // namespace opt 50 } // namespace mindspore 51 52 #endif // MINDSPORE_LITE_TOOLS_OPTIMIZER_FUSION_TF_LSTM_CELL_FUSION_H_ 53