Migrate FL + DP tutorial to tff.learning.algorithms.
" # Typically a non-adaptive server optimizer is used because the noise in the\n",
" # updates can cause the second moment accumulators to become very large\n",
" # prematurely.\n",
- " learning_process = tff.learning.build_federated_averaging_process(\n",
+ " learning_process = tff.learning.algorithms.build_unweighted_fed_avg(\n",
" my_model_fn,\n",
" client_optimizer_fn=lambda: tf.keras.optimizers.SGD(0.01),\n",
" server_optimizer_fn=lambda: tf.keras.optimizers.SGD(1.0, momentum=0.9),\n",
- " model_update_aggregation_factory=aggregation_factory)\n",
+ " model_aggregator=aggregation_factory)\n",
"\n",
" eval_process = tff.learning.build_federated_evaluation(my_model_fn)\n",
" \n",
" state = learning_process.initialize()\n",
" for round in range(rounds):\n",
" if round % 5 == 0:\n",
- " metrics = eval_process(state.model, [test_data])['eval']\n",
+ " model_weights = learning_process.get_model_weights(state)\n",
+ " metrics = eval_process(model_weights, [test_data])['eval']\n",
" if round \u003c 25 or round % 25 == 0:\n",
" print(f'Round {round:3d}: {metrics}')\n",
" data_frame = data_frame.append({'Round': round,\n",
" for client in sampled_clients]\n",
"\n",
" # Use selected clients for update.\n",
- " state, metrics = learning_process.next(state, sampled_train_data)\n",
+ " result = learning_process.next(state, sampled_train_data)\n",
+ " state = result.state\n",
+ " metrics = result.metrics\n",
"\n",
- " metrics = eval_process(state.model, [test_data])['eval']\n",
+ " model_weights = learning_process.get_model_weights(state)\n",
+ " metrics = eval_process(model_weights, [test_data])['eval']\n",
" print(f'Round {rounds:3d}: {metrics}')\n",
" data_frame = data_frame.append({'Round': rounds,\n",
" 'NoiseMultiplier': noise_multiplier,\n",
