我们可以在 tensorflow GraphDef 中看到 Send 节点和 Receive 节点吗? [英] Can we see the Send nodes and the Receive nodes in the tensorflow GraphDef?

查看:26
本文介绍了我们可以在 tensorflow GraphDef 中看到 Send 节点和 Receive 节点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在tensorflow GraphDef中看到Send节点和Receive节点吗,或者使用python API?

Can we see the Send nodes and the Receive nodes in the tensorflow GraphDef, or by using python API?

我试试下面的代码

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 中没有发送/接收节点.是否有任何发送/接收节点添加到图中以将 xy 传输到 cpu?

But there is no send/recv nodes in the graph_def. Are there any send/recv nodes added to the graph for transporting x and y to cpu?

推荐答案

send 和 recv 节点仅在您第一次尝试执行图形时添加到图形中,调用 tf.Session.run()... 实际上,添加的发送和接收节点集将取决于您在该调用中提供和获取的特定张量.

The send and recv nodes are only added to the graph on the first time you try to execute the graph, in a call to tf.Session.run()... and, indeed, the set of send and recv nodes that gets added will depend on the specific tensors that you feed and fetch in that call.

您可以通过将 tf.RunOptions(output_partition_graphs=True) 传递给 Session.run() 调用,如下:

You can see the exact graphs that execute on each device, including the send and recv nodes, by passing tf.RunOptions(output_partition_graphs=True) to the Session.run() call, as follows:

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.

这篇关于我们可以在 tensorflow GraphDef 中看到 Send 节点和 Receive 节点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆