8

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.

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.

I've tried

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

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

4

1 回答 1

5

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

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.
于 2015-11-13T03:10:39.990 回答