tf.config.experimental.set_virtual_device_configuration
Устанавливает конфигурацию виртуального устройства для PhysicalDevice.
tf.config.experimental.set_virtual_device_configuration(
device, virtual_devices
)
PhysicalDevice, помеченный как видимый, по умолчанию будет иметь один LogicalDevice, выделенный для него после настройки среды выполнения. Указание списка объектов tf.config.experimental.VirtualDeviceConfiguration позволяет настроить несколько устройств, использующих один и тот же PhysicalDevice.
Следующий пример разделяет процессор на 2 виртуальных устройства:
physical_devices = tf.config.experimental.list_physical_devices('CPU')
assert len(physical_devices) == 1, "No CPUs found"
# Specify 2 virtual CPUs. Note currently memory limit is not supported.
tf.config.experimental.set_virtual_device_configuration(
physical_devices[0],
[tf.config.experimental.VirtualDeviceConfiguration(),
tf.config.experimental.VirtualDeviceConfiguration()])
logical_devices = tf.config.experimental.list_logical_devices('CPU')
assert len(logical_devices) == 2
try:
tf.config.experimental.set_virtual_device_configuration(
physical_devices[0],
[tf.config.experimental.VirtualDeviceConfiguration(),
tf.config.experimental.VirtualDeviceConfiguration(),
tf.config.experimental.VirtualDeviceConfiguration(),
tf.config.experimental.VirtualDeviceConfiguration()])
except:
print('Cannot modify the virtual devices once they have been initialized.')
Следующий пример разделяет графический процессор на 2 виртуальных устройства по 100 МБ каждое:
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "No GPUs found"
tf.config.experimental.set_virtual_device_configuration(
physical_devices[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=100),
tf.config.experimental.VirtualDeviceConfiguration(memory_limit=100)])
try:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
except:
print('Cannot set memory growth when virtual devices configured')
logical_devices = tf.config.experimental.list_logical_devices('GPU')
assert len(logical_devices) == len(physical_devices) + 1
try:
tf.config.experimental.set_virtual_device_configuration(
physical_devices[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=10),
tf.config.experimental.VirtualDeviceConfiguration(memory_limit=10)])
except:
print('Cannot modify the virtual devices once they have been initialized.')
| Аргументы | |
|---|---|
device | (необязательно) Требуется обновление |
virtual_devices | (необязательно) Требуется обновление |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/config/experimental/set_virtual_device_configuration