The wrapper assembles together all needed layers for the decoder.
(trg_vocab_size,
max_length,
n_layer,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
prepostprocess_dropout,
attention_dropout,
relu_dropout,
preprocess_cmd,
postprocess_cmd,
weight_sharing,
embedding_sharing,
dec_inputs=None,
enc_output=None,
caches=None, is_train=True, params_type="normal")
| 686 | |
| 687 | |
| 688 | def wrap_decoder(trg_vocab_size, |
| 689 | max_length, |
| 690 | n_layer, |
| 691 | n_head, |
| 692 | d_key, |
| 693 | d_value, |
| 694 | d_model, |
| 695 | d_inner_hid, |
| 696 | prepostprocess_dropout, |
| 697 | attention_dropout, |
| 698 | relu_dropout, |
| 699 | preprocess_cmd, |
| 700 | postprocess_cmd, |
| 701 | weight_sharing, |
| 702 | embedding_sharing, |
| 703 | dec_inputs=None, |
| 704 | enc_output=None, |
| 705 | caches=None, is_train=True, params_type="normal"): |
| 706 | """ |
| 707 | The wrapper assembles together all needed layers for the decoder. |
| 708 | """ |
| 709 | if dec_inputs is None: |
| 710 | # This is used to implement independent decoder program in inference. |
| 711 | trg_word, reverse_trg_word, trg_pos, trg_slf_attn_bias, trg_src_attn_bias, enc_output = \ |
| 712 | make_all_inputs(decoder_data_input_fields) |
| 713 | else: |
| 714 | trg_word, reverse_trg_word, trg_pos, trg_slf_attn_bias, trg_src_attn_bias = dec_inputs |
| 715 | |
| 716 | dec_input = prepare_decoder( |
| 717 | trg_word, |
| 718 | trg_pos, |
| 719 | trg_vocab_size, |
| 720 | d_model, |
| 721 | max_length, |
| 722 | prepostprocess_dropout, |
| 723 | word_emb_param_name=word_emb_param_names[0] |
| 724 | if embedding_sharing else word_emb_param_names[1], |
| 725 | training=is_train, |
| 726 | params_type=params_type) |
| 727 | |
| 728 | dec_output = decoder( |
| 729 | dec_input, |
| 730 | enc_output, |
| 731 | trg_slf_attn_bias, |
| 732 | trg_src_attn_bias, |
| 733 | n_layer, |
| 734 | n_head, |
| 735 | d_key, |
| 736 | d_value, |
| 737 | d_model, |
| 738 | d_inner_hid, |
| 739 | prepostprocess_dropout, |
| 740 | attention_dropout, |
| 741 | relu_dropout, |
| 742 | preprocess_cmd, |
| 743 | postprocess_cmd, |
| 744 | caches=caches) |
| 745 | # Reshape to 2D tensor to use GEMM instead of BatchedGEMM |
no test coverage detected