193 lines
13 KiB
C++
193 lines
13 KiB
C++
/**
|
||
* Copyright 2019-2021 Huawei Technologies Co., Ltd
|
||
*
|
||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
* you may not use this file except in compliance with the License.
|
||
* You may obtain a copy of the License at
|
||
*
|
||
* http://www.apache.org/licenses/LICENSE-2.0
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software
|
||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
* See the License for the specific language governing permissions and
|
||
* limitations under the License.
|
||
*/
|
||
|
||
#include "transform/graph_ir/op_declare/rnn_declare.h"
|
||
|
||
namespace mindspore::transform {
|
||
// BasicLSTMCell
|
||
INPUT_MAP(BasicLSTMCell) = {
|
||
{1, INPUT_DESC(x)}, {2, INPUT_DESC(h)}, {3, INPUT_DESC(c)}, {4, INPUT_DESC(w)}, {5, INPUT_DESC(b)}};
|
||
// 输入映射,共五个,x索引为1,h索引为2,c索引为3,w索引为4,b索引为5
|
||
ATTR_MAP(BasicLSTMCell) = {{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())},
|
||
{"forget_bias", ATTR_DESC(forget_bias, AnyTraits<float>())},
|
||
{"state_is_tuple", ATTR_DESC(state_is_tuple, AnyTraits<bool>())},
|
||
{"activation", ATTR_DESC(activation, AnyTraits<std::string>())}};
|
||
// 属性映射,列出了"keep_prob"、"forget_bias"、"state_is_tuple"、"activation"四个属性,类型分别为bool和std::string
|
||
OUTPUT_MAP(BasicLSTMCell) = {{0, OUTPUT_DESC(ct)}, {1, OUTPUT_DESC(ht)}, {2, OUTPUT_DESC(it)}, {3, OUTPUT_DESC(jt)},
|
||
{4, OUTPUT_DESC(ft)}, {5, OUTPUT_DESC(ot)}, {6, OUTPUT_DESC(tanhct)}}
|
||
// 输出映射,共七个,cty索引为0,ht索引为1,it索引为2,jt索引为3,ft索引为4,ot索引为5,tanhct索引为6
|
||
REG_ADPT_DESC(BasicLSTMCell, kNameBasicLSTMCell, ADPT_DESC(BasicLSTMCell))
|
||
// 注册BasicLSTMCell操作的适配器描述kNameBasicLSTMCell
|
||
|
||
// BasicLSTMCellInputGrad
|
||
INPUT_MAP(BasicLSTMCellInputGrad) = {{1, INPUT_DESC(dgate)}, {2, INPUT_DESC(w)}};
|
||
// 输入映射,共两个,dgate索引为1,w索引为2
|
||
ATTR_MAP(BasicLSTMCellInputGrad) = {{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())}};
|
||
// 属性映射,列出了"keep_prob"属性,类型为float
|
||
OUTPUT_MAP(BasicLSTMCellInputGrad) = {{0, OUTPUT_DESC(dxt)}, {1, OUTPUT_DESC(dht)}};
|
||
// 输出映射,共两个,dxt索引为0,dht索引为1
|
||
REG_ADPT_DESC(BasicLSTMCellInputGrad, kNameBasicLSTMCellInputGrad, ADPT_DESC(BasicLSTMCellInputGrad))
|
||
// 注册BasicLSTMCellInputGrad操作的适配器描述kNameBasicLSTMCellInputGrad
|
||
|
||
|
||
// BasicLSTMCellWeightGrad
|
||
INPUT_MAP(BasicLSTMCellWeightGrad) = {{1, INPUT_DESC(x)}, {2, INPUT_DESC(h)}, {3, INPUT_DESC(dgate)}};
|
||
// 输入映射,共三个,dgate索引为1,w索引为2,dgate索引为3
|
||
ATTR_MAP(BasicLSTMCellWeightGrad) = EMPTY_ATTR_MAP;
|
||
//属性映射,空
|
||
OUTPUT_MAP(BasicLSTMCellWeightGrad) = {{0, OUTPUT_DESC(dw)}, {1, OUTPUT_DESC(db)}};
|
||
// 输出映射,共两个,dw索引为0,db索引为1
|
||
REG_ADPT_DESC(BasicLSTMCellWeightGrad, kNameBasicLSTMCellWeightGrad, ADPT_DESC(BasicLSTMCellWeightGrad))
|
||
// 注册BasicLSTMCellWeightGrad操作的适配器描述kNameBasicLSTMCellWeightGrad
|
||
|
||
// BasicLSTMCellCStateGrad
|
||
INPUT_MAP(BasicLSTMCellCStateGrad) = {{1, INPUT_DESC(c)}, {2, INPUT_DESC(dht)}, {3, INPUT_DESC(dct)},
|
||
{4, INPUT_DESC(it)}, {5, INPUT_DESC(jt)}, {6, INPUT_DESC(ft)},
|
||
{7, INPUT_DESC(ot)}, {8, INPUT_DESC(tanhct)}};
|
||
// 输入映射,共八个,c索引为1,dht索引为2,dct索引为3,it索引为4,jt索引为5,ft索引为6,ot索引为7,tanhct索引为8
|
||
ATTR_MAP(BasicLSTMCellCStateGrad) = {{"forget_bias", ATTR_DESC(forget_bias, AnyTraits<float>())},
|
||
{"activation", ATTR_DESC(activation, AnyTraits<std::string>())}};
|
||
// 属性映射,列出了"forget_bias"和"activation"属性,类型分别为float和std::string
|
||
OUTPUT_MAP(BasicLSTMCellCStateGrad) = {{0, OUTPUT_DESC(dgate)}, {1, OUTPUT_DESC(dct_1)}};
|
||
// 输出映射,共两个,dgate索引为0,dct_1索引为1
|
||
REG_ADPT_DESC(BasicLSTMCellCStateGrad, kNameBasicLSTMCellCStateGrad, ADPT_DESC(BasicLSTMCellCStateGrad))
|
||
// 注册BasicLSTMCellCStateGrad操作的适配器描述kNameBasicLSTMCellCStateGrad
|
||
|
||
|
||
// LSTMInputGrad
|
||
INPUT_MAP(LSTMInputGrad) = {{1, INPUT_DESC(w)}, {2, INPUT_DESC(init_c)}, {3, INPUT_DESC(c)}, {4, INPUT_DESC(dy)},
|
||
{5, INPUT_DESC(dh)}, {6, INPUT_DESC(dc)}, {7, INPUT_DESC(i)}, {8, INPUT_DESC(j)},
|
||
{9, INPUT_DESC(f)}, {10, INPUT_DESC(o)}, {11, INPUT_DESC(tanhct)}};
|
||
//输入映射,共十一个,w索引为1,init_c索引为2,di索引为3,dy索引为4,dh索引为5,dc索引为6,i索引为7,j索引为8,f索引为9,o索引为10,tanhct索引为11
|
||
ATTR_MAP(LSTMInputGrad) = EMPTY_ATTR_MAP;
|
||
// 属性映射,空
|
||
OUTPUT_MAP(LSTMInputGrad) = {
|
||
{0, OUTPUT_DESC(dx)}, {1, OUTPUT_DESC(dh_prev)}, {2, OUTPUT_DESC(dc_prev)}, {4, OUTPUT_DESC(dgate)}};
|
||
// 输出映射,共四个,dh_prev索引为1,dc_prev索引为2,dgate索引为4
|
||
REG_ADPT_DESC(LSTMInputGrad, kNameLSTMInputGrad, ADPT_DESC(LSTMInputGrad))
|
||
// 注册LSTMInputGrad操作的适配器描述kNameLSTMInputGrad
|
||
|
||
// DynamicRNN
|
||
INPUT_MAP(DynamicRNN) = {{1, INPUT_DESC(x)}, {2, INPUT_DESC(w)}, {3, INPUT_DESC(b)},
|
||
{4, INPUT_DESC(seq_length)}, {5, INPUT_DESC(init_h)}, {6, INPUT_DESC(init_c)},
|
||
{7, INPUT_DESC(wci)}, {8, INPUT_DESC(wcf)}, {9, INPUT_DESC(wco)},
|
||
{10, INPUT_DESC(mask)}};
|
||
// 输入映射,共十个,x索引为1,w索引为2,b索引为3,seq_length索引为4,init_h索引为5,init_c索引为6,wci索引为7,wcf索引为8,wco索引为9,mask索引为10
|
||
ATTR_MAP(DynamicRNN) = {{"cell_type", ATTR_DESC(cell_type, AnyTraits<std::string>())},
|
||
{"direction", ATTR_DESC(direction, AnyTraits<std::string>())},
|
||
{"cell_depth", ATTR_DESC(cell_depth, AnyTraits<int64_t>())},
|
||
{"use_peephole", ATTR_DESC(use_peephole, AnyTraits<bool>())},
|
||
{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())},
|
||
{"cell_clip", ATTR_DESC(cell_clip, AnyTraits<float>())},
|
||
{"num_proj", ATTR_DESC(num_proj, AnyTraits<int64_t>())},
|
||
{"time_major", ATTR_DESC(time_major, AnyTraits<bool>())},
|
||
{"ivation", ATTR_DESC(activation, AnyTraits<std::string>())},
|
||
{"forget_bias", ATTR_DESC(forget_bias, AnyTraits<float>())},
|
||
{"is_training", ATTR_DESC(is_training, AnyTraits<bool>())}};
|
||
// 属性映射,列出了"cell_type""ivation"和"direction"属性,类型为std::string
|
||
//"cell_depth"和"num_proj",类型为int64_t
|
||
//"use_peephole""is_training"和"time_major",类型为bool
|
||
//"keep_prob""cell_clip""forget_bias",类型为float
|
||
OUTPUT_MAP(DynamicRNN) = {{0, OUTPUT_DESC(y)}, {1, OUTPUT_DESC(output_h)}, {2, OUTPUT_DESC(output_c)},
|
||
{3, OUTPUT_DESC(i)}, {4, OUTPUT_DESC(j)}, {5, OUTPUT_DESC(f)},
|
||
{6, OUTPUT_DESC(o)}, {7, OUTPUT_DESC(tanhc)}};
|
||
// 输出映射,共十个,x索引为1,w索引为2,b索引为3,seq_length索引为4,init_h索引为5,init_c索引为6,wci索引为7,wcf索引为8,wco索引为9,mask索引为10
|
||
REG_ADPT_DESC(DynamicRNN, kNameDynamicRNN, ADPT_DESC(DynamicRNN))
|
||
// 注册DynamicRNN操作的适配器描述kNameDynamicRNN
|
||
|
||
// DynamicRNNGrad
|
||
INPUT_MAP(DynamicRNNGrad) = {
|
||
{1, INPUT_DESC(x)}, {2, INPUT_DESC(w)}, {3, INPUT_DESC(b)}, {4, INPUT_DESC(y)},
|
||
{5, INPUT_DESC(init_h)}, {6, INPUT_DESC(init_c)}, {7, INPUT_DESC(h)}, {8, INPUT_DESC(c)},
|
||
{9, INPUT_DESC(dy)}, {10, INPUT_DESC(dh)}, {11, INPUT_DESC(dc)}, {12, INPUT_DESC(i)},
|
||
{13, INPUT_DESC(j)}, {14, INPUT_DESC(f)}, {15, INPUT_DESC(o)}, {16, INPUT_DESC(tanhct)}};
|
||
// 输入映射,共十个,x索引为1,w索引为2,b索引为3,y索引为4,init_h索引为5,init_c索引为6,h索引为7,c索引为8,dy索引为9,dh索引为10,dc索引为11,i索引为12
|
||
//j索引为13,f索引为14,o索引为15,tanhct索引为16
|
||
ATTR_MAP(DynamicRNNGrad) = {{"cell_type", ATTR_DESC(cell_type, AnyTraits<std::string>())},
|
||
{"direction", ATTR_DESC(direction, AnyTraits<std::string>())},
|
||
{"cell_depth", ATTR_DESC(cell_depth, AnyTraits<int64_t>())},
|
||
{"use_peephole", ATTR_DESC(use_peephole, AnyTraits<bool>())},
|
||
{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())},
|
||
{"cell_clip", ATTR_DESC(cell_clip, AnyTraits<float>())},
|
||
{"num_proj", ATTR_DESC(num_proj, AnyTraits<int64_t>())},
|
||
{"time_major", ATTR_DESC(time_major, AnyTraits<bool>())},
|
||
{"forget_bias", ATTR_DESC(forget_bias, AnyTraits<float>())}};
|
||
// 属性映射,列出了"cell_type"和"direction"属性,类型为std::string
|
||
//"cell_depth"和"num_proj",类型为int64_t
|
||
//"use_peephole""is_training"和"time_major",类型为bool
|
||
//"keep_prob""cell_clip""forget_bias",类型为float
|
||
OUTPUT_MAP(DynamicRNNGrad) = {{0, OUTPUT_DESC(dw)},
|
||
{1, OUTPUT_DESC(db)},
|
||
{2, OUTPUT_DESC(dx)},
|
||
{3, OUTPUT_DESC(dh_prev)},
|
||
{4, OUTPUT_DESC(dc_prev)}};
|
||
// 输出映射,共五个,dw索引为0,db索引为1,dh_prev索引为2,dh_prev索引为3,dc_prev索引为4
|
||
REG_ADPT_DESC(DynamicRNNGrad, kNameDynamicRNNGrad, ADPT_DESC(DynamicRNNGrad))
|
||
// 注册DynamicRNNGrad操作的适配器描述kNameDynamicRNNGrad
|
||
|
||
// DynamicGRUV2
|
||
INPUT_MAP(DynamicGRUV2) = {{1, INPUT_DESC(x)}, {2, INPUT_DESC(weight_input)}, {3, INPUT_DESC(weight_hidden)},
|
||
{4, INPUT_DESC(bias_input)}, {5, INPUT_DESC(bias_hidden)}, {6, INPUT_DESC(seq_length)},
|
||
{7, INPUT_DESC(init_h)}};
|
||
// 输入映射,共七个,x索引为1,weight_input索引为2,weight_hidden索引为3,bias_input索引为4,bias_hidden索引为5,seq_length索引为6,init_h索引为7
|
||
ATTR_MAP(DynamicGRUV2) = {{"direction", ATTR_DESC(direction, AnyTraits<std::string>())},
|
||
{"cell_depth", ATTR_DESC(cell_depth, AnyTraits<int64_t>())},
|
||
{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())},
|
||
{"cell_clip", ATTR_DESC(cell_clip, AnyTraits<float>())},
|
||
{"num_proj", ATTR_DESC(num_proj, AnyTraits<int64_t>())},
|
||
{"time_major", ATTR_DESC(time_major, AnyTraits<bool>())},
|
||
{"activation", ATTR_DESC(activation, AnyTraits<std::string>())},
|
||
{"gate_order", ATTR_DESC(gate_order, AnyTraits<std::string>())},
|
||
{"reset_after", ATTR_DESC(reset_after, AnyTraits<bool>())},
|
||
{"is_training", ATTR_DESC(is_training, AnyTraits<bool>())}};
|
||
// 属性映射,列出了"direction"和"activation""gate_order"属性,类型为std::string
|
||
//"cell_depth"和"num_proj",类型为int64_t
|
||
//"reset_after""is_training"和"time_major",类型为bool
|
||
//"keep_prob""cell_clip""forget_bias",类型为float
|
||
OUTPUT_MAP(DynamicGRUV2) = {{0, OUTPUT_DESC(y)}, {1, OUTPUT_DESC(output_h)}, {2, OUTPUT_DESC(update)},
|
||
{3, OUTPUT_DESC(reset)}, {4, OUTPUT_DESC(new)}, {5, OUTPUT_DESC(hidden_new)}};
|
||
// 输入映射,共六个,y索引为0,output_h索引为1,update索引为2,reset索引为3,new索引为4,hidden_new索引为5
|
||
REG_ADPT_DESC(DynamicGRUV2, kNameDynamicGRUV2, ADPT_DESC(DynamicGRUV2))
|
||
// 注册DynamicGRUV2操作的适配器描述kNameDynamicGRUV2
|
||
//
|
||
// DynamicGRUV2Grad
|
||
INPUT_MAP(DynamicGRUV2Grad) = {
|
||
{1, INPUT_DESC(x)}, {2, INPUT_DESC(weight_input)}, {3, INPUT_DESC(weight_hidden)},
|
||
{4, INPUT_DESC(y)}, {5, INPUT_DESC(init_h)}, {6, INPUT_DESC(h)},
|
||
{7, INPUT_DESC(dy)}, {8, INPUT_DESC(dh)}, {9, INPUT_DESC(update)},
|
||
{10, INPUT_DESC(reset)}, {11, INPUT_DESC(new)}, {12, INPUT_DESC(hidden_new)},
|
||
{13, INPUT_DESC(seq_length)}, {14, INPUT_DESC(mask)}};
|
||
// 输入映射,共十四个,x索引为1,weight_input索引为2,weight_hidden索引为3,y索引为4,init_h索引为5,h索引为6,dy索引为7,dh索引为8,
|
||
//update索引为9,reset索引为10,new索引为11,hidden_new索引为12,seq_length索引为13,mask索引为14
|
||
ATTR_MAP(DynamicGRUV2Grad) = {{"direction", ATTR_DESC(direction, AnyTraits<std::string>())},
|
||
{"cell_depth", ATTR_DESC(cell_depth, AnyTraits<int64_t>())},
|
||
{"keep_prob", ATTR_DESC(keep_prob, AnyTraits<float>())},
|
||
{"cell_clip", ATTR_DESC(cell_clip, AnyTraits<float>())},
|
||
{"num_proj", ATTR_DESC(num_proj, AnyTraits<int64_t>())},
|
||
{"time_major", ATTR_DESC(time_major, AnyTraits<bool>())},
|
||
{"gate_order", ATTR_DESC(gate_order, AnyTraits<std::string>())},
|
||
{"reset_after", ATTR_DESC(reset_after, AnyTraits<bool>())}};
|
||
// 属性映射,列出了"direction"和"activation""gate_order"属性,类型为std::string
|
||
//"cell_depth"和"num_proj",类型为int64_t
|
||
//"reset_after""is_training"和"time_major",类型为bool
|
||
//"keep_prob""cell_clip",类型为float
|
||
OUTPUT_MAP(DynamicGRUV2Grad) = {{0, OUTPUT_DESC(dw_input)}, {1, OUTPUT_DESC(dw_hidden)}, {2, OUTPUT_DESC(db_input)},
|
||
{3, OUTPUT_DESC(db_hidden)}, {4, OUTPUT_DESC(dx)}, {5, OUTPUT_DESC(dh_prev)}};
|
||
// 输入映射,共六个,dw_input索引为0,dw_hidden索引为1,db_input索引为2,db_hidden索引为3,dx索引为4,dh_prev索引为5
|
||
REG_ADPT_DESC(DynamicGRUV2Grad, kNameDynamicGRUV2Grad, ADPT_DESC(DynamicGRUV2Grad))
|
||
// 注册DynamicGRUV2Grad操作的适配器描述kNameDynamicGRUV2Grad
|
||
} // namespace mindspore::transform
|