gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:07:02 25 4
gpt4 key购买 nike

因此 session 配置原型(prototype)有一个 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。我不想在每个操作的基础上覆盖设备。

最佳答案

ConfigProto.device_filters 字段目前被 TensorFlow 忽略,尽管它旨在支持您将来的用例。如果你想在 /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.

关于python - TensorFlow 中设备过滤器的格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33678180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com