How does "tf.train.replica_device_setter" work?
<p>I understood that <code>tf.train.replica_device_setter</code> can be used for automatically assigning the variables always on the same parameter server (PS) (using round-robin) and the compute intensive nodes on one worker.</p>

<p>How do the same variables get reused across multiple graph replicas, build up by different workers? Does the parameter server only look at the name of the variable that a worker asks for? </p>

<p>Does this mean that tasks should not be used parallel for the execution of two different graphs if in both graphs the variables are named the same?</p>

<p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/train.html#replica_device_setter" rel="nofollow"><code>tf.train.replica_device_setter()</code></a> is quite simple in its behavior: it makes a purely local decision to assign a device to each <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/state_ops.html#Variable" rel="nofollow"><code>tf.Variable</code></a> as it is created&mdash;in a round-robin fashion across the parameter server tasks.</p>

<p>In the distributed version of TensorFlow, each <em>device</em> (e.g. <code>"/job:ps/task:17/cpu:0"</code>) maintains a map from variable names to variables that is shared between all sessions that use this device. This means that when different worker replicas create a session using that device, if they assign the same symbolic variable (having the same <code>Variable.name</code> property) to the same device, they will see each other's updates.</p>

<p>When you do <a href="https://www.tensorflow.org/versions/r0.10/how_tos/distributed/index.html#replicated-training" rel="nofollow">"between-graph replication"</a> across multiple replicas, the <code>tf.train.replica_device_setter()</code> provides a simple, deterministic way to assign variables to devices. If you build an identical graph on each worker replica, each variable will be assigned to the same device and successfully shared, without any external coordination.</p>

<p><strong>Caveat:</strong> With this scheme, your worker replicas must create an identical graph*, and there must be no randomness in how the graph is constructed. I once saw an issue where the order of creating variables was determined by iterating over the keys of a Python <code>dict</code>, which is <a href="http://stackoverflow.com/questions/4458169/in-what-order-does-python-display-dictionary-keys">not guaranteed to happen in the same order</a> across processes. This led to variables being assigned to different PS devices by different workers....</p>

<p>As to your other question, you do need to be careful about variable name clashes when training multiple models using the same processes. By default all variables are shared in a global namespace, so two variables from different networks with the same name will clash. One way to mitigate this problem is to wrap each model in a <a href="https://www.tensorflow.org/versions/master/api_docs/python/framework.html#container" rel="nofollow"><code>with tf.container(name):</code></a> block (with different values for <code>name</code>, e.g. <code>"model_1"</code> and <code>"model_2"</code>)
to put your variables in a different namespace, which is called a "container" in the TensorFlow jargon. You can think of a container as a prefix that is added to the name of all of your variables when they are looked up on the device. The support for containers in the API is still quite preliminary, but there are plans to make them more useful in future.</p>

<hr>

<p>&nbsp;* Technically, they only need to create their <code>tf.Variable</code> objects in the same sequence.</p>

python tensorflow