The decoder is composed of a stack of identical decoder_layer layers. :param dec_input: (batch_size, tgt_len, emb_dim) :param enc_output: (batch_size, n_tokens, emb_dim) :param dec_slf_attn_bias: (batch_size, n_head, tgt_len, tgt_len) :param dec_enc_attn_bias: (batch_size, n
(dec_input,
enc_output,
dec_slf_attn_bias,
dec_enc_attn_bias,
n_layer,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
prepostprocess_dropout,
attention_dropout,
relu_dropout,
hidden_act,
preprocess_cmd,
postprocess_cmd,
caches=None,
gather_idx=None,
param_initializer=None,
name='transformer_decoder')
| 128 | |
| 129 | |
| 130 | def transformer_decoder(dec_input, |
| 131 | enc_output, |
| 132 | dec_slf_attn_bias, |
| 133 | dec_enc_attn_bias, |
| 134 | n_layer, |
| 135 | n_head, |
| 136 | d_key, |
| 137 | d_value, |
| 138 | d_model, |
| 139 | d_inner_hid, |
| 140 | prepostprocess_dropout, |
| 141 | attention_dropout, |
| 142 | relu_dropout, |
| 143 | hidden_act, |
| 144 | preprocess_cmd, |
| 145 | postprocess_cmd, |
| 146 | caches=None, |
| 147 | gather_idx=None, |
| 148 | param_initializer=None, |
| 149 | name='transformer_decoder'): |
| 150 | """ |
| 151 | The decoder is composed of a stack of identical decoder_layer layers. |
| 152 | :param dec_input: (batch_size, tgt_len, emb_dim) |
| 153 | :param enc_output: (batch_size, n_tokens, emb_dim) |
| 154 | :param dec_slf_attn_bias: (batch_size, n_head, tgt_len, tgt_len) |
| 155 | :param dec_enc_attn_bias: (batch_size, n_head, tgt_len, n_tokens) |
| 156 | """ |
| 157 | for i in range(n_layer): |
| 158 | # (batch_size, tgt_len, emb_dim) |
| 159 | dec_output = transformer_decoder_layer( |
| 160 | dec_input=dec_input, |
| 161 | enc_output=enc_output, |
| 162 | slf_attn_bias=dec_slf_attn_bias, |
| 163 | dec_enc_attn_bias=dec_enc_attn_bias, |
| 164 | n_head=n_head, |
| 165 | d_key=d_key, |
| 166 | d_value=d_value, |
| 167 | d_model=d_model, |
| 168 | d_inner_hid=d_inner_hid, |
| 169 | prepostprocess_dropout=prepostprocess_dropout, |
| 170 | attention_dropout=attention_dropout, |
| 171 | relu_dropout=relu_dropout, |
| 172 | hidden_act=hidden_act, |
| 173 | preprocess_cmd=preprocess_cmd, |
| 174 | postprocess_cmd=postprocess_cmd, |
| 175 | cache=None if caches is None else caches[i], |
| 176 | gather_idx=gather_idx, |
| 177 | param_initializer=param_initializer, |
| 178 | name=name + '_layer_' + str(i)) |
| 179 | |
| 180 | dec_input = dec_output |
| 181 | |
| 182 | # add layer normalization |
| 183 | dec_output = pre_process_layer(out=dec_output, |
| 184 | process_cmd=preprocess_cmd, |
| 185 | dropout_rate=prepostprocess_dropout, |
| 186 | name=name + '_post') |
| 187 |
nothing calls this directly
no test coverage detected