TensorFlow中设备过滤器的格式是什么?

时间:2015-11-12 17:59:20

标签: python tensorflow

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

// 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作为选项,因为我用它来运行其他模型。

我试过

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

但我仍然将操作分配给gpu 0.我不想基于每个操作覆盖设备。

1 个答案:

答案 0 :(得分:4)

TensorFlow目前忽略ConfigProto.device_filters字段,但它打算在将来支持您的用例。如果您希望在/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.
相关问题