Session.run(fetches) 是否保证执行它的“fetches"?按顺序论证? [英] Is Session.run(fetches) guaranteed to execute its "fetches" arguments in-order?

查看:19
本文介绍了Session.run(fetches) 是否保证执行它的“fetches"?按顺序论证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Session.run(fetches, feed_dict) 是否保证按顺序执行其 fetches 参数?

Is Session.run(fetches, feed_dict) guaranteed to execute its fetches arguments in-order?

文档似乎没有提到它.

例如,如果您运行

sess.run([accuracy, train_op], feed_dict=feed_dict)

执行顺序很重要:train_op会更新影响accuracy的参数.

the order of execution matters: train_op will update parameters affecting accuracy.

推荐答案

没有.默认情况下,Tensorflow 可以以任何顺序自由评估运算符.由于并发,该顺序甚至可能在运行之间发生变化.这通常是一件好事,因为这意味着 Tensorflow 可以优化使用可用硬件.如果您的代码改变了诸如变量之类的状态,则可能会出现问题.

No. By default, Tensorflow is free to evaluate operators in any order. Because of concurrency, that order may even change between runs. This is usually a good thing because it means that Tensorflow may make optimal use of the available hardware. It can be problematic if your code mutates state such as Variables.

但是,如果出于某种原因您确实希望控制求值顺序,通常您可以使用控制依赖来强制操作符之间的顺序.此处记录了控制依赖项:

However, if for some reason you do wish to control the order of evaluation, in general you can use control dependencies to enforce an order between operators. Control dependencies are documented here:

https://www.tensorflow.org/api_docs/python/tf/图#control_dependencies

希望有帮助!

这篇关于Session.run(fetches) 是否保证执行它的“fetches"?按顺序论证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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