# tf.compat.v1.tpu.rewrite

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/tpu/tpu.py#L1430-L1489) |

Rewrites `computation` for execution on a TPU system.

    tf.compat.v1.tpu.rewrite(
        computation: Callable[..., Any],
        inputs: Optional[List[List[Optional[core_types.Tensor]]]] = None,
        infeed_queue: Optional[tpu_feed.InfeedQueue] = None,
        device_assignment: Optional[https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/tpu/experimental/DeviceAssignment] = None,
        name: Optional[Text] = None,
        xla_options: Optional[https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/tpu/XLAOptions] = None
    ) -> Any

<br />

<br />

<br />

| ## 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. <br /> `computation` may return a list of operations and tensors. Tensors must come before operations in the returned list. The return value of `rewrite` is a list of tensors corresponding to the tensors from the output of `computation`. All `Operation`s constructed during `computation` will be executed when evaluating any of the returned output tensors, not just the ones returned. |
| `inputs` | A list of input tensors or `None` (equivalent to an empty list). Each input can be a nested structure containing values that are convertible to tensors. Note that passing an N-dimension list of compatible values will result in a N-dimension list of scalar tensors rather than a single Rank-N tensors. If you need different behavior, convert part of inputs to tensors with [`tf.convert_to_tensor`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/convert_to_tensor). |
| `infeed_queue` | If not `None`, the `InfeedQueue` from which to append a tuple of arguments as inputs to `computation`. |
| `device_assignment` | if not `None`, a `DeviceAssignment` describing the mapping between logical cores in the computation with physical cores in the TPU topology. May be omitted for a single-core computation, in which case the core attached to task 0, TPU device 0 is used. |
| `name` | (Deprecated) Does nothing. |
| `xla_options` | An instance of [`tpu.XLAOptions`](https://www.tensorflow.org/api_docs/python/tf/tpu/XLAOptions) which indicates the options passed to XLA compiler. Use `None` for default options. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Same data structure as if computation(\*inputs) is called directly with some exceptions for correctness. Exceptions include: <br /> 1) None output: a NoOp would be returned which control-depends on computation. 2) Single value output: A tuple containing the value would be returned. 3) Operation-only outputs: a NoOp would be returned which control-depends on computation. ||

<br />