Tensorflow文档具有以下示例代码,用于查找节点的设备放置.也就是说,在哪个设备上进行特定计算.
# 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)
Run Code Online (Sandbox Code Playgroud)
对我来说,代码不会像预期的那样打印出设备的位置.我正在使用在Ubuntu上运行的Jupyter笔记本.我该如何修复此问题或以其他方式查找信息?
mrr*_*rry 11
对于Jupyter(和其他)用户,最近添加的功能可以在您Session.run()拨打电话并在笔记本中打印时回读设备放置.
# 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()
# Runs the op.
options = tf.RunOptions(output_partition_graphs=True)
metadata = tf.RunMetadata()
c_val = sess.run(c, options=options, run_metadata=metadata)
print metadata.partition_graphs
Run Code Online (Sandbox Code Playgroud)
在metadata.partition_graphs包含执行该图中,由设备分配的实际节点.分区未使用它们所代表的设备明确标记,但NodeDef图中的每个分区都有其device字段集.
不幸的是,Jupyter 看不到设备放置日志记录使用的 C++ 错误标准输出消息。这里有一个关于这个问题的更长的线程:
https://github.com/nteract/Hydrogen/issues/209
据我所知,除了在 Jupyter 之外运行脚本之外,没有简单的解决方法。
| 归档时间: |
|
| 查看次数: |
4960 次 |
| 最近记录: |