前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tf.config

tf.config

作者头像
狼啸风云
修改2022-09-03 19:30:22
1K0
修改2022-09-03 19:30:22
举报

目录

一、模块和函数

二、experimental模块

1、tf.config.experimental.set_visible_devices

2、tf.config.experimental.list_physical_devices

3、tf.config.experimental.set_memory_growth

4、tf.config.experimental.list_logical_devices


Public API for tf.config namespace.

一、模块和函数

Modules:

  • experimental module: Public API for tf.config.experimental namespace.
  • optimizer module: Public API for tf.config.optimizer namespace.
  • threading module: Public API for tf.config.threading namespace.

Functions:

二、experimental模块

Classes:

Functions:

1、tf.config.experimental.set_visible_devices

Set the list of visible devices.

代码语言:javascript
复制
tf.config.experimental.set_visible_devices(
    devices,
    device_type=None
)

Used in the guide:

Sets the list of PhysicalDevices to be marked as visible to the runtime. Any devices that are not marked as visible means TensorFlow will not allocate memory on it and will not be able to place any operations on it as no LogicalDevice will be created on it. By default all discovered devices are marked as visible.

The following example demonstrates disabling the first GPU on the machine.

代码语言:javascript
复制
physical_devices = config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
# Disable first GPU
tf.config.experimental.set_visible_devices(physical_devices[1:], 'GPU')
logical_devices = config.experimental.list_logical_devices('GPU')
# Logical device was not created for first GPU
assert len(logical_devices) == len(physical_devices) - 1

Args:

  • devices: (optional) List of PhysicalDevice objects to make visible
  • device_type: (optional) Device types to limit visibility configuration to. Other device types will be left unaltered.

Compat aliases

2、tf.config.experimental.list_physical_devices

Return a list of physical devices visible to the runtime.

代码语言:javascript
复制
tf.config.experimental.list_physical_devices(device_type=None)

Used in the guide:

Used in the tutorials:

Physical devices are hardware devices locally present on the current machine. By default all discovered CPU and GPU devices are considered visible. The list_physical_devices allows querying the hardware prior to runtime initialization.

The following example ensures the machine can see at least 1 GPU.

代码语言:javascript
复制
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "No GPUs found."

Args:

  • device_type: (optional) Device type to filter by such as "CPU" or "GPU"

Returns:

  • List of PhysicalDevice objects

Compat aliases

3、tf.config.experimental.set_memory_growth

Set if memory growth should be enabled for a PhysicalDevice.

代码语言:javascript
复制
tf.config.experimental.set_memory_growth(
    device,
    enable
)

Used in the guide:

A PhysicalDevice with memory growth set will not allocate all memory on the device upfront. Memory growth cannot be configured on a PhysicalDevice with virtual devices configured.

For example:

代码语言:javascript
复制
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
tf.config.experimental.set_memory_growth(physical_devices[0], True)

Args:

  • device: PhysicalDevice to configure
  • enable: Whether to enable or disable memory growth

Compat aliases

4、tf.config.experimental.list_logical_devices

Return a list of logical devices created by runtime.

代码语言:javascript
复制
tf.config.experimental.list_logical_devices(device_type=None)

Used in the guide:

Logical devices may correspond to physical devices or remote devices in the cluster. Operations and tensors may be placed on these devices by using the name of the LogicalDevice.

For example:

代码语言:javascript
复制
logical_devices = tf.config.experimental.list_logical_devices('GPU')
# Allocate on GPU:0
with tf.device(logical_devices[0].name):
  one = tf.constant(1)
# Allocate on GPU:1
with tf.device(logical_devices[1].name):
  two = tf.constant(2)

Args:

  • device_type: (optional) Device type to filter by such as "CPU" or "GPU"

Returns:

List of LogicalDevice objects

Compat aliases

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 目录
  • 一、模块和函数
  • 二、experimental模块
    • 1、tf.config.experimental.set_visible_devices
      • 2、tf.config.experimental.list_physical_devices
        • 3、tf.config.experimental.set_memory_growth
          • 4、tf.config.experimental.list_logical_devices
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档