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

Function finalize

examples/tensorflow/decoding/utils/ft_decoding.py:22–41  ·  view source on GitHub ↗
(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None)

Source from the content-addressed store, hash-verified

20from examples.tensorflow.decoder.utils.position import SinusoidalPositionEncoder
21
22def finalize(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None):
23 maximum_lengths = tf.reduce_max(tf.reshape(
24 sequence_lengths, [-1, beam_width]), axis=-1)
25
26 if max_seq_len != None:
27 array_shape = [max_seq_len, -1, beam_width]
28 else:
29 array_shape = [tf.reduce_max(maximum_lengths), -1, beam_width]
30
31 step_ids = tf.reshape(outputs, array_shape)
32 parent_ids = tf.reshape(parent_ids, array_shape)
33
34 ids = tf.contrib.seq2seq.gather_tree(
35 step_ids, parent_ids, maximum_lengths, end_id)
36
37 ids = tf.transpose(ids, perm=[1, 2, 0])
38 lengths = tf.not_equal(ids, end_id)
39 lengths = tf.cast(lengths, tf.int32)
40 lengths = tf.reduce_sum(lengths, axis=-1)
41 return ids, lengths
42
43def ft_decoding(memory_tensor,
44 memory_sequence_length,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected