TensorFlow 中设备过滤器的格式是什么? [英] What is the format for device filters in TensorFlow?

查看:56
本文介绍了TensorFlow 中设备过滤器的格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以 Session config proto 有一个 device_filters 选项,带有注释:

So the Session config proto has a device_filters option, with the comment:

// When any filters are present sessions will ignore all devices which do not
  // match the filters. Each filter can be partially specified, e.g. "/job:ps"
  // "/job:worker/replica:3", etc.

有人对格式有具体的解释吗?例如,我想排除/gpu:0 作为选项,因为我用它来运行其他模型.

Does anyone have concrete explanation of the format? For example, I want to exclude /gpu:0 as an option because I use it for running other models.

我试过了

config = tf.ConfigProto()
config.device_filters.append('/gpu:1')
config.device_filters.append('/cpu:0')
with tf.Session(config=config):
    # Do stuff

但我仍然将操作分配给 gpu 0.我不想在每个操作的基础上覆盖设备.

But I'm still getting ops allocated to gpu 0. I don't want to override the devices on a per-op basis.

推荐答案

ConfigProto.device_filters 字段当前被 TensorFlow 忽略,尽管它旨在支持您将来的用例.如果您想在 /gpu:1/cpu:0 上实现相同的运行操作,您可以使用软放置"执行以下操作:

The ConfigProto.device_filters field is currently ignored by TensorFlow, although it is intended to support your use case in future. If you want to achieve the same end of running ops on /gpu:1 and /cpu:0, you can do that as follows, using "soft placement":

with tf.device("/gpu:1"):
  # Build your model in this with context. All nodes will get the
  # device "/gpu:1".

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)):
  # Execute your mode in this with context.
  # Soft placement will use /gpu:1 for GPU-compatible ops, and /cpu:0
  # for CPU-only ops.

这篇关于TensorFlow 中设备过滤器的格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆