MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / _body

Function _body

examples/tensorflow/decoder/utils/decoding.py:247–285  ·  view source on GitHub ↗
(word_ids, cum_log_probs, finished, step, outputs, my_cache, extra_vars, op_self_cache, op_mem_cache)

Source from the content-addressed store, hash-verified

245 return tf.reduce_any(tf.logical_not(finished))
246
247 def _body(word_ids, cum_log_probs, finished, step, outputs, my_cache, extra_vars, op_self_cache, op_mem_cache):
248 logits, my_cache, op_self_cache, op_mem_cache = decoding_body(word_ids,
249 step,
250 extended_memory,
251 extended_memory_sequence_length,
252 my_cache,
253 op_self_cache,
254 op_mem_cache,
255 embedding_table,
256 decoding_args,
257 decoder_type,
258 extra_vars[1])
259
260 end_ids = tf.fill([tf.shape(logits)[0]], decoding_args.end_id) # [batch_size * beam_width]
261 eos_max_prob = tf.one_hot(end_ids, decoding_args.vocab_size,
262 on_value=decoder_args.dtype.max,
263 off_value=decoder_args.dtype.min) # [batch_size * beam_width, vocab_size]
264
265 # [batch_size * beam_width, vocab_size]
266 logits = tf.where(finished, x=eos_max_prob, y=logits)
267 logits = tf.cast(logits, tf.float32)
268
269 output_id, next_cum_log_probs, finished, my_cache, \
270 extra_vars, op_self_cache = search_word(beam_width,
271 decoding_args.vocab_size,
272 step,
273 logits,
274 cum_log_probs,
275 finished,
276 my_cache,
277 extra_vars,
278 op_self_cache,
279 search_method=search_method)
280 cum_log_probs = tf.where(finished, x=cum_log_probs, y=next_cum_log_probs)
281
282 outputs = outputs.write(step, output_id)
283 finished = tf.logical_or(finished, tf.equal(output_id, decoding_args.end_id))
284
285 return output_id, cum_log_probs, finished, step + 1, outputs, my_cache, extra_vars, op_self_cache, op_mem_cache
286
287 # initialization
288 batchxbeam = tf.shape(extended_memory)[0]

Callers

nothing calls this directly

Calls 4

sampleMethod · 0.95
search_wordFunction · 0.90
SamplingClass · 0.90
decoding_bodyFunction · 0.85

Tested by

no test coverage detected