# tf.experimental.dtensor.call_with_layout

<br />

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

Calls a function in the DTensor device scope if `layout` is not None.

    tf.experimental.dtensor.call_with_layout(
        fn: Callable[..., Any],
        layout: Optional[https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/experimental/dtensor/Layout],
        *args,
        **kwargs
    ) -> Any

If `layout` is not None, `fn` consumes DTensor(s) as input and produces a
DTensor as output; a DTensor is a tf.Tensor with layout-related attributes.

If `layout` is None, `fn` consumes and produces regular tf.Tensors.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `fn` | A supported TF API function such as tf.zeros. |
| `layout` | Optional, the layout of the output DTensor. |
| `*args` | Arguments given to `fn`. |
| `**kwargs` | Keyword arguments given to `fn`. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The return value of `fn` transformed to a DTensor if requested. ||

<br />