How many session objects are needed for synchronous in-graph replication?
<p>When using synchronous in-graph replication I only call <code>tf.Session.run()</code> once.</p>

<p><strong>Question 1:</strong> Do I still have to create a new session object for each worker and have to pass the URL of the master server (the one that calls <code>tf.Session.run()</code>) as the session target?</p>

<p><strong>Question 2:</strong> Can I get the session target for each server by using <code>server.target</code> or do I have to specify the URL of the master server specifically?</p>

<p>If you are using "in-graph replication", the graph contains multiple copies of the computational nodes, typically with one copy per device (i.e. one per worker task if you're doing distributed CPU training, or one per GPU if you're doing distributed or local multi-GPU training). Since all of the replicas are in the same graph, you only need one <code>tf.Session</code> to control the entire training process. You <strong>don't</strong> need to create <code>tf.Session</code> objects in the workers that don't call <code>Session.run()</code>. </p>

<p>For in-graph training, it's typical to have a single master that is separate from the worker tasks (for performance isolation), but you could colocate it with your client program. In that case, you could simply create a single-task job called <code>"client"</code> and in that task create a session using <code>server.target</code>. The following example shows how you could write a single script for your <code>"client"</code>, <code>"worker"</code>, and <code>"ps"</code> jobs:</p>

<pre><code>server = tf.train.Server({"client": ["client_host:2222"],
                          "worker": ["worker_host0:2222", ...],
                          "ps": ["ps_host0:2222", ...]})

if job_name == "ps" or job_name == "worker":
    server.join()

elif job_name == "client":
    # Build a replicated graph.
    # ...

    sess = tf.Session(server.target)

    # Insert training loop here.
    # ...
</code></pre>

python tensorflow