MCPcopy Create free account
hub / github.com/google-research/language / tile_batch

Function tile_batch

language/capwap/utils/tensor_utils.py:102–122  ·  view source on GitHub ↗

Tile the batch dimension of a (possibly nested structure of) tensor(s) t. Args: t: Tensor shaped [batch_size, ...] multiplier: Returns: A possibly nested structure of Tensor shaped [batch_size * multipler, ...]

(t, multiplier)

Source from the content-addressed store, hash-verified

100
101
102def tile_batch(t, multiplier):
103 """Tile the batch dimension of a (possibly nested structure of) tensor(s) t.
104
105 Args:
106 t: Tensor shaped [batch_size, ...]
107 multiplier: <int32>
108
109 Returns:
110 A possibly nested structure of Tensor shaped [batch_size * multipler, ...]
111 """
112
113 def _tile_batch(t, multiplier):
114 """Core single-tensor implementation of tile_batch."""
115 tensor = tf.convert_to_tensor(t)
116 tensor = tf.expand_dims(tensor, axis=1)
117 tile_dims = [1] * tensor.shape.ndims
118 tile_dims[1] = multiplier
119 tiled = tf.tile(tensor, tile_dims)
120 return tf.reshape(tiled, [-1] + shape(tensor)[2:])
121
122 return tf.nest.map_structure(lambda t_: _tile_batch(t_, multiplier), t)
123
124
125def gather(src, indices):

Callers

nothing calls this directly

Calls 1

_tile_batchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…