# tf.config.experimental.set_memory_growth

<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/framework/config.py#L712-L737) |

Set if memory growth should be enabled for a `PhysicalDevice`.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.config.experimental.set_memory_growth(
        device, enable
    )

If memory growth is enabled for a `PhysicalDevice`, the runtime initialization
will not allocate all memory on the device. Memory growth cannot be configured
on a `PhysicalDevice` with virtual devices configured.

#### For example:

    physical_devices = tf.config.list_physical_devices('GPU')
    try:
      tf.config.experimental.set_memory_growth(physical_devices[0], True)
    except:
      # Invalid device or cannot modify virtual devices once initialized.
      pass

<br />

<br />

<br />

| ## Args ||
|---|---|
| `device` | `PhysicalDevice` to configure |
| `enable` | (Boolean) Whether to enable or disable memory growth |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | Invalid `PhysicalDevice` specified. |
| `RuntimeError` | Runtime is already initialized. |

<br />