Builds a graph operator that runs a replicated TPU computation. Args: computation: A Python function that builds the computation to replicate. inputs: A list of lists of input tensors or `None` (equivalent to `[[]]`), indexed by `[replica_num][input_num]`. All replicas must ha
(computation,
inputs=None,
infeed_queue=None,
device_assignment=None,
name=None,
maximum_shapes=None)
| 577 | |
| 578 | @tf_export(v1=["tpu.replicate"]) |
| 579 | def replicate(computation, |
| 580 | inputs=None, |
| 581 | infeed_queue=None, |
| 582 | device_assignment=None, |
| 583 | name=None, |
| 584 | maximum_shapes=None): |
| 585 | """Builds a graph operator that runs a replicated TPU computation. |
| 586 | |
| 587 | Args: |
| 588 | computation: A Python function that builds the computation to replicate. |
| 589 | inputs: A list of lists of input tensors or `None` (equivalent to |
| 590 | `[[]]`), indexed by `[replica_num][input_num]`. All replicas must |
| 591 | have the same number of inputs. Each input can be a nested structure |
| 592 | containing values that are convertible to tensors. Note that passing an |
| 593 | N-dimension list of compatible values will result in a N-dimension list of |
| 594 | scalar tensors rather than a single Rank-N tensors. If you need different |
| 595 | behavior, convert part of inputs to tensors with `tf.convert_to_tensor`. |
| 596 | infeed_queue: If not `None`, the `InfeedQueue` from which to append a tuple |
| 597 | of arguments as inputs to computation. |
| 598 | device_assignment: If not `None`, a `DeviceAssignment` describing the |
| 599 | mapping between logical cores in the computation with physical cores in |
| 600 | the TPU topology. Uses a default device assignment if `None`. The |
| 601 | `DeviceAssignment` may be omitted if each replica of the computation uses |
| 602 | only one core, and there is either only one replica, or the number of |
| 603 | replicas is equal to the number of cores in the TPU system. |
| 604 | name: (Deprecated) Does nothing. |
| 605 | maximum_shapes: A nested structure of tf.TensorShape representing the shape |
| 606 | to which the respective component of each input element in each replica |
| 607 | should be padded. Any unknown dimensions (e.g. |
| 608 | tf.compat.v1.Dimension(None) in a tf.TensorShape or -1 in a tensor-like |
| 609 | object) will be padded to the maximum size of that dimension over all |
| 610 | replicas. The structure of `maximum_shapes` needs to be the same as |
| 611 | `inputs[0]`. |
| 612 | Returns: |
| 613 | A list of outputs, indexed by `[replica_num]` each output can be a nested |
| 614 | structure same as what computation() returns with a few exceptions. |
| 615 | |
| 616 | Exceptions include: |
| 617 | 1) None output: a NoOp would be returned which control-depends on |
| 618 | computation. |
| 619 | 2) Single value output: A tuple containing the value would be returned. |
| 620 | 3) Operation-only outputs: a NoOp would be returned which |
| 621 | control-depends on computation. |
| 622 | TODO(b/121383831): Investigate into removing these special cases. |
| 623 | |
| 624 | Raises: |
| 625 | ValueError: If all replicas do not have equal numbers of input tensors. |
| 626 | ValueError: If the number of inputs per replica does not match |
| 627 | the number of formal parameters to `computation`. |
| 628 | ValueError: If the static `inputs` dimensions don't match with the values |
| 629 | given in `maximum_shapes`. |
| 630 | ValueError: If the structure of inputs per replica does not match |
| 631 | the structure of `maximum_shapes`. |
| 632 | """ |
| 633 | return split_compile_and_replicate( |
| 634 | computation, |
| 635 | inputs, |
| 636 | infeed_queue, |
no test coverage detected