Variable is a resource, inherited from
ResourceBase and managed by
ResourceMgr. But why is there another named
ResourceVariable? Both of them can be used for optimizers like
gradient_descent (see this example). What’s the difference? I know the former is well documented and most often used. What’s the purpose of the latter?
ResourceVariable is the replacement for
Variable, that aims to clean up some of the messier aspects of the semantics of
ResourceVariable is the default in TF 2.0 and you very likely don’t care about the differences between the two unless you are working on details deep inside the Tensorflow implementation. When eager execution is enabled
tf.Variable also creates resource variables.
So just use
tf.Variable for now, it’s almost certainly what you want; if you experience issues which look like race conditions or bugs from inconsistent values of variables in code you can try enabling resource variables (by either passing
use_resource=True to your variable-creating code or calling
tf.enable_resource_variables() in TF 1.x).
Answered By – Peter Hawkins