Rewrites `computation` for execution on a TPU system. Args: computation: A Python function that builds a computation to apply to the input. If the function takes n inputs, 'inputs' should be a list of n tensors. `computation` may return a list of operations and tensors. Ten
(computation,
inputs=None,
infeed_queue=None,
device_assignment=None,
name=None)
| 1463 | |
| 1464 | @tf_export(v1=["tpu.rewrite"]) |
| 1465 | def rewrite(computation, |
| 1466 | inputs=None, |
| 1467 | infeed_queue=None, |
| 1468 | device_assignment=None, |
| 1469 | name=None): |
| 1470 | """Rewrites `computation` for execution on a TPU system. |
| 1471 | |
| 1472 | Args: |
| 1473 | computation: A Python function that builds a computation to apply to the |
| 1474 | input. If the function takes n inputs, 'inputs' should be a list of n |
| 1475 | tensors. |
| 1476 | |
| 1477 | `computation` may return a list of operations and tensors. Tensors must |
| 1478 | come before operations in the returned list. The return value of |
| 1479 | `rewrite` is a list of tensors corresponding to the tensors from the |
| 1480 | output of `computation`. |
| 1481 | |
| 1482 | All `Operation`s constructed during `computation` will be executed when |
| 1483 | evaluating any of the returned output tensors, not just the ones returned. |
| 1484 | inputs: A list of input tensors or `None` (equivalent to an empty list). |
| 1485 | Each input can be a nested structure containing values that are |
| 1486 | convertible to tensors. Note that passing an N-dimension list of |
| 1487 | compatible values will result in a N-dimention list of scalar tensors |
| 1488 | rather than a single Rank-N tensors. If you need different behavior, |
| 1489 | convert part of inputs to tensors with `tf.convert_to_tensor`. |
| 1490 | infeed_queue: If not `None`, the `InfeedQueue` from which to append a tuple |
| 1491 | of arguments as inputs to `computation`. |
| 1492 | device_assignment: if not `None`, a `DeviceAssignment` describing the |
| 1493 | mapping between logical cores in the computation with physical cores in |
| 1494 | the TPU topology. May be omitted for a single-core computation, in which |
| 1495 | case the core attached to task 0, TPU device 0 is used. |
| 1496 | name: (Deprecated) Does nothing. |
| 1497 | Returns: |
| 1498 | Same data structure as if computation(*inputs) is called directly with some |
| 1499 | exceptions for correctness. Exceptions include: |
| 1500 | 1) None output: a NoOp would be returned which control-depends on |
| 1501 | computation. |
| 1502 | 2) Single value output: A tuple containing the value would be returned. |
| 1503 | 3) Operation-only outputs: a NoOp would be returned which |
| 1504 | control-depends on computation. |
| 1505 | TODO(b/121383831): Investigate into removing these special cases. |
| 1506 | """ |
| 1507 | # TODO(b/36647078) remove disable when pylint bug is fixed. |
| 1508 | # pylint: disable=indexing-exception |
| 1509 | return replicate( |
| 1510 | computation, |
| 1511 | None if inputs is None else [inputs], |
| 1512 | infeed_queue=infeed_queue, |
| 1513 | device_assignment=device_assignment, |
| 1514 | name=name)[0] |
| 1515 | # pylint: enable=indexing-exception |
| 1516 | |
| 1517 | # Operations that indicate some error in the user's inference graph. |
| 1518 | _BLACKLISTED_INFERENCE_OPS = set([ |
| 1519 | "ReadVariableOp", |
| 1520 | "AssignVariableOp", |
no test coverage detected