所以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.
Run Code Online (Sandbox Code Playgroud)
有没有人对格式有具体的解释?例如,我想排除/ gpu:0作为选项,因为我用它来运行其他模型.
我试过了
config = tf.ConfigProto()
config.device_filters.append('/gpu:1')
config.device_filters.append('/cpu:0')
with tf.Session(config=config):
# Do stuff
Run Code Online (Sandbox Code Playgroud)
但是我仍然将操作分配给gpu 0.我不想在每个操作的基础上覆盖设备.
该ConfigProto.device_filters
字段目前被 TensorFlow 忽略,但它旨在支持您未来的用例。如果你想达到上运行OPS的同一端/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.
Run Code Online (Sandbox Code Playgroud)