設置可見設備列表。
用法
tf.config.set_visible_devices(
devices, device_type=None
)
參數
-
devices
要顯示的PhysicalDevice
列表 -
device_type
(可選)僅配置匹配此設備類型的設備。例如 "CPU" 或 "GPU"。其他設備將保持不變。
拋出
-
ValueError
如果參數驗證失敗。 -
RuntimeError
運行時已經初始化。
指定哪些PhysicalDevice
對象對運行時可見。 TensorFlow 隻會在可見的物理設備上分配內存和放置操作,否則不會在它們上創建 LogicalDevice
。默認情況下,所有發現的設備都標記為可見。
以下示例演示了禁用機器上的第一個 GPU。
physical_devices = tf.config.list_physical_devices('GPU')
try:
# Disable first GPU
tf.config.set_visible_devices(physical_devices[1:], 'GPU')
logical_devices = tf.config.list_logical_devices('GPU')
# Logical device was not created for first GPU
assert len(logical_devices) == len(physical_devices) - 1
except:
# Invalid device or cannot modify virtual devices once initialized.
pass
相關用法
- Python tf.config.set_logical_device_configuration用法及代碼示例
- Python tf.config.list_logical_devices用法及代碼示例
- Python tf.config.experimental.get_memory_usage用法及代碼示例
- Python tf.config.list_physical_devices用法及代碼示例
- Python tf.config.get_logical_device_configuration用法及代碼示例
- Python tf.config.experimental.get_memory_info用法及代碼示例
- Python tf.config.run_functions_eagerly用法及代碼示例
- Python tf.config.experimental.enable_tensor_float_32_execution用法及代碼示例
- Python tf.config.experimental_connect_to_cluster用法及代碼示例
- Python tf.config.experimental.set_memory_growth用法及代碼示例
- Python tf.config.experimental_connect_to_host用法及代碼示例
- Python tf.config.experimental.enable_op_determinism用法及代碼示例
- Python tf.config.get_visible_devices用法及代碼示例
- Python tf.config.experimental.get_device_details用法及代碼示例
- Python tf.config.experimental.ClusterDeviceFilters用法及代碼示例
- Python tf.config.experimental.reset_memory_stats用法及代碼示例
- Python tf.config.experimental.get_memory_growth用法及代碼示例
- Python tf.concat用法及代碼示例
- Python tf.convert_to_tensor用法及代碼示例
- Python tf.constant_initializer.from_config用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.config.set_visible_devices。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。