<p>Any <code>tff.Computation</code> (like <code>next</code>) will always run the <em>entire</em> specified computation. If your <code>tff.templates.IterativeProcess</code> is, for example, the result of <a href="https://www.tensorflow.org/federated/api_docs/python/tff/learning/build_federated_averaging_process" rel="nofollow noreferrer"><code>tff.learning.build_federated_averaging_process</code></a>, its <code>next</code> function will represent one round of the federated averaging algorithm.</p>
<p>The federated averaging algorithm runs training for a fixed number of <em>epochs</em> (let's say 1 for simplicity) over each local dataset, and averages the model updates in a data-weighted manner at the server in order to complete a round--see <a href="https://arxiv.org/pdf/1602.05629.pdf" rel="nofollow noreferrer">Algorithm 1 in the original federated averaging paper</a> for a specification of the algorithm.</p>
<p>Now, for how TFF represents and executes this algorithm. From the documentation for <a href="https://www.tensorflow.org/federated/api_docs/python/tff/learning/build_federated_averaging_process" rel="nofollow noreferrer"><code>build_federated_averaging_process</code></a>, the <code>next</code> function has type signature:</p>
<pre><code>(&lt;S@SERVER, {B*}@CLIENTS&gt; -&gt; &lt;S@SERVER, T@SERVER&gt;)
</code></pre>
<p>TFF's type system represents a dataset as a <a href="https://www.tensorflow.org/federated/api_docs/python/tff/SequenceType" rel="nofollow noreferrer"><code>tff.SequenceType</code></a> (this is the meaning of the <code>*</code> above), so the second element in the parameter of the type signature represents a set (technically a multiset) of datasets with elements of type <code>B</code>, placed at the clients.</p>
<p>What this means in your example is as follows. You have a list of <code>tf.data.Datasets</code>, each of which represents the local data on each client--you can think of the list as representing the federated placement. In this context, TFF executing the entire specified computation means: TFF will treat every item in the list as a client to be trained on in this round. In the terms of the algorithm linked above, your list of datasets represents the set S_t.</p>
<p>TFF will faithfully execute one round of the federated averaging algorithm, with the <code>Dataset</code> elements of your list representing the clients selected for this round. Training will be run for a single epoch on each client (in parallel); if datasets have different amounts of data, you are correct that the training on each client is likely to finish at different times. However, this is the correct semantics of a single round of the federated averaging algorithm, as opposed to a parameterization of a similar algorithm like <a href="https://openai.com/blog/reptile/" rel="nofollow noreferrer">Reptile</a>, which runs for a fixed number of steps for each client.</p>
<p>If you wish to select a subset of clients to run a round of training on, this should be done <em>in Python</em>, before calling into TFF, e.g.:</p>
<pre class="lang-py prettyprint-override"><code>state = iterative_process.initialize()

# ls is list of datasets
sampled_clients = random.sample(ls, N_CLIENTS)

state = iterative_process.next(state, sampled_clients)
</code></pre>
<p>Generally, you can think of the Python runtime as an &quot;experiment driver&quot; layer--any selection of clients, for example, should happen at this layer. See the beginning of <a href="https://stackoverflow.com/questions/59835749/implement-data-generator-in-federated-training/59865565#59865565">this answer</a> for further detail on this.</p>
What exactly happens when we call IterativeProcess.next on federated training data?
<p>I went through the Federated Learning tutorial. I was wondering how .next function work when we call it on an iterative process.
Assuming that we have train data which is a list of lists. The outer list is a list of clients and the inner lists are batches of data for each client. Then, we create an iterative process, for example, a federated averaging process and we initialize the state.
What exactly happens when we call IterativeProcess.next on this training data. Does it take from these data randomly in each round? Or just take data from each client one batch at a time?</p>
<p>Assume that I have a list of tf.data.Datasets each representing a client data. How can I add some randomness to sampling from this list for the next iteration of federated learning?</p>
<p>My datasets are not necessarily the same length. When one of them is completely iterated over, does this dataset waits for all other datasets to completely iterate over their data or not?</p>