在TensorFlow优化器中use_locking = True有什么作用? [英] What does use_locking=True do in TensorFlow optimizers?

查看:425
本文介绍了在TensorFlow优化器中use_locking = True有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它只是防止异步更新还是还会导致对该变量的其他访问以等待更新?我同时使用相同的模型进行训练和推理,并希望确保始终在一致的模型上进行推理.

Does it only protect against asynchronous updates or does it also cause other access to the variable to wait for the update? I'm using the same model for training and inference at the same time and want to make sure that inference is always done on a consistent model.

推荐答案

创建TensorFlow时传递use_locking=True

Passing use_locking=True when creating a TensorFlow optimizer, or a variable assignment op, causes a lock to be acquired around the relevant updates to the variable. Other optimizers/assignments on the same variable also created with use_locking=True will be serialized.

但是,使用此选项时,请记住两个警告:

However, there are two caveats that you should bear in mind when using this option:

  • 在锁定下不执行对变量的读取,因此可以查看中间状态和部分应用的更新.序列化读取需要额外的协调,例如tf.train.SyncReplicasOptimizer提供的协调.

仍然可以使用use_locking=False写入(优化程序/赋值)相同的变量,并且不会获取该锁.程序员负责确保不会发生这些写操作.

Writes (optimizers/assignments) to the same variable with use_locking=False are still possible, and will not acquire the lock. The programmer is responsible for ensuring that these writes do not occur.

这篇关于在TensorFlow优化器中use_locking = True有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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