我们能否看到tensorflow GraphDef中的发送节点和接收节点,或者使用python?
我尝试下面的代码
import tensorflow as tf
with tf.device("/gpu:0"):
x = tf.constant(1.0)
with tf.device("/gpu:1"):
y = tf.constant(2.0)
with tf.device("/cpu:0"):
sum = tf.add(x, y)
graph_def = tf.get_default_graph().as_graph_def()
print(graph_def)
但是graph_def
中没有发送/recv节点。是否向图中添加了发送/recv节点,以便将x
和y
传输到cpu
发布于 2016-11-01 12:59:56
在第一次尝试执行图时,发送节点和recv节点仅在调用tf.Session.run()
时才被添加到图中.实际上,所添加的发送和recv节点集将取决于您在该调用中输入和获取的特定张量。
通过将tf.RunOptions(output_partition_graphs=True)
传递给Session.run()
调用,您可以看到在每个设备上执行的精确图,包括发送节点和recv节点,如下所示:
options = tf.RunOptions(output_partition_graphs=True)
metadata = tf.RunMetadata()
sess.run(..., options=options, metadata=metadata)
for partition_graph_def in metadata.partition_graphs:
print partition_graph_def # Contains all the nodes that ran on a single device.
https://stackoverflow.com/questions/40347592
复制相似问题