Newer
Older
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "tqrD7Yzlmlsk"
},
"source": [
"##### Copyright 2019 The TensorFlow Authors."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"cellView": "form",
"colab": {},
"colab_type": "code",
"id": "2k8X1C1nmpKv"
},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "32xflLc4NTx-"
},
"source": [
"# Custom Federated Algorithms, Part 2: Implementing Federated Averaging"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "jtATV6DlqPs0"
},
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/federated/tutorials/custom_federated_algorithms_2\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/federated/blob/v0.8.0/docs/tutorials/custom_federated_algorithms_2.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/federated/blob/v0.8.0/docs/tutorials/custom_federated_algorithms_2.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
" \u003c/td\u003e\n",
"\u003c/table\u003e"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "_igJ2sfaNWS8"
},
"source": [
"This tutorial is the second part of a two-part series that demonstrates how to\n",
"implement custom types of federated algorithms in TFF using the\n",
"[Federated Core (FC)](../federated_core.md), which serves as a foundation for\n",
"the [Federated Learning (FL)](../federated_learning.md) layer (`tff.learning`).\n",
"\n",
"We encourage you to first read the\n",
"[first part of this series](custom_federated_algorithms_1.ipynb), which\n",
"introduce some of the key concepts and programming abstractions used here.\n",
"\n",
"This second part of the series uses the mechanisms introduced in the first part\n",
"to implement a simple version of federated training and evaluation algorithms.\n",
"\n",
"We encourage you to review the\n",
"[image classification](federated_learning_for_image_classification.ipynb) and\n",
"[text generation](federated_learning_for_text_generation.ipynb) tutorials for a\n",
"higher-level and more gentle introduction to TFF's Federated Learning APIs, as\n",
"they will help you put the concepts we describe here in context."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "cuJuLEh2TfZG"
},
"source": [
"## Before we start\n",
"\n",
"Before we start, try to run the following \"Hello World\" example to make sure\n",
"your environment is correctly setup. If it doesn't work, please refer to the\n",
"[Installation](../install.md) guide for instructions."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "rB1ovcX1mBxQ"
},
"outputs": [],
"source": [
"# NOTE: If you are running a Jupyter notebook, and installing a locally built\n",
"# pip package, you may need to edit the following to point to the '.whl' file\n",
"# on your local filesystem.\n",
"\n",
"!pip install --quiet --upgrade tensorflow_federated\n",
"!pip install --quiet --upgrade tf-nightly"
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "-skNC6aovM46"
},
"outputs": [],
"source": [
"from __future__ import absolute_import, division, print_function\n",
"\n",
"import collections\n",
"\n",
"import numpy as np\n",
"from six.moves import range\n",
"import tensorflow as tf\n",
"import tensorflow_federated as tff\n",
"\n",
"tf.compat.v1.enable_v2_behavior()"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"executionInfo": {
"elapsed": 420,
"status": "ok",
"timestamp": 1570209774342,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "zzXwGnZamIMM",
"outputId": "a339c5a0-a5e0-4b52-d92e-c6c2b1c333d7"
},
"outputs": [
{
"data": {
"text/plain": [
"'Hello, World!'"
]
},
"execution_count": 139,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
"source": [
"@tff.federated_computation\n",
"def hello_world():\n",
" return 'Hello, World!'\n",
"\n",
"\n",
"hello_world()"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "iu5Gd8D6W33s"
},
"source": [
"## Implementing Federated Averaging\n",
"\n",
"As in\n",
"[Federated Learning for Image Classification](federated_learning_for_image_classification.md),\n",
"we are going to use the MNIST example, but since this is intended as a low-level\n",
"tutorial, we are going to bypass the Keras API and `tff.simulation`, write raw\n",
"model code, and construct a federated data set from scratch.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "b6qCjef350c_"
},
"source": [
"\n",
"### Preparing federated data sets\n",
"\n",
"For the sake of a demonstration, we're going to simulate a scenario in which we\n",
"have data from 10 users, and each of the users contributes knowledge how to\n",
"recognize a different digit. This is about as\n",
"non-[i.i.d.](https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables)\n",
"as it gets.\n",
"\n",
"First, let's load the standard MNIST data:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "uThZM4Ds-KDQ"
},
"outputs": [],
"source": [
"mnist_train, mnist_test = tf.keras.datasets.mnist.load_data()"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"executionInfo": {
"elapsed": 419,
"status": "ok",
"timestamp": 1570209775660,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "PkJc5rHA2no_",
"outputId": "391477e3-180a-4d76-c1da-116c0fb3bf46"
},
"outputs": [
{
"data": {
"text/plain": [
"[(dtype('uint8'), (60000, 28, 28)), (dtype('uint8'), (60000,))]"
]
},
"execution_count": 141,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
"source": [
"[(x.dtype, x.shape) for x in mnist_train]"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "mFET4BKJFbkP"
},
"source": [
"The data comes as Numpy arrays, one with images and another with digit labels, both\n",
"with the first dimension going over the individual examples. Let's write a\n",
"helper function that formats it in a way compatible with how we feed federated\n",
"sequences into TFF computations, i.e., as a list of lists - the outer list\n",
"ranging over the users (digits), the inner ones ranging over batches of data in\n",
"each client's sequence. As is customary, we will structure each batch as a pair\n",
"of tensors named `x` and `y`, each with the leading batch dimension. While at\n",
"it, we'll also flatten each image into a 784-element vector and rescale the\n",
"pixels in it into the `0..1` range, so that we don't have to clutter the model\n",
"logic with data conversions."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "XTaTLiq5GNqy"
},
"outputs": [],
"source": [
"NUM_EXAMPLES_PER_USER = 1000\n",
"BATCH_SIZE = 100\n",
"\n",
"def get_data_for_digit(source, digit):\n",
" output_sequence = []\n",
" all_samples = [i for i, d in enumerate(source[1]) if d == digit]\n",
" for i in range(0, min(len(all_samples), NUM_EXAMPLES_PER_USER), BATCH_SIZE):\n",
" batch_samples = all_samples[i:i + BATCH_SIZE]\n",
" output_sequence.append({\n",
" 'x': np.array([source[0][i].flatten() / 255.0 for i in batch_samples],\n",
" dtype=np.float32),\n",
" 'y': np.array([source[1][i] for i in batch_samples], dtype=np.int32)})\n",
" return output_sequence\n",
"\n",
"federated_train_data = [get_data_for_digit(mnist_train, d) for d in range(10)]\n",
"\n",
"federated_test_data = [get_data_for_digit(mnist_test, d) for d in range(10)]"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "xpNdBimWaMHD"
},
"source": [
"As a quick sanity check, let's look at the `Y` tensor in the last batch of data\n",
"contributed by the fifth client (the one corresponding to the digit `5`)."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 101
},
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
"executionInfo": {
"elapsed": 433,
"status": "ok",
"timestamp": 1570209778170,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "bTNuL1W4bcuc",
"outputId": "43b62cf9-777c-48f5-d568-59aa41b85bf9"
},
"outputs": [
{
"data": {
"text/plain": [
"array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n",
" 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n",
" 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n",
" 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n",
" 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], dtype=int32)"
]
},
"execution_count": 143,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
"source": [
"federated_train_data[5][-1]['y']"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Xgvcwv7Obhat"
},
"source": [
"Just to be sure, let's also look at the image corresponding to the last element of that batch."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 275
},
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
"executionInfo": {
"elapsed": 613,
"status": "ok",
"timestamp": 1570209778830,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "cI4aat1za525",
"outputId": "ae6c35e8-c05e-4d9d-f5db-e510c0709da3"
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQUAAAECCAYAAAD3k8IpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnU1sm1X2/7+245fYSRynVdOoQCvKorBCIMSis6EDEhIF\nqYvRoBZRZjEbVJAqVVUlQEAHFgGNGKkVCHZddDpCM2KGgDQCqavZDNJoVlMWvwqVlpC20MRx/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IWFBQDAwsICHnrooaExeUulEvL5vP/4yy+/xIMPPjjAGZnQh1ivY+t88MEH\nuHLlCj788EOMjf3iQQ/T9bPNr5/XbygyGr/77jucOXMGuVwO6XQa8/Pz2Ldv36CnBQC4ceMGXn31\nVdTrddTrdezfvx+vv/46du7cObA5vfPOO/j6669x584dTE9PI5PJYGFhYWiuo21+H330EV555ZWB\nX8erV6/i2Wefxb59+/yU4XvvvRfnzp0biuvnmt/p06f79jkcClFQFGV4GLj7oCjKcKGioCiKgYqC\noigGKgqKohioKCiKYqCioCiKgYqCoigGKgqKohj8P9TxOUEZnVRqAAAAAElFTkSuQmCC\n",
"text/plain": [
"\u003cmatplotlib.figure.Figure at 0xe994c5abe10\u003e"
]
},
"metadata": {
"tags": []
},
"output_type": "display_data"
}
],
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
"source": [
"from matplotlib import pyplot as plt\n",
"\n",
"plt.imshow(federated_train_data[5][-1]['x'][-1].reshape(28, 28), cmap='gray')\n",
"plt.grid(False)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "J-ox58PA56f8"
},
"source": [
"### On combining TensorFlow and TFF\n",
"\n",
"In this tutorial, for compactness we immediately decorate functions that\n",
"introduce TensorFlow logic with `tff.tf_computation`. However, for more complex\n",
"logic, this is not the pattern we recommend. Debugging TensorFlow can already be\n",
"a challenge, and debugging TensorFlow after it has been fully serialized and\n",
"then re-imported necessarily loses some metadata and limits interactivity,\n",
"making debugging even more of a challenge.\n",
"\n",
"Therefore, **we strongly recommend writing complex TF logic as stand-alone\n",
"Python functions** (that is, without `tff.tf_computation` decoration). This way\n",
"the TensorFlow logic can be developed and tested using TF best practices and\n",
"tools (like eager mode), before serializing the computation for TFF (e.g., by invoking `tff.tf_computation` with a Python function as the argument)."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "RSd6UatXbzw-"
},
"source": [
"### Defining a loss function\n",
"\n",
"Now that we have the data, let's define a loss function that we can use for\n",
"training. First, let's define the type of input as a TFF named tuple. Since the\n",
"size of data batches may vary, we set the batch dimension to `None` to indicate\n",
"that the size of this dimension is unknown."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
"executionInfo": {
"elapsed": 419,
"status": "ok",
"timestamp": 1570209779265,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "653xv5NXd4fy",
"outputId": "28264cf1-2b98-4f2f-f7ad-5f9c690e5e71"
},
"outputs": [
{
"data": {
"text/plain": [
"'\u003cx=float32[?,784],y=int32[?]\u003e'"
]
},
"execution_count": 145,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
"source": [
"BATCH_SPEC = collections.OrderedDict([\n",
" ('x', tf.TensorSpec(shape=[None, 784], dtype=tf.float32)),\n",
" ('y', tf.TensorSpec(shape=[None], dtype=tf.int32)),\n",
"])\n",
"BATCH_TYPE = tff.to_type(BATCH_SPEC)\n",
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
"\n",
"str(BATCH_TYPE)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "pb6qPUvyh5A1"
},
"source": [
"You may be wondering why we can't just define an ordinary Python type. Recall\n",
"the discussion in [part 1](custom_federated_algorithms_1.ipynb), where we\n",
"explained that while we can express the logic of TFF computations using Python,\n",
"under the hood TFF computations *are not* Python. The symbol `BATCH_TYPE`\n",
"defined above represents an abstract TFF type specification. It is important to\n",
"distinguish this *abstract* TFF type from concrete Python *representation*\n",
"types, e.g., containers such as `dict` or `collections.namedtuple` that may be\n",
"used to represent the TFF type in the body of a Python function. Unlike Python,\n",
"TFF has a single abstract type constructor `tff.NamedTupleType` for tuple-like\n",
"containers, with elements that can be individually named or left unnamed. This\n",
"type is also used to model formal parameters of computations, as TFF\n",
"computations can formally only declare one parameter and one result - you will\n",
"see examples of this shortly.\n",
"\n",
"Let's now define the TFF type of model parameters, again as a TFF named tuple of\n",
"*weights* and *bias*."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
"executionInfo": {
"elapsed": 447,
"status": "ok",
"timestamp": 1570209779730,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "Og7VViafh-30",
"outputId": "7c2584c1-7340-4923-e211-6c4087813ca5"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u003cweights=float32[784,10],bias=float32[10]\u003e\n"
]
}
],
"source": [
"MODEL_SPEC = collections.OrderedDict([\n",
" ('weights', tf.TensorSpec(shape=[784, 10], dtype=tf.float32)),\n",
" ('bias', tf.TensorSpec(shape=[10], dtype=tf.float32)),\n",
"])\n",
"MODEL_TYPE = tff.to_type(MODEL_SPEC)\n",
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "iHhdaWSpfQxo"
},
"source": [
"With those definitions in place, now we can define the loss for a given model, over\n",
"a single batch. Note how in the body of `batch_loss`, we access named tuple\n",
"elements using the dot (`X.Y`) notation, as is standard for TFF."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "4EObiz_Ke0uK"
},
"outputs": [],
"source": [
"# NOTE: `forward_pass` is defined separately from `batch_loss` so that it can \n",
"# be later called from within another tf.function. Necessary because a\n",
"# @tf.function decorated method cannot invoke a @tff.tf_computation.\n",
"\n",
"@tf.function\n",
"def forward_pass(model, batch):\n",
" predicted_y = tf.nn.softmax(\n",
" tf.matmul(batch['x'], model['weights']) + model['bias'])\n",
" return -tf.reduce_mean(\n",
" tf.reduce_sum(\n",
" tf.one_hot(batch['y'], 10) * tf.math.log(predicted_y), axis=[1]))\n",
"\n",
"@tff.tf_computation(MODEL_TYPE, BATCH_TYPE)\n",
"def batch_loss(model, batch):\n",
" return batch_loss(model, batch)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
},
"source": [
"As expected, computation `batch_loss` returns `float32` loss given the model and\n",
"a single data batch. Note how the `MODEL_TYPE` and `BATCH_TYPE` have been lumped\n",
"together into a 2-tuple of formal parameters; you can recognize the type of\n",
"`batch_loss` as `(\u003cMODEL_TYPE,BATCH_TYPE\u003e -\u003e float32)`."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
"executionInfo": {
"elapsed": 451,
"status": "ok",
"timestamp": 1570209780675,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "4WXEAY8Nr89V",
"outputId": "fbd8ad63-ca6f-49bf-f0c8-0adf4c35a6c1"
},
"outputs": [
{
"data": {
"text/plain": [
"'(\u003c\u003cweights=float32[784,10],bias=float32[10]\u003e,\u003cx=float32[?,784],y=int32[?]\u003e\u003e -\u003e float32)'"
]
},
"execution_count": 148,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
"source": [
"str(batch_loss.type_signature)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "pAnt_UcdnvGa"
},
"source": [
"As a sanity check, let's construct an initial model filled with zeros and\n",
"compute the loss over the batch of data we visualized above."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
"executionInfo": {
"elapsed": 420,
"status": "ok",
"timestamp": 1570209781117,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "U8Ne8igan3os",
"outputId": "d0b9d7aa-4e01-49cd-91ff-8f76aa82257f"
},
"outputs": [
{
"data": {
"text/plain": [
"2.3025854"
]
},
"execution_count": 149,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
"source": [
"initial_model = {\n",
" 'weights': np.zeros([784, 10], dtype=np.float32),\n",
" 'bias': np.zeros([10], dtype=np.float32)\n",
"}\n",
"\n",
"sample_batch = federated_train_data[5][-1]\n",
"\n",
"batch_loss(initial_model, sample_batch)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ckigEAyDAWFV"
},
"source": [
"Note that we feed the TFF computation with the initial model defined as a\n",
"`dict`, even though the body of the Python function that defines it consumes\n",
"model parameters as `model.weight` and `model.bias`. The arguments of the call\n",
"to `batch_loss` aren't simply passed to the body of that function.\n",
"\n",
"\n",
"What happens when we invoke `batch_loss`?\n",
"The Python body of `batch_loss` has already been traced and serialized in the above cell where it was defined. TFF acts as the caller to `batch_loss`\n",
"at the computation definition time, and as the target of invocation at the time\n",
"`batch_loss` is invoked. In both roles, TFF serves as the bridge between TFF's\n",
"abstract type system and Python representation types. At the invocation time,\n",
"TFF will accept most standard Python container types (`dict`, `list`, `tuple`,\n",
"`collections.namedtuple`, etc.) as concrete representations of abstract TFF\n",
"tuples. Also, although as noted above, TFF computations formally only accept a\n",
"single parameter, you can use the familiar Python call syntax with positional\n",
"and/or keyword arguments in case where the type of the parameter is a tuple - it\n",
"works as expected."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "eB510nILYbId"
},
"source": [
"### Gradient descent on a single batch\n",
"\n",
"Now, let's define a computation that uses this loss function to perform a single\n",
"step of gradient descent. Note how in defining this function, we use\n",
"`batch_loss` as a subcomponent. You can invoke a computation constructed with\n",
"`tff.tf_computation` inside the body of another computation, though typically\n",
"this is not necessary - as noted above, because serialization looses some\n",
"debugging information, it is often preferable for more complex computations to\n",
"write and test all the TensorFlow without the `tff.tf_computation` decorator."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "O4uaVxw3AyYS"
},
"outputs": [],
"source": [
"@tff.tf_computation(MODEL_TYPE, BATCH_TYPE, tf.float32)\n",
"def batch_train(initial_model, batch, learning_rate):\n",
" # Define a group of model variables and set them to `initial_model`.\n",
" model_vars = collections.OrderedDict([\n",
" (name, tf.Variable(name=name, initial_value=value))\n",
" for name, value in initial_model.items()\n",
" ])\n",
" @tf.function\n",
" def _train_on_batch(model_vars, batch):\n",
" # Perform one step of gradient descent using loss from `batch_loss`.\n",
" optimizer = tf.keras.optimizers.SGD(learning_rate)\n",
" with tf.GradientTape() as tape:\n",
" loss = forward_pass(model_vars, batch)\n",
" grads = tape.gradient(loss, model_vars)\n",
" optimizer.apply_gradients(\n",
" zip(tf.nest.flatten(grads), tf.nest.flatten(model_vars)))\n",
" return model_vars\n",
" return _train_on_batch(model_vars, batch)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
"executionInfo": {
"elapsed": 417,
"status": "ok",
"timestamp": 1570209782394,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "Y84gQsaohC38",
"outputId": "c35a322d-15cd-415c-f046-c88853b5f6ba"
},
"outputs": [
{
"data": {
"text/plain": [
"'(\u003c\u003cweights=float32[784,10],bias=float32[10]\u003e,\u003cx=float32[?,784],y=int32[?]\u003e,float32\u003e -\u003e \u003cweights=float32[784,10],bias=float32[10]\u003e)'"
]
},
"execution_count": 151,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
"source": [
"str(batch_train.type_signature)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ID8xg9FCUL2A"
},
"source": [
"When you invoke a Python function decorated with `tff.tf_computation` within the\n",
"body of another such function, the logic of the inner TFF computation is\n",
"embedded (essentially, inlined) in the logic of the outer one. As noted above,\n",
"if you are writing both computations, it is likely preferable to make the inner\n",
"function (`batch_loss` in this case) a regular Python or `tf.function` rather\n",
"than a `tff.tf_computation`. However, here we illustrate that calling one\n",
"`tff.tf_computation` inside another basically works as expected. This may be\n",
"necessary if, for example, you do not have the Python code defining\n",
"`batch_loss`, but only its serialized TFF representation.\n",
"\n",
"Now, let's apply this function a few times to the initial model to see whether\n",
"the loss decreases."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "8edcJTlXUULm"
},
"outputs": [],
"source": [
"model = initial_model\n",
"losses = []\n",
"for _ in range(5):\n",
" model = batch_train(model, sample_batch, 0.1)\n",
" losses.append(batch_loss(model, sample_batch))"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
"executionInfo": {
"elapsed": 416,
"status": "ok",
"timestamp": 1570209783978,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "3n1onojT1zHv",
"outputId": "24ed4703-fa57-4613-d8a1-99fcd3cebcc1"
},
"outputs": [
{
"data": {
"text/plain": [
"[0.19690022, 0.13176313, 0.10113226, 0.082738124, 0.0703014]"
]
},
"execution_count": 153,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
"source": [
"losses"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "EQk4Ha8PU-3P"
},
"source": [
"### Gradient descent on a sequence of local data\n",
"\n",
"Now, since `batch_train` appears to work, let's write a similar training\n",
"function `local_train` that consumes the entire sequence of all batches from one\n",
"user instead of just a single batch. The new computation will need to now\n",
"consume `tff.SequenceType(BATCH_TYPE)` instead of `BATCH_TYPE`."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "EfPD5a6QVNXM"
},
"outputs": [],
"source": [
"LOCAL_DATA_TYPE = tff.SequenceType(BATCH_TYPE)\n",
"\n",
"@tff.federated_computation(MODEL_TYPE, tf.float32, LOCAL_DATA_TYPE)\n",
"def local_train(initial_model, learning_rate, all_batches):\n",
"\n",
" # Mapping function to apply to each batch.\n",
" @tff.federated_computation(MODEL_TYPE, BATCH_TYPE)\n",
" def batch_fn(model, batch):\n",
" return batch_train(model, batch, learning_rate)\n",
"\n",
" return tff.sequence_reduce(all_batches, initial_model, batch_fn)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"height": 34
},
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"executionInfo": {
"elapsed": 420,
"status": "ok",
"timestamp": 1570209784877,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "sAhkS5yKUgjC",
"outputId": "3d098970-5cc5-456f-92b5-77e502d208b1"
},
"outputs": [
{
"data": {
"text/plain": [
"'(\u003c\u003cweights=float32[784,10],bias=float32[10]\u003e,float32,\u003cx=float32[?,784],y=int32[?]\u003e*\u003e -\u003e \u003cweights=float32[784,10],bias=float32[10]\u003e)'"
]
},
"execution_count": 155,
"metadata": {
"tags": []
},