(word_ids,
step,
memory,
memory_sequence_length,
my_cache,
op_self_cache,
op_mem_cache,
embedding_table,
decoding_args,
decoder_type,
sequence_lengths)
| 95 | return ids, lengths |
| 96 | |
| 97 | def decoding_body(word_ids, |
| 98 | step, |
| 99 | memory, |
| 100 | memory_sequence_length, |
| 101 | my_cache, |
| 102 | op_self_cache, |
| 103 | op_mem_cache, |
| 104 | embedding_table, |
| 105 | decoding_args, |
| 106 | decoder_type, |
| 107 | sequence_lengths): |
| 108 | |
| 109 | decoder_args = decoding_args.decoder_args |
| 110 | hidden_dim = decoder_args.hidden_dim |
| 111 | k_init_range = decoder_args.kernel_init_range |
| 112 | data_type = decoder_args.dtype |
| 113 | |
| 114 | batchxbeam = tf.shape(word_ids)[0] |
| 115 | # [batch_size * beam_width, hidden_dim] |
| 116 | inputs = tf.nn.embedding_lookup(embedding_table, word_ids) |
| 117 | # [batch_size * beam_width, 1, hidden_dim] |
| 118 | inputs = tf.expand_dims(inputs, 1) |
| 119 | |
| 120 | inputs *= hidden_dim**0.5 |
| 121 | position_encoder = SinusoidalPositionEncoder() |
| 122 | if position_encoder is not None: |
| 123 | position_encoding_table = position_encoder._create_position_encoding_table(decoding_args.max_seq_len, hidden_dim, data_type) |
| 124 | position_encoding_val = position_encoding_table[step] |
| 125 | position_encoding_val = tf.reshape(position_encoding_val, [1, 1, -1]) |
| 126 | position_encoding_val = tf.tile(position_encoding_val, [batchxbeam, 1, 1]) |
| 127 | inputs = inputs + position_encoding_val |
| 128 | |
| 129 | with tf.variable_scope("decoder", reuse=tf.AUTO_REUSE): |
| 130 | tf_result = tf_decoder(decoder_args=decoder_args, |
| 131 | inputs=inputs, |
| 132 | memory=memory, |
| 133 | memory_sequence_length=memory_sequence_length, |
| 134 | step=step, |
| 135 | cache=my_cache) |
| 136 | |
| 137 | if decoder_type != 0: |
| 138 | decoder_vars = tf.global_variables() |
| 139 | decoder_vars_start_id = 0 |
| 140 | while decoder_vars_start_id < len(decoder_vars): |
| 141 | if decoder_vars[decoder_vars_start_id].name.find("transformer/decoder/layer") != -1: |
| 142 | break |
| 143 | decoder_vars_start_id += 1 |
| 144 | decoder_vars = decoder_vars[decoder_vars_start_id:] |
| 145 | decoder_var_dict = {} |
| 146 | for v in decoder_vars: |
| 147 | decoder_var_dict[v.name] = v |
| 148 | |
| 149 | psuedo_input = [] |
| 150 | if decoder_type == 2: |
| 151 | psuedo_input = tf_result |
| 152 | |
| 153 | op_result, op_self_cache, op_mem_cache = op_decoder(inputs, |
| 154 | memory, |
no test coverage detected