MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / shard

Function shard

tensorflow/python/tpu/tpu.py:1327–1404  ·  view source on GitHub ↗

Shards `computation` for parallel execution. `inputs` must be a list of Tensors or None (equivalent to an empty list), each of which has a corresponding split axis (from `input_shard_axes`). Each input is split into `num_shards` pieces along the corresponding axis, and computation is applie

(computation,
          inputs=None,
          num_shards=1,
          input_shard_axes=None,
          outputs_from_all_shards=True,
          output_shard_axes=None,
          infeed_queue=None,
          device_assignment=None,
          name=None)

Source from the content-addressed store, hash-verified

1325
1326@tf_export(v1=["tpu.shard"])
1327def shard(computation,
1328 inputs=None,
1329 num_shards=1,
1330 input_shard_axes=None,
1331 outputs_from_all_shards=True,
1332 output_shard_axes=None,
1333 infeed_queue=None,
1334 device_assignment=None,
1335 name=None):
1336 """Shards `computation` for parallel execution.
1337
1338 `inputs` must be a list of Tensors or None (equivalent to an empty list), each
1339 of which has a corresponding split axis (from `input_shard_axes`). Each input
1340 is split into `num_shards` pieces along the corresponding axis, and
1341 computation is applied to each shard in parallel.
1342
1343 Tensors are broadcast to all shards if they are lexically captured by
1344 `computation`. e.g.,
1345
1346 x = tf.constant(7)
1347 def computation():
1348 return x + 3
1349 ... = shard(computation, ...)
1350
1351 TODO(phawkins): consider adding support for broadcasting Tensors passed
1352 as inputs.
1353
1354 If `outputs_from_all_shards` is true, the outputs from all shards of
1355 `computation` are concatenated back together along their `output_shards_axes`.
1356 Otherwise, each output is taken from an arbitrary shard.
1357
1358 Inputs and outputs of the computation must be at least rank-1 Tensors.
1359
1360 Args:
1361 computation: A Python function that builds a computation to apply to each
1362 shard of the input.
1363 inputs: A list of input tensors or None (equivalent to an empty list). Each
1364 input tensor has a corresponding shard axes, given by `input_shard_axes`,
1365 which must have size divisible by `num_shards`.
1366 num_shards: The number of shards.
1367 input_shard_axes: A list of dimensions along which to shard `inputs`, or
1368 `None`. `None` means "shard all inputs along dimension 0". If not `None`,
1369 there must be one dimension per input.
1370 outputs_from_all_shards: Boolean or list of boolean. For each output, if
1371 `True`, outputs from all shards are concatenated along the corresponding
1372 `output_shard_axes` entry. Otherwise, each output is taken
1373 from an arbitrary shard. If the argument is a boolean, the argument's
1374 value is used for each output.
1375 output_shard_axes: A list of dimensions along which to concatenate the
1376 outputs of `computation`, or `None`. `None` means "concatenate all outputs
1377 along dimension 0". If not `None`, there must be one dimension per output.
1378 Ignored if `outputs_from_all_shards` is False.
1379 infeed_queue: If not `None`, the `InfeedQueue` to use to augment the inputs
1380 of `computation`.
1381 device_assignment: If not `None`, a `DeviceAssignment` describing the
1382 mapping between logical cores in the computation with physical cores in
1383 the TPU topology. Uses a default device assignment if `None`. The
1384 `DeviceAssignment` may be omitted if each shard of the computation uses

Callers 1

batch_parallelFunction · 0.85

Calls 1

split_compile_and_shardFunction · 0.85

Tested by

no test coverage detected