# tf.tpu.experimental.DeviceAssignment

<br />

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

Mapping from logical cores in a computation to the physical TPU topology.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.tpu.experimental.DeviceAssignment`](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/DeviceAssignment)

<br />

    tf.tpu.experimental.DeviceAssignment(
        topology: https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/Topology,
        core_assignment: np.ndarray
    )

Prefer to use the [`DeviceAssignment.build()`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/DeviceAssignment#build) helper to construct a
`DeviceAssignment`; it is easier if less flexible than constructing a
`DeviceAssignment` directly.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `topology` | A `Topology` object that describes the physical TPU topology. |
| `core_assignment` | A logical to physical core mapping, represented as a rank 3 numpy array. See the description of the `core_assignment` property for more details. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `topology` is not `Topology` object. |
| `ValueError` | If `core_assignment` is not a rank 3 numpy array. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `core_assignment` | The logical to physical core mapping. |
| `num_cores_per_replica` | The number of cores per replica. |
| `num_replicas` | The number of replicas of the computation. |
| `topology` | A `Topology` that describes the TPU topology. |

<br />

## Methods

### `build`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L185-L200)

    @classmethod
    build(
        topology: https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/Topology,
        computation_shape: Optional[np.ndarray] = None,
        computation_stride: Optional[np.ndarray] = None,
        num_replicas: int = 1,
        device_order_mode: https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/DeviceOrderMode = DeviceOrderMode.AUTO
    ) -> 'DeviceAssignment'

### `coordinates`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L140-L142)

    coordinates(
        replica: int, logical_core: int
    ) -> Tuple

Returns the physical topology coordinates of a logical core.

### `host_device`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L169-L175)

    host_device(
        replica: int = 0, logical_core: int = 0, job: Optional[str] = None
    ) -> str

Returns the CPU device attached to a logical core.

### `lookup_replicas`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L144-L162)

    lookup_replicas(
        task_id: int, logical_core: int
    ) -> List[int]

Lookup replica ids by task number and logical core.

<br />

<br />

<br />

| Args ||
|---|---|
| `task_id` | TensorFlow task number. |
| `logical_core` | An integer, identifying a logical core. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A sorted list of the replicas that are attached to that task and logical_core. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If no replica exists in the task which contains the logical core. |

<br />

### `tpu_device`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L177-L183)

    tpu_device(
        replica: int = 0, logical_core: int = 0, job: Optional[str] = None
    ) -> str

Returns the name of the TPU device assigned to a logical core.

### `tpu_ordinal`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/device_assignment.py#L164-L167)

    tpu_ordinal(
        replica: int = 0, logical_core: int = 0
    ) -> int

Returns the ordinal of the TPU device assigned to a logical core.