# tf_agents.utils.common.soft_device_placement

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/common.py#L1488-L1504) |

Context manager for soft device placement, allowing summaries on CPU.

    @contextlib.contextmanager
    tf_agents.utils.common.soft_device_placement()

Eager and graph contexts have different default device placements. See
b/148408921 for details. This context manager should be used whenever using
summary writers contexts to make sure summaries work when executing on TPUs.

<br />

<br />

<br />

| ## Yields ||
|---|---|
| Sets [`tf.config.set_soft_device_placement(True)`](https://www.tensorflow.org/api_docs/python/tf/config/set_soft_device_placement) within the context ||

<br />