我正在使用Jupyter Notebook编写分布式Tensorflow代码。我想确保我的操作放在正确的设备上。我想以某种方式检查已分配给哪些设备的操作。我知道这可以使用Tensorboard,但我希望有一种方法可以使用Python。
答案 0 :(得分:1)
直接引用Tensorflow文档:
要了解您的操作和张量分配到哪些设备, 使用log_device_placement配置选项集创建会话 真实。
foreach(nameof(var t) in ....)
您应该看到以下输出:
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))