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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With