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

Function split_heads

examples/tensorflow/decoder/utils/decoder.py:33–48  ·  view source on GitHub ↗

Splits a tensor in depth. Args: inputs: A ``tf.Tensor`` of shape :math:`[B, T, D]`. num_heads: The number of heads :math:`H`. Returns: A ``tf.Tensor`` of shape :math:`[B, H, T, D / H]`.

(inputs, num_heads)

Source from the content-addressed store, hash-verified

31
32
33def split_heads(inputs, num_heads):
34 """Splits a tensor in depth.
35
36 Args:
37 inputs: A ``tf.Tensor`` of shape :math:`[B, T, D]`.
38 num_heads: The number of heads :math:`H`.
39
40 Returns:
41 A ``tf.Tensor`` of shape :math:`[B, H, T, D / H]`.
42 """
43 static_shape = inputs.get_shape().as_list()
44 depth = static_shape[-1]
45 outputs = tf.reshape(
46 inputs, [tf.shape(inputs)[0], tf.shape(inputs)[1], num_heads, depth // num_heads])
47 outputs = tf.transpose(outputs, perm=[0, 2, 1, 3])
48 return outputs
49
50
51def build_sequence_mask(sequence_length,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected