From 12cda975320bcfc506d60ec2ed3681f2e32beb73 Mon Sep 17 00:00:00 2001 From: Valerio Maggio Date: Wed, 22 Mar 2023 10:06:21 +0000 Subject: [PATCH] checked and trusted notebooks --- .../1-Intro-Federated-Learning.ipynb | 2 +- .../2-Homomorphic-Encryption.ipynb | 119 +- .../3-OpenMined-private-AI-series.ipynb | 2 +- .../duet_iris_classifier/duet-iris-DO.ipynb | 3086 +++++++++++++++- .../duet_iris_classifier/duet-iris-DS.ipynb | 3095 ++++++++++++++++- .../duet_splitnn/1-intro-splitNN.ipynb | 4 +- .../duet_splitnn/splitnn-DO.ipynb | 2 +- .../duet_splitnn/splitnn-DS.ipynb | 2 +- 8 files changed, 6194 insertions(+), 118 deletions(-) diff --git a/3-federated-learning/1-Intro-Federated-Learning.ipynb b/3-federated-learning/1-Intro-Federated-Learning.ipynb index c10116e..8039fc4 100644 --- a/3-federated-learning/1-Intro-Federated-Learning.ipynb +++ b/3-federated-learning/1-Intro-Federated-Learning.ipynb @@ -3182,7 +3182,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/2-Homomorphic-Encryption.ipynb b/3-federated-learning/2-Homomorphic-Encryption.ipynb index efc2a34..6f5c1ab 100644 --- a/3-federated-learning/2-Homomorphic-Encryption.ipynb +++ b/3-federated-learning/2-Homomorphic-Encryption.ipynb @@ -3111,7 +3111,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "bdcbbd53-0049-4b0c-9642-ae21f20d7a1e", "metadata": {}, "outputs": [], @@ -3127,7 +3127,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "f1a0cbf9-b445-4117-b2fa-537402b081f9", "metadata": {}, "outputs": [], @@ -3137,7 +3137,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "25b32d56-f468-4b79-b351-4dd19bd765bb", "metadata": {}, "outputs": [], @@ -3148,7 +3148,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "2fcefbf6-42a7-403a-a03c-884afe922a50", "metadata": {}, "outputs": [], @@ -3168,7 +3168,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "2dc11391-39fc-4e84-891f-53d4296894da", "metadata": {}, "outputs": [], @@ -3191,7 +3191,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "46f9bfc2-678e-4cc0-80c4-833710be20b4", "metadata": {}, "outputs": [], @@ -3238,7 +3238,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "7efb4506-d11d-4fc0-95b3-fcf71fbbae41", "metadata": {}, "outputs": [], @@ -3272,7 +3272,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "f56f1247-27de-45e3-8299-a4793e037725", "metadata": {}, "outputs": [], @@ -3289,18 +3289,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "5f7bd444-eb7f-4d55-a55e-f7ee737a91b1", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Alice: Generating paillier keypair\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Alice: Generating paillier keypair\")\n", "alice = Alice()\n", @@ -3310,19 +3302,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "55f86ad0-5fcf-4874-8d58-07c1da3a28a2", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Alice: Training BC Classifier\n", - "[elapsed time: 0.02 s]\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Alice: Training BC Classifier\")\n", "with timer() as t:\n", @@ -3339,20 +3322,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "be931707-a0b6-4a0e-bab8-75d64c8e8239", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Classify with model in the clear -- what Alice would get having Bob's data locally\n", - "[elapsed time: 0.00 s]\n", - "Error 0.014\n" - ] - } - ], + "outputs": [], "source": [ "print(\n", " \"Classify with model in the clear -- \"\n", @@ -3373,19 +3346,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "d97d605a-0746-47be-acc6-416f3ffd8295", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Alice: Encrypting classifier\n", - "[elapsed time: 0.43 s]\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Alice: Encrypting classifier\")\n", "with timer() as t:\n", @@ -3394,18 +3358,10 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "c78f1493-5423-4b9d-89cd-60e6186ba483", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Bob: Scoring with encrypted classifier\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Bob: Scoring with encrypted classifier\")\n", "bob = Bob(alice.pubkey)\n", @@ -3414,18 +3370,10 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "385c53c9-f399-4d8a-bcd9-2aefe0b22985", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[elapsed time: 5.77 s]\n" - ] - } - ], + "outputs": [], "source": [ "with timer() as t:\n", " encrypted_scores = bob.encrypted_evaluate(X_test)" @@ -3441,21 +3389,12 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "5e44043a-08f3-4e95-9d6d-0ebc06c8c98b", "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Alice: Decrypting Bob's scores\n", - "[elapsed time: 0.59 s]\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Alice: Decrypting Bob's scores\")\n", "with timer() as t:\n", @@ -3464,18 +3403,10 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "ed338750-e553-4b87-81d3-72338dd9116f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Error 0.014 -- this is not known to Alice, who does not possess the ground truth labels\n" - ] - } - ], + "outputs": [], "source": [ "error = np.mean(np.sign(scores) != y_test)\n", "print(\n", @@ -3511,7 +3442,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/3-OpenMined-private-AI-series.ipynb b/3-federated-learning/3-OpenMined-private-AI-series.ipynb index 7d3bcb2..0becbc3 100644 --- a/3-federated-learning/3-OpenMined-private-AI-series.ipynb +++ b/3-federated-learning/3-OpenMined-private-AI-series.ipynb @@ -3132,7 +3132,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/duet_iris_classifier/duet-iris-DO.ipynb b/3-federated-learning/duet_iris_classifier/duet-iris-DO.ipynb index adb3593..c958314 100644 --- a/3-federated-learning/duet_iris_classifier/duet-iris-DO.ipynb +++ b/3-federated-learning/duet_iris_classifier/duet-iris-DO.ipynb @@ -2,10 +2,3086 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "b073ea8f-52e3-4fd3-874f-023f514a0b5a", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "
\n", + " The notebook is using\n", + " \n", + " no$\\TeX$book Jupyter Theme (release 2.0.1).\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "##! IGNORE THIS if running on Google Colab\n", "%load_ext notexbook\n", @@ -85,7 +3161,9 @@ "cell_type": "code", "execution_count": null, "id": "plastic-ridge", - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ "duet = sy.launch_duet() # option to add loopback=True if running locally" @@ -348,7 +3426,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/duet_iris_classifier/duet-iris-DS.ipynb b/3-federated-learning/duet_iris_classifier/duet-iris-DS.ipynb index 61d38b6..b8a9a74 100644 --- a/3-federated-learning/duet_iris_classifier/duet-iris-DS.ipynb +++ b/3-federated-learning/duet_iris_classifier/duet-iris-DS.ipynb @@ -2,10 +2,3086 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "6cdb755e-d4c9-4652-93ae-e7f0b7ef2a56", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "
\n", + " The notebook is using\n", + " \n", + " no$\\TeX$book Jupyter Theme (release 2.0.1).\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "##! IGNORE THIS if running on Google Colab\n", "%load_ext notexbook\n", @@ -70,7 +3146,7 @@ "source": [ "import syft as sy\n", "\n", - "SERVER_ID = \"\" # paste server ID here\n", + "SERVER_ID = \"d114821a3dd22ef9c0d9b6e01c42c0be\" # paste server ID here\n", "\n", "duet = sy.duet(SERVER_ID)\n", "# Option to replace with the following if RUNNING locally\n", @@ -356,31 +3432,22 @@ "from tqdm.notebook import tqdm\n", "\n", "def train(iterations, model, torch_ref, optim, data_ptr, target_ptr):\n", - "\n", " losses = []\n", - "\n", " for i in tqdm(range(iterations), desc=\"Epochs: \"):\n", - "\n", " optim.zero_grad()\n", - "\n", - " output = model(data_ptr)\n", - "\n", + " output = model(data_ptr) # we provide the model only the reference to the data\n", " # nll_loss = negative log-liklihood loss\n", " loss = torch_ref.nn.functional.nll_loss(output, target_ptr.long())\n", "\n", " loss_item = loss.item()\n", - "\n", " loss_value = loss_item.get(\n", " reason=\"To evaluate training progress\", request_block=True, timeout_secs=5\n", " )\n", - "\n", " if i % 10 == 0:\n", " print(\"Epoch\", i, \"loss\", loss_value)\n", "\n", " losses.append(loss_value)\n", - "\n", " loss.backward()\n", - "\n", " optim.step()\n", "\n", " return losses" @@ -549,7 +3616,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/duet_splitnn/1-intro-splitNN.ipynb b/3-federated-learning/duet_splitnn/1-intro-splitNN.ipynb index ab40659..9d443e1 100644 --- a/3-federated-learning/duet_splitnn/1-intro-splitNN.ipynb +++ b/3-federated-learning/duet_splitnn/1-intro-splitNN.ipynb @@ -3108,7 +3108,7 @@ "\n", "### What is a SplitNN?\n", "\n", - "The training of a neural network (`NN`) is 'split' accross one or more hosts. \n", + "The training of a neural network (`NN`) is 'split' across one or more hosts. \n", "\n", "Each model segment is a self contained `NN` that feeds into the segment in front. \n", "\n", @@ -3168,7 +3168,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/duet_splitnn/splitnn-DO.ipynb b/3-federated-learning/duet_splitnn/splitnn-DO.ipynb index d57eae3..9963490 100644 --- a/3-federated-learning/duet_splitnn/splitnn-DO.ipynb +++ b/3-federated-learning/duet_splitnn/splitnn-DO.ipynb @@ -3215,7 +3215,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/3-federated-learning/duet_splitnn/splitnn-DS.ipynb b/3-federated-learning/duet_splitnn/splitnn-DS.ipynb index 02c0147..bca39b9 100644 --- a/3-federated-learning/duet_splitnn/splitnn-DS.ipynb +++ b/3-federated-learning/duet_splitnn/splitnn-DS.ipynb @@ -3357,7 +3357,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4,