tf.config.list_physical_devices
Stay organized with collections
Save and categorize content based on your preferences.
Return a list of physical devices visible to the host runtime.
tf.config.list_physical_devices(
device_type=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
Physical devices are hardware devices present on the host machine. By default
all discovered CPU and GPU devices are considered visible.
This API allows querying the physical hardware resources prior to runtime
initialization. Thus, giving an opportunity to call any additional
configuration APIs. This is in contrast to tf.config.list_logical_devices
,
which triggers runtime initialization in order to list the configured devices.
The following example lists the number of visible GPUs on the host.
physical_devices = tf.config.list_physical_devices('GPU')
print("Num GPUs:", len(physical_devices))
Num GPUs: ...
However, the number of GPUs available to the runtime may change during runtime
initialization due to marking certain devices as not visible or configuring
multiple logical devices.
Args |
device_type
|
(optional string) Only include devices matching this device
type. For example "CPU" or "GPU".
|
Notes
|
- If provided with any numerical values or any string other than
supported device type such as 'CPU' it returns an empty list instead of
raising error. 2. For default value it returns all physical devices
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.config.list_physical_devices\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/framework/config.py#L424-L458) |\n\nReturn a list of physical devices visible to the host runtime.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.config.experimental.list_physical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_physical_devices)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.config.experimental.list_physical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_physical_devices), [`tf.compat.v1.config.list_physical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_physical_devices)\n\n\u003cbr /\u003e\n\n tf.config.list_physical_devices(\n device_type=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Use a GPU](https://www.tensorflow.org/guide/gpu) - [TensorFlow basics](https://www.tensorflow.org/guide/basics) - [Distributed training with Core APIs and DTensor](https://www.tensorflow.org/guide/core/distribution) - [Distributed training with TensorFlow](https://www.tensorflow.org/guide/distributed_training) - [DTensor concepts](https://www.tensorflow.org/guide/dtensor_overview) | - [Customization basics: tensors and operations](https://www.tensorflow.org/tutorials/customization/basics) - [Custom layers](https://www.tensorflow.org/tutorials/customization/custom_layers) - [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) - [Distributed Input](https://www.tensorflow.org/tutorials/distribute/input) |\n\nPhysical devices are hardware devices present on the host machine. By default\nall discovered CPU and GPU devices are considered visible.\n\nThis API allows querying the physical hardware resources prior to runtime\ninitialization. Thus, giving an opportunity to call any additional\nconfiguration APIs. This is in contrast to [`tf.config.list_logical_devices`](../../tf/config/list_logical_devices),\nwhich triggers runtime initialization in order to list the configured devices.\n\nThe following example lists the number of visible GPUs on the host. \n\n physical_devices = tf.config.list_physical_devices('GPU')\n print(\"Num GPUs:\", len(physical_devices))\n Num GPUs: ...\n\nHowever, the number of GPUs available to the runtime may change during runtime\ninitialization due to marking certain devices as not visible or configuring\nmultiple logical devices.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `device_type` | (optional string) Only include devices matching this device type. For example \"CPU\" or \"GPU\". |\n| `Notes` | \u003cbr /\u003e 1. If provided with any numerical values or any string other than supported device type such as 'CPU' it returns an empty list instead of raising error. 2. For default value it returns all physical devices |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| List of discovered [`tf.config.PhysicalDevice`](../../tf/config/PhysicalDevice) objects ||\n\n\u003cbr /\u003e"]]