<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/dtensor/python/api.py#L167-L188) |

Copies a tf.Tensor onto the DTensor device with the given layout.

    tf.experimental.dtensor.copy_to_mesh(
        tensor: Any,
        layout: https://www.tensorflow.org/api_docs/python/tf/experimental/dtensor/Layout,
        source_layout: Optional[https://www.tensorflow.org/api_docs/python/tf/experimental/dtensor/Layout] = None
    ) -> https://www.tensorflow.org/api_docs/python/tf/Tensor

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [DTensor concepts](https://www.tensorflow.org/guide/dtensor_overview) | - [Using DTensors with Keras](https://www.tensorflow.org/tutorials/distribute/dtensor_keras_tutorial) - [Distributed training with DTensors](https://www.tensorflow.org/tutorials/distribute/dtensor_ml_tutorial) |

Copies a regular tf.Tensor onto the DTensor device. Use the mesh attached to
`layout` as target mesh. This method currently only supports replicated
layouts, or one-to-one copies for sharded layouts.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensor` | A regular tf.Tensor to be copied as a DTensor. |
| `layout` | Target layout (and mesh) for the result DTensor. |
| `source_layout` | Source layout of the tensor before copy. This argument is deprecated. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A DTensor on the DTensor device with the given layout. ||

<br />