问题描述
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/Graph#control_dependencies
希望有帮助!
这篇关于是否确保Session.run(fetches)执行其“提取"操作?争论有序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!