<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/framework/config.py#L741-L766) |

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
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Use a GPU](https://www.tensorflow.org/guide/gpu) - [Import a JAX model using JAX2TF](https://www.tensorflow.org/guide/jax2tf) - [Using the SavedModel format](https://www.tensorflow.org/guide/saved_model) | - [Universal Sentence Encoder SentEval demo](https://www.tensorflow.org/hub/tutorials/senteval_for_universal_sentence_encoder_cmlm) - [Bayesian Gaussian Mixture Model and Hamiltonian MCMC](https://www.tensorflow.org/probability/examples/Bayesian_Gaussian_Mixture_Model) - [Modeling COVID-19 spread in Europe and the effect of interventions](https://www.tensorflow.org/probability/examples/Estimating_COVID_19_in_11_European_countries) |

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 />