diff --git a/test/test_crypten.py b/test/test_crypten.py index c8744dd2..4ef7c04a 100644 --- a/test/test_crypten.py +++ b/test/test_crypten.py @@ -283,12 +283,8 @@ def forward(self, input): return out def set_all_parameters(self, value): - self.fc1.weight.data.fill_(value) - self.fc1.bias.data.fill_(value) - self.fc2.weight.data.fill_(value) - self.fc2.bias.data.fill_(value) - self.fc3.weight.data.fill_(value) - self.fc3.bias.data.fill_(value) + for p in self.parameters(): + torch.nn.init.constant_(p, value) class NestedTestModule(nn.Module): @@ -302,9 +298,8 @@ def forward(self, input): out = self.nested(out) def set_all_parameters(self, value): - self.fc1.weight.data.fill_(value) - self.fc1.bias.data.fill_(value) - self.nested.set_all_parameters(value) + for p in self.parameters(): + torch.nn.init.constant_(p, value) # This code only runs when executing the file outside the test harness diff --git a/tutorials/Introduction.ipynb b/tutorials/Introduction.ipynb index 544cd859..80fb30a7 100644 --- a/tutorials/Introduction.ipynb +++ b/tutorials/Introduction.ipynb @@ -77,7 +77,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_1_Basics_of_CrypTen_Tensors.ipynb b/tutorials/Tutorial_1_Basics_of_CrypTen_Tensors.ipynb index d5bfeabe..80471c67 100644 --- a/tutorials/Tutorial_1_Basics_of_CrypTen_Tensors.ipynb +++ b/tutorials/Tutorial_1_Basics_of_CrypTen_Tensors.ipynb @@ -17,7 +17,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -39,18 +39,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tensor([1., 2., 3.])\n", - "tensor([4., 5., 6.])\n" - ] - } - ], + "outputs": [], "source": [ "# Create torch tensor\n", "x = torch.tensor([1.0, 2.0, 3.0])\n", @@ -87,28 +78,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Public addition: tensor([3., 4., 5.])\n", - "Private addition: tensor([3., 4., 5.])\n", - "\n", - "Public subtraction: tensor([-1., 0., 1.])\n", - "Private subtraction: tensor([-1., 0., 1.])\n", - "\n", - "Public multiplication: tensor([2., 4., 6.])\n", - "Private multiplication: tensor([2., 4., 6.])\n", - "\n", - "Public division: tensor([0.5000, 1.0000, 1.5000])\n", - "Private division: tensor([0.5000, 1.0000, 1.5000])\n" - ] - } - ], + "outputs": [], "source": [ "#Arithmetic operations between CrypTensors and plaintext tensors\n", "x_enc = crypten.cryptensor([1.0, 2.0, 3.0])\n", @@ -153,36 +125,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x: tensor([1., 2., 3., 4., 5.])\n", - "y: tensor([5., 4., 3., 2., 1.])\n", - "\n", - "Public (x < y) : tensor([1., 1., 0., 0., 0.])\n", - "Private (x < y) : tensor([1., 1., 0., 0., 0.])\n", - "\n", - "Public (x <= y): tensor([1., 1., 1., 0., 0.])\n", - "Private (x <= y): tensor([1., 1., 1., 0., 0.])\n", - "\n", - "Public (x > y) : tensor([0., 0., 0., 1., 1.])\n", - "Private (x > y) : tensor([0., 0., 0., 1., 1.])\n", - "\n", - "Public (x >= y): tensor([0., 0., 1., 1., 1.])\n", - "Private (x >= y): tensor([0., 0., 1., 1., 1.])\n", - "\n", - "Public (x == y): tensor([0., 0., 1., 0., 0.])\n", - "Private (x == y): tensor([0., 0., 1., 0., 0.])\n", - "\n", - "Public (x != y): tensor([1., 1., 0., 1., 1.])\n", - "Private (x != y): tensor([1., 1., 0., 1., 1.])\n" - ] - } - ], + "outputs": [], "source": [ "#Construct two example CrypTensors\n", "x_enc = crypten.cryptensor([1.0, 2.0, 3.0, 4.0, 5.0])\n", @@ -243,31 +188,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Public reciprocal: tensor([10.0000, 3.3333, 2.0000, 1.0000, 0.6667, 0.5000, 0.4000])\n", - "Private reciprocal: tensor([10.0009, 3.3335, 2.0000, 1.0000, 0.6667, 0.5000, 0.4000])\n", - "\n", - "Public logarithm: tensor([-2.3026, -1.2040, -0.6931, 0.0000, 0.4055, 0.6931, 0.9163])\n", - "Private logarithm: tensor([-2.3181, -1.2110, -0.6997, 0.0004, 0.4038, 0.6918, 0.9150])\n", - "\n", - "Public exponential: tensor([ 1.1052, 1.3499, 1.6487, 2.7183, 4.4817, 7.3891, 12.1825])\n", - "Private exponential: tensor([ 1.1021, 1.3440, 1.6468, 2.7121, 4.4574, 7.3280, 12.0188])\n", - "\n", - "Public square root: tensor([0.3162, 0.5477, 0.7071, 1.0000, 1.2247, 1.4142, 1.5811])\n", - "Private square root: tensor([0.3135, 0.5445, 0.7051, 1.0000, 1.2195, 1.4080, 1.5762])\n", - "\n", - "Public tanh: tensor([0.0997, 0.2913, 0.4621, 0.7616, 0.9051, 0.9640, 0.9866])\n", - "Private tanh: tensor([0.1019, 0.2892, 0.4613, 0.7642, 0.9081, 0.9689, 0.9922])\n" - ] - } - ], + "outputs": [], "source": [ "torch.set_printoptions(sci_mode=False)\n", "\n", @@ -321,20 +244,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "RuntimeError caught: \"Cannot evaluate MPCTensors to boolean values\"\n", - "\n", - "z: tensor(2.)\n", - "z: tensor(2.)\n" - ] - } - ], + "outputs": [], "source": [ "x_enc = crypten.cryptensor(2.0)\n", "y_enc = crypten.cryptensor(4.0)\n", @@ -372,28 +284,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Indexing:\n", - " tensor([1., 2.])\n", - "\n", - "Concatenation:\n", - " tensor([1., 2., 3., 4., 5., 6.])\n", - "\n", - "Stacking:\n", - " tensor([[1., 2., 3.],\n", - " [4., 5., 6.]])\n", - "\n", - "Reshaping:\n", - " tensor([[1., 2., 3., 4., 5., 6.]])\n" - ] - } - ], + "outputs": [], "source": [ "x_enc = crypten.cryptensor([1.0, 2.0, 3.0])\n", "y_enc = crypten.cryptensor([4.0, 5.0, 6.0])\n", @@ -411,7 +304,7 @@ "print('\\nStacking:\\n', z_enc.get_plain_text())\n", "\n", "# Reshaping\n", - "w_enc = z_enc.reshape(-1, 6)\n", + "w_enc = z_enc.reshape((-1, 6))\n", "print('\\nReshaping:\\n', w_enc.get_plain_text())\n" ] }, @@ -446,7 +339,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_2_Inside_CrypTensors.ipynb b/tutorials/Tutorial_2_Inside_CrypTensors.ipynb index 50821d5f..17cc3660 100644 --- a/tutorials/Tutorial_2_Inside_CrypTensors.ipynb +++ b/tutorials/Tutorial_2_Inside_CrypTensors.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -49,18 +49,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x_enc internal type: ptype.arithmetic\n", - "y_enc internal type: ptype.binary\n" - ] - } - ], + "outputs": [], "source": [ "#Constructing CrypTensors with ptype attribute\n", "\n", @@ -90,28 +81,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rank 0:\n", - " MPCTensor(\n", - "\t_tensor=tensor([1559458991263271971, 464556655590487085, 3264140948701540070])\n", - "\tplain_text=HIDDEN\n", - "\tptype=ptype.arithmetic\n", - ")Rank 1:\n", - " MPCTensor(\n", - "\t_tensor=tensor([-1559458991263206435, -464556655590356013, -3264140948701343462])\n", - "\tplain_text=HIDDEN\n", - "\tptype=ptype.arithmetic\n", - ")\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "import crypten.mpc as mpc\n", "import crypten.communicator as comm \n", @@ -142,28 +114,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rank 0:\n", - " MPCTensor(\n", - "\t_tensor=tensor([ 125494978816570963, 7944957613546045877])\n", - "\tplain_text=HIDDEN\n", - "\tptype=ptype.binary\n", - ")Rank 1:\n", - " MPCTensor(\n", - "\t_tensor=tensor([ 125494978816570961, 7944957613546045878])\n", - "\tplain_text=HIDDEN\n", - "\tptype=ptype.binary\n", - ")\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def examine_binary_shares():\n", @@ -187,24 +140,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "to(crypten.binary):\n", - " ptype: ptype.binary\n", - " plaintext: tensor([1., 2., 3.])\n", - "\n", - "to(crypten.arithmetic):\n", - " ptype: ptype.arithmetic\n", - " plaintext: tensor([1., 2., 3.])\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "from crypten.mpc import MPCTensor\n", "\n", @@ -253,22 +191,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rank 0: 0\n", - "Rank 2: 2\n", - "Rank 1: 1\n", - "Source 0: 0.0\n", - "Source 1: 1.0\n", - "Source 2: 2.0\n" - ] - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=3)\n", "def examine_sources():\n", @@ -306,7 +231,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_3_Introduction_to_Access_Control.ipynb b/tutorials/Tutorial_3_Introduction_to_Access_Control.ipynb index 6e594add..da7aa1e2 100644 --- a/tutorials/Tutorial_3_Introduction_to_Access_Control.ipynb +++ b/tutorials/Tutorial_3_Introduction_to_Access_Control.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -79,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -96,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -111,27 +111,16 @@ "\n", "We have now generated features and labels for our model to learn. In the scenarios we explore in this tutorial, we would like to ensure that each party only has access to some subset of the data we have generated. To do so, we will use special save / load methods that CrypTen provides to handle loading only to a specified party and synchronizing across processes. \n", "\n", - "We will use `crypten.save()` here to save data from a particular source, then we will load using `crypten.load()` in each example to load on a particular source. The following code will save all data we will use to files, then each example will load its data as necessary.\n", + "We will use `crypten.save_from_party()` here to save data from a particular source, then we will load using `crypten.load_from_party()` in each example to load on a particular source. The following code will save all data we will use to files, then each example will load its data as necessary.\n", "\n", "(Note that because we are operating on a single machine, all processes will have access to all of the files we are using. However, this still will work as expected when operating across machines.)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from crypten import mpc\n", "\n", @@ -153,28 +142,28 @@ "@mpc.run_multiprocess(world_size=2)\n", "def save_all_data():\n", " # Save features, labels for Data Labeling example\n", - " crypten.save(features, filenames[\"features\"])\n", - " crypten.save(labels, filenames[\"labels\"])\n", + " crypten.save_from_party(features, filenames[\"features\"])\n", + " crypten.save_from_party(labels, filenames[\"labels\"])\n", " \n", " # Save split features for Feature Aggregation example\n", " features_alice = features[:50]\n", " features_bob = features[50:]\n", " \n", - " crypten.save(features_alice, filenames[\"features_alice\"], src=ALICE)\n", - " crypten.save(features_bob, filenames[\"features_bob\"], src=BOB)\n", + " crypten.save_from_party(features_alice, filenames[\"features_alice\"], src=ALICE)\n", + " crypten.save_from_party(features_bob, filenames[\"features_bob\"], src=BOB)\n", " \n", " # Save split dataset for Dataset Aggregation example\n", " samples_alice = features[:, :500]\n", " samples_bob = features[:, 500:]\n", - " crypten.save(samples_alice, filenames[\"samples_alice\"], src=ALICE)\n", - " crypten.save(samples_bob, filenames[\"samples_bob\"], src=BOB)\n", + " crypten.save_from_party(samples_alice, filenames[\"samples_alice\"], src=ALICE)\n", + " crypten.save_from_party(samples_bob, filenames[\"samples_bob\"], src=BOB)\n", " \n", " # Save true model weights and biases for Model Hiding example\n", - " crypten.save(w_true, filenames[\"w_true\"], src=ALICE)\n", - " crypten.save(b_true, filenames[\"b_true\"], src=ALICE)\n", + " crypten.save_from_party(w_true, filenames[\"w_true\"], src=ALICE)\n", + " crypten.save_from_party(b_true, filenames[\"b_true\"], src=ALICE)\n", " \n", - " crypten.save(test_features, filenames[\"test_features\"], src=BOB)\n", - " crypten.save(test_labels, filenames[\"test_labels\"], src=BOB)\n", + " crypten.save_from_party(test_features, filenames[\"test_features\"], src=BOB)\n", + " crypten.save_from_party(test_labels, filenames[\"test_labels\"], src=BOB)\n", " \n", "save_all_data()" ] @@ -194,64 +183,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 0 --- Training Accuracy 53.40%\n", - "Epoch 1 --- Training Accuracy 58.70%\n", - "Epoch 2 --- Training Accuracy 63.80%\n", - "Epoch 3 --- Training Accuracy 68.30%\n", - "Epoch 4 --- Training Accuracy 73.60%\n", - "Epoch 6 --- Training Accuracy 81.00%\n", - "Epoch 7 --- Training Accuracy 84.60%\n", - "Epoch 8 --- Training Accuracy 87.00%\n", - "Epoch 10 --- Training Accuracy 91.50%\n", - "Epoch 11 --- Training Accuracy 92.90%\n", - "Epoch 12 --- Training Accuracy 93.80%\n", - "Epoch 13 --- Training Accuracy 94.30%\n", - "Epoch 14 --- Training Accuracy 95.50%\n", - "Epoch 16 --- Training Accuracy 96.30%\n", - "Epoch 17 --- Training Accuracy 96.60%\n", - "Epoch 18 --- Training Accuracy 96.80%\n", - "Epoch 19 --- Training Accuracy 97.60%\n", - "Epoch 20 --- Training Accuracy 97.70%\n", - "Epoch 21 --- Training Accuracy 97.90%\n", - "Epoch 22 --- Training Accuracy 98.20%\n", - "Epoch 23 --- Training Accuracy 98.10%\n", - "Epoch 24 --- Training Accuracy 98.90%\n", - "Epoch 25 --- Training Accuracy 99.20%\n", - "Epoch 26 --- Training Accuracy 99.20%\n", - "Epoch 27 --- Training Accuracy 99.50%\n", - "Epoch 28 --- Training Accuracy 99.80%\n", - "Epoch 29 --- Training Accuracy 99.60%\n", - "Epoch 30 --- Training Accuracy 99.60%\n", - "Epoch 31 --- Training Accuracy 99.50%\n", - "Epoch 32 --- Training Accuracy 99.90%\n", - "Epoch 33 --- Training Accuracy 99.90%\n", - "Epoch 34 --- Training Accuracy 100.00%\n", - "Epoch 35 --- Training Accuracy 100.00%\n", - "Epoch 36 --- Training Accuracy 100.00%\n", - "Epoch 37 --- Training Accuracy 100.00%\n", - "Epoch 38 --- Training Accuracy 100.00%\n", - "Epoch 39 --- Training Accuracy 100.00%\n", - "Test accuracy 92.00%\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from crypten import mpc\n", "\n", @@ -259,8 +193,8 @@ "def data_labeling_example():\n", " \"\"\"Apply data labeling access control model\"\"\"\n", " # Alice loads features, Bob loads labels\n", - " features_enc = crypten.load(filenames[\"features\"], src=ALICE)\n", - " labels_enc = crypten.load(filenames[\"labels\"], src=BOB)\n", + " features_enc = crypten.load_from_party(filenames[\"features\"], src=ALICE)\n", + " labels_enc = crypten.load_from_party(filenames[\"labels\"], src=BOB)\n", " \n", " # Execute training\n", " w, b = train_linear_svm(features_enc, labels_enc, epochs=epochs, lr=lr)\n", @@ -284,71 +218,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 0 --- Training Accuracy 53.40%\n", - "Epoch 1 --- Training Accuracy 58.70%\n", - "Epoch 2 --- Training Accuracy 63.80%\n", - "Epoch 3 --- Training Accuracy 68.30%\n", - "Epoch 4 --- Training Accuracy 73.60%\n", - "Epoch 5 --- Training Accuracy 78.00%\n", - "Epoch 6 --- Training Accuracy 81.00%\n", - "Epoch 7 --- Training Accuracy 84.60%\n", - "Epoch 8 --- Training Accuracy 87.00%\n", - "Epoch 10 --- Training Accuracy 91.50%\n", - "Epoch 11 --- Training Accuracy 92.90%\n", - "Epoch 12 --- Training Accuracy 93.80%\n", - "Epoch 13 --- Training Accuracy 94.30%\n", - "Epoch 14 --- Training Accuracy 95.50%\n", - "Epoch 16 --- Training Accuracy 96.30%\n", - "Epoch 17 --- Training Accuracy 96.60%\n", - "Epoch 18 --- Training Accuracy 96.70%\n", - "Epoch 19 --- Training Accuracy 97.40%\n", - "Epoch 20 --- Training Accuracy 98.30%\n", - "Epoch 21 --- Training Accuracy 98.00%\n", - "Epoch 22 --- Training Accuracy 98.10%\n", - "Epoch 23 --- Training Accuracy 98.00%\n", - "Epoch 24 --- Training Accuracy 98.70%\n", - "Epoch 25 --- Training Accuracy 98.70%\n", - "Epoch 26 --- Training Accuracy 99.30%\n", - "Epoch 27 --- Training Accuracy 99.70%\n", - "Epoch 28 --- Training Accuracy 99.60%\n", - "Epoch 29 --- Training Accuracy 99.50%\n", - "Epoch 30 --- Training Accuracy 99.70%\n", - "Epoch 31 --- Training Accuracy 99.50%\n", - "Epoch 32 --- Training Accuracy 99.60%\n", - "Epoch 33 --- Training Accuracy 99.90%\n", - "Epoch 34 --- Training Accuracy 100.00%\n", - "Epoch 35 --- Training Accuracy 100.00%\n", - "Epoch 36 --- Training Accuracy 100.00%\n", - "Epoch 37 --- Training Accuracy 100.00%\n", - "Epoch 38 --- Training Accuracy 100.00%\n", - "Epoch 39 --- Training Accuracy 100.00%\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def feature_aggregation_example():\n", " \"\"\"Apply feature aggregation access control model\"\"\"\n", " # Alice loads some features, Bob loads other features\n", - " features_alice_enc = crypten.load(filenames[\"features_alice\"], src=ALICE)\n", - " features_bob_enc = crypten.load(filenames[\"features_bob\"], src=BOB)\n", + " features_alice_enc = crypten.load_from_party(filenames[\"features_alice\"], src=ALICE)\n", + " features_bob_enc = crypten.load_from_party(filenames[\"features_bob\"], src=BOB)\n", " \n", " # Concatenate features\n", " features_enc = crypten.cat([features_alice_enc, features_bob_enc], dim=0)\n", @@ -378,71 +257,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 0 --- Training Accuracy 53.40%\n", - "Epoch 1 --- Training Accuracy 58.70%\n", - "Epoch 2 --- Training Accuracy 63.80%\n", - "Epoch 3 --- Training Accuracy 68.30%\n", - "Epoch 5 --- Training Accuracy 78.00%\n", - "Epoch 6 --- Training Accuracy 81.00%\n", - "Epoch 7 --- Training Accuracy 84.60%\n", - "Epoch 8 --- Training Accuracy 87.00%\n", - "Epoch 9 --- Training Accuracy 90.40%\n", - "Epoch 10 --- Training Accuracy 91.50%\n", - "Epoch 11 --- Training Accuracy 92.90%\n", - "Epoch 12 --- Training Accuracy 93.80%\n", - "Epoch 13 --- Training Accuracy 94.40%\n", - "Epoch 14 --- Training Accuracy 95.30%\n", - "Epoch 15 --- Training Accuracy 96.30%\n", - "Epoch 16 --- Training Accuracy 96.20%\n", - "Epoch 17 --- Training Accuracy 96.80%\n", - "Epoch 19 --- Training Accuracy 97.20%\n", - "Epoch 20 --- Training Accuracy 97.90%\n", - "Epoch 21 --- Training Accuracy 97.80%\n", - "Epoch 22 --- Training Accuracy 98.00%\n", - "Epoch 23 --- Training Accuracy 98.90%\n", - "Epoch 24 --- Training Accuracy 99.20%\n", - "Epoch 25 --- Training Accuracy 99.40%\n", - "Epoch 26 --- Training Accuracy 99.40%\n", - "Epoch 27 --- Training Accuracy 99.60%\n", - "Epoch 28 --- Training Accuracy 99.00%\n", - "Epoch 29 --- Training Accuracy 99.30%\n", - "Epoch 30 --- Training Accuracy 99.30%\n", - "Epoch 31 --- Training Accuracy 99.40%\n", - "Epoch 32 --- Training Accuracy 99.50%\n", - "Epoch 33 --- Training Accuracy 99.90%\n", - "Epoch 34 --- Training Accuracy 99.70%\n", - "Epoch 35 --- Training Accuracy 99.70%\n", - "Epoch 36 --- Training Accuracy 99.90%\n", - "Epoch 38 --- Training Accuracy 100.00%\n", - "Epoch 39 --- Training Accuracy 100.00%\n", - "Test accuracy 92.00%\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def dataset_augmentation_example():\n", " \"\"\"Apply dataset augmentation access control model\"\"\" \n", " # Alice loads some samples, Bob loads other samples\n", - " samples_alice_enc = crypten.load(filenames[\"samples_alice\"], src=ALICE)\n", - " samples_bob_enc = crypten.load(filenames[\"samples_bob\"], src=BOB)\n", + " samples_alice_enc = crypten.load_from_party(filenames[\"samples_alice\"], src=ALICE)\n", + " samples_bob_enc = crypten.load_from_party(filenames[\"samples_bob\"], src=BOB)\n", " \n", " # Concatenate features\n", " samples_enc = crypten.cat([samples_alice_enc, samples_bob_enc], dim=1)\n", @@ -473,37 +297,19 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Test accuracy 100.00%\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def model_hiding_example():\n", " \"\"\"Apply model hiding access control model\"\"\"\n", " # Alice loads the model\n", - " w_true_enc = crypten.load(filenames[\"w_true\"], src=ALICE)\n", - " b_true_enc = crypten.load(filenames[\"b_true\"], src=ALICE)\n", + " w_true_enc = crypten.load_from_party(filenames[\"w_true\"], src=ALICE)\n", + " b_true_enc = crypten.load_from_party(filenames[\"b_true\"], src=ALICE)\n", " \n", " # Bob loads the features to be evaluated\n", - " test_features_enc = crypten.load(filenames[\"test_features\"], src=BOB)\n", + " test_features_enc = crypten.load_from_party(filenames[\"test_features\"], src=BOB)\n", " \n", " # Evaluate model\n", " evaluate_linear_svm(test_features_enc, test_labels, w_true_enc, b_true_enc)\n", @@ -524,7 +330,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -551,7 +357,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb b/tutorials/Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb index 04cff3ef..2cc63a77 100644 --- a/tutorials/Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb +++ b/tutorials/Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -74,7 +74,11 @@ " out = self.fc2(out)\n", " out = F.relu(out)\n", " out = self.fc3(out)\n", - " return out" + " return out\n", + " \n", + " def set_all_parameters(self, value):\n", + " for p in self.parameters():\n", + " nn.init.constant_(p, value)" ] }, { @@ -86,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -109,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -123,7 +127,7 @@ "source": [ "In CrypTen, encrypting PyTorch network is straightforward: we load a PyTorch model from file to the appropriate source, convert it to a CrypTen model and then encrypt it. Let us understand each of these steps.\n", "\n", - "As we did with CrypTensors in Tutorial 3, we will use CrypTen's load functionality (i.e., `crypten.load`) to read a model from file to a particular source. The source is indicated by the keyword argument `src`. As in Tutorial 3, this src argument tells us the rank of the party we want to load the model to (and later, encrypt the model from). In addition, here we also need to provide a dummy model to tell CrypTen the model's structure. The dummy model is indicated by the keyword argument `dummy_model`. Note that unlike loading a tensor, the result from `crypten.load` is not encrypted. Instead, only the `src` party's model is populated from the file.\n", + "As we did with CrypTensors in Tutorial 3, we will use CrypTen's load functionality (i.e., `crypten.load_from_party`) to read a model from file to a particular source. The source is indicated by the keyword argument `src`. As in Tutorial 3, this src argument tells us the rank of the party we want to load the model to (and later, encrypt the model from). In addition, here we also need to provide a dummy model to tell CrypTen the model's structure. The dummy model is indicated by the keyword argument `dummy_model`. Note that unlike loading a tensor, the result from `crypten.load_from_party` is not encrypted. Instead, only the `src` party's model is populated from the file.\n", "\n", "Once the model is loaded, we call the function `from_pytorch`: this function sets up a CrypTen network from the PyTorch network. It takes the plaintext network as input as well as dummy input. The dummy input must be a `torch` tensor of the same shape as a potential input to the network, however the values inside the tensor do not matter. \n", "\n", @@ -132,21 +136,13 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Model successfully encrypted: True\n" - ] - } - ], + "outputs": [], "source": [ "# Load pre-trained model to Alice\n", "dummy_model = AliceNet()\n", - "plaintext_model = crypten.load('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", + "plaintext_model = crypten.load_from_party('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", "\n", "# Encrypt the model from Alice: \n", "\n", @@ -174,28 +170,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\tAccuracy: 99.0000\n", - "\tAccuracy: 99.0000\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 0, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import crypten.mpc as mpc\n", "import crypten.communicator as comm\n", @@ -206,7 +183,7 @@ "@mpc.run_multiprocess(world_size=2)\n", "def encrypt_model_and_data():\n", " # Load pre-trained model to Alice\n", - " model = crypten.load('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", + " model = crypten.load_from_party('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", " \n", " # Encrypt model from Alice \n", " dummy_input = torch.empty((1, 784))\n", @@ -214,7 +191,7 @@ " private_model.encrypt(src=ALICE)\n", " \n", " # Load data to Bob\n", - " data_enc = crypten.load('/tmp/bob_test.pth', src=BOB)\n", + " data_enc = crypten.load_from_party('/tmp/bob_test.pth', src=BOB)\n", " data_enc2 = data_enc[:count]\n", " data_flatten = data_enc2.flatten(start_dim=1)\n", "\n", @@ -243,45 +220,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Output tensor encrypted: True\n", - "Output tensor encrypted: True\n", - "Decrypted labels:\n", - "Decrypted labels:\n", - " tensor([7, 2, 1, 0, 4, 1, 4, 9, 6, 9, 0, 6, 9, 0, 1, 5, 9, 7, 3, 4, 9, 6, 6, 5,\n", - " 4, 0, 7, 4, 0, 1, 3, 1, 3, 4, 7, 2, 7, 1, 2, 1, 1, 7, 4, 2, 3, 5, 1, 2,\n", - " 4, 4, 6, 3, 5, 5, 6, 0, 4, 1, 9, 5, 7, 8, 9, 3, 7, 4, 6, 4, 3, 0, 7, 0,\n", - " 2, 9, 1, 7, 3, 2, 9, 7, 7, 6, 2, 7, 8, 4, 7, 3, 6, 1, 3, 6, 9, 3, 1, 4,\n", - " 1, 7, 6, 9])\n", - " tensor([7, 2, 1, 0, 4, 1, 4, 9, 6, 9, 0, 6, 9, 0, 1, 5, 9, 7, 3, 4, 9, 6, 6, 5,\n", - " 4, 0, 7, 4, 0, 1, 3, 1, 3, 4, 7, 2, 7, 1, 2, 1, 1, 7, 4, 2, 3, 5, 1, 2,\n", - " 4, 4, 6, 3, 5, 5, 6, 0, 4, 1, 9, 5, 7, 8, 9, 3, 7, 4, 6, 4, 3, 0, 7, 0,\n", - " 2, 9, 1, 7, 3, 2, 9, 7, 7, 6, 2, 7, 8, 4, 7, 3, 6, 1, 3, 6, 9, 3, 1, 4,\n", - " 1, 7, 6, 9])\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 0, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def encrypt_model_and_data():\n", " # Load pre-trained model to Alice\n", - " plaintext_model = crypten.load('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", + " plaintext_model = crypten.load_from_party('models/tutorial4_alice_model.pth', dummy_model=dummy_model, src=ALICE)\n", " \n", " # Encrypt model from Alice \n", " dummy_input = torch.empty((1, 784))\n", @@ -289,7 +235,7 @@ " private_model.encrypt(src=ALICE)\n", " \n", " # Load data to Bob\n", - " data_enc = crypten.load('/tmp/bob_test.pth', src=BOB)\n", + " data_enc = crypten.load_from_party('/tmp/bob_test.pth', src=BOB)\n", " data_enc2 = data_enc[:count]\n", " data_flatten = data_enc2.flatten(start_dim=1)\n", "\n", @@ -323,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -383,7 +329,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb b/tutorials/Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb index 563187c1..f79e0c30 100644 --- a/tutorials/Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb +++ b/tutorials/Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -52,27 +52,24 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Plaintext Weights: Parameter containing:\n", - "tensor([[ 0.1231, -0.3265, 0.2590, -0.0752],\n", - " [-0.2957, 0.1935, 0.2226, -0.0387]], requires_grad=True)\n", - "Plaintext Bias: Parameter containing:\n", - "tensor([ 0.1789, -0.0787], requires_grad=True)\n" - ] - } - ], + "outputs": [], "source": [ "import torch.nn as nn\n", + "import types\n", "\n", "# Instantiate single Linear layer\n", "layer_linear = nn.Linear(4, 2)\n", "\n", + "def set_all_parameters(module, value):\n", + " for p in module.parameters():\n", + " nn.init.constant_(p, value)\n", + "\n", + "# Make sure we have the set_all_parameters method added to the\n", + "# Linear Module since this is not native to PyTorch\n", + "nn.Linear.set_all_parameters = set_all_parameters\n", + "\n", "# The weights and the bias are initialized to small random values\n", "print(\"Plaintext Weights:\", layer_linear._parameters['weight'])\n", "print(\"Plaintext Bias:\", layer_linear._parameters['bias'])\n", @@ -95,38 +92,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Weights:\n", - " tensor([[ 2898316751075970645, -4579388503044133723, 5038242173536375749,\n", - " -1490107348288071119],\n", - " [-1557770914353334546, -2564120523467162291, -6444290604699277632,\n", - " -1291727171320069465]])\n", - "Bias:\n", - " tensor([2530322031011295021, 3780145476852328879])\n", - "\n", - "Decrypted result:\n", - " tensor([[ 0.4359, -0.0401],\n", - " [ 0.3171, -0.1922],\n", - " [ 0.2721, -0.2406]])\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import crypten.mpc as mpc\n", "import crypten.communicator as comm\n", @@ -136,7 +111,7 @@ " rank = comm.get().get_rank()\n", " \n", " # Load and encrypt the layer\n", - " layer = crypten.load(layer_linear_file, dummy_model=nn.Linear(4, 2), src=ALICE)\n", + " layer = crypten.load_from_party(layer_linear_file, dummy_model=nn.Linear(4, 2), src=ALICE)\n", " layer_enc = crypten.nn.from_pytorch(layer, dummy_input=torch.empty((1,4)))\n", " layer_enc.encrypt(src=ALICE)\n", " \n", @@ -147,7 +122,7 @@ " print()\n", " \n", " # Load and encrypt data\n", - " data_enc = crypten.load(toy_data_file, src=BOB)\n", + " data_enc = crypten.load_from_party(toy_data_file, src=BOB)\n", " \n", " # Apply the encrypted layer (linear transformation):\n", " result_enc = layer_enc.forward(data_enc)\n", @@ -173,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -203,38 +178,21 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Weights:\n", - " tensor([[ 3824570129683350441, -8540765741594476771, -3033476021071207225],\n", - " [-3600177681891051605, -5879382445495720845, 981762740632649929],\n", - " [-8080559122370361369, -1390179875616073746, 5513490018807349512]])\n", - "Bias:\n", - " tensor([-1285976053388686819, -5042828109819508063, -6784293398454048581])\n", - "\n", - "Plaintext result:\n", - " tensor([[5., 5., 5.],\n", - " [5., 5., 5.]])\n" - ] - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def forward_scaling_layer():\n", " rank = comm.get().get_rank()\n", " \n", " # Load and encrypt the layer\n", - " layer = crypten.load(layer_scale_file, dummy_model=nn.Linear(3, 3), src=ALICE)\n", + " layer = crypten.load_from_party(layer_scale_file, dummy_model=nn.Linear(3, 3), src=ALICE)\n", " layer_enc = crypten.nn.from_pytorch(layer, dummy_input=torch.empty((1,3)))\n", " layer_enc.encrypt(src=ALICE)\n", " \n", " # Load and encrypt data\n", - " data_enc = crypten.load(toy_data_file, src=BOB) \n", + " data_enc = crypten.load_from_party(toy_data_file, src=BOB) \n", " \n", " # Note that layer parameters are (still) encrypted:\n", " if rank == 0: # Print once for readability\n", @@ -279,7 +237,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -307,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -325,26 +283,18 @@ " out = self.fc1(x)\n", " out = F.relu(out)\n", " out = self.fc2(out)\n", - " return out" + " return out\n", + " \n", + " def set_all_parameters(self, value):\n", + " for p in self.parameters():\n", + " nn.init.constant_(p, value)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 99 Loss: 0.2470429241657257\n", - "Epoch 199 Loss: 0.08965438604354858\n", - "Epoch 299 Loss: 0.05166155472397804\n", - "Epoch 399 Loss: 0.03510778397321701\n", - "Epoch 499 Loss: 0.026072446256875992\n" - ] - } - ], + "outputs": [], "source": [ "# Train and save Alice's network\n", "model = AliceNet()\n", @@ -385,22 +335,12 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Name: 5 \tModule: \n", - "Name: 6 \tModule: \n", - "Name: output \tModule: \n" - ] - } - ], + "outputs": [], "source": [ "# Load the trained network to Alice\n", - "model_plaintext = crypten.load(sample_trained_model_file, dummy_model=AliceNet(), src=ALICE)\n", + "model_plaintext = crypten.load_from_party(sample_trained_model_file, dummy_model=AliceNet(), src=ALICE)\n", "\n", "# Convert the trained network to CrypTen network \n", "private_model = crypten.nn.from_pytorch(model_plaintext, dummy_input=torch.empty((1, 50)))\n", @@ -423,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -436,134 +376,21 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rank: 0 First Linear Layer: Output Encrypted: True\n", - "Rank: 1 First Linear Layer: Output Encrypted: True\n", - "\n", - "\n", - "Rank: 1 Shares after First Linear Layer:tensor([[-6301967327924596124, 1441054799224171566, 6544478469984047445,\n", - " 5552031352886356103, 5272638317470990646, 7596515253675258249,\n", - " -69400202746828565, 5828418225954818579, -4749428913547144580,\n", - " 6606576454575994085, -8611449871174003033, -6879516893031986420,\n", - " -6036166085005125285, -4328313888449389705, -1251365986125740619,\n", - " 1495196102692730834, 6980508649455116950, -3898827469711590256,\n", - " -3534438480830590527, 7371155115760810984],\n", - " [-6302093306442423781, 1441068736631097953, 6544305404511755054,\n", - " 5552029867695634565, 5272413795589744532, 7596469503207299393,\n", - " -69427899322696412, 5828641617418962017, -4749404070611225973,\n", - " 6606436629940671374, -8611581346037569523, -6879276243271746212,\n", - " -6036089440109381038, -4328277524632069842, -1251216352309478973,\n", - " 1495192104950105102, 6980505109848126085, -3898641388919762689,\n", - " -3534384514954890154, 7371263553023027417],\n", - " [-6302196016530670846, 1441068422199275460, 6544443190226594007,\n", - " 5551897792045937027, 5272509097568418791, 7596546678139037730,\n", - " -69306306479188599, 5828478682830348811, -4749419202150460350,\n", - " 6606494462688830463, -8611676291652022053, -6879452222434676411,\n", - " -6035926685963266004, -4328281958910070566, -1251144220136015792,\n", - " 1495257173537946749, 6980624771196506827, -3898680292457191596,\n", - " -3534469608370045576, 7371273537554122402]])\n", - "Rank: 0 Shares after First Linear Layer:tensor([[ 6301967327924594800, -1441054799224176132, -6544478469984052362,\n", - " -5552031352886337494, -5272638317470974057, -7596515253675304938,\n", - " 69400202746838963, -5828418225954796072, 4749428913547168229,\n", - " -6606576454575990257, 8611449871174013243, 6879516893031998421,\n", - " 6036166085005223019, 4328313888449341972, 1251365986125818451,\n", - " -1495196102692711430, -6980508649455074221, 3898827469711585822,\n", - " 3534438480830525249, -7371155115760827632],\n", - " [ 6302093306442492083, -1441068736631147091, -6544305404511679859,\n", - " -5552029867695630280, -5272413795589733129, -7596469503207352552,\n", - " 69427899322731120, -5828641617418886389, 4749404070611239923,\n", - " -6606436629940739146, 8611581346037528727, 6879276243271785375,\n", - " 6036089440109297098, 4328277524632063893, 1251216352309547208,\n", - " -1495192104950139917, -6980505109848110538, 3898641388919730573,\n", - " 3534384514954863793, -7371263553022910235],\n", - " [ 6302196016530668683, -1441068422199236029, -6544443190226441867,\n", - " -5551897792045847705, -5272509097568441345, -7596546678139042775,\n", - " 69306306479163138, -5828478682830264817, 4749419202150444357,\n", - " -6606494462688755085, 8611676291652106198, 6879452222434649489,\n", - " 6035926685963163807, 4328281958910026926, 1251144220135913003,\n", - " -1495257173538037216, -6980624771196606705, 3898680292457184428,\n", - " 3534469608370108188, -7371273537554142112]])\n", - "\n", - "\n", - "Rank: 1 ReLU:\n", - " Output Encrypted: True\n", - "Rank: 0 ReLU:\n", - " Output Encrypted: True\n", - "\n", - "\n", - "Rank: 1 Shares after ReLU: tensor([[ 20335834269325, -1862188223396, -22422596809382, -122992649562725,\n", - " -10942144055156, -92661931292462, 36370634722858, -4303917317055,\n", - " -95427716802747, 29753629293586, -132682053296116, 4382837271338,\n", - " 43569228086006, 56871160109942, -96186304271390, -91283597225481,\n", - " 52829263593360, 55452337381297, 126612973214354, 15568818343686],\n", - " [ -17053860036317, 104771133945462, -60277585643193, 35958852287441,\n", - " -566669716469, -132755904050627, 76984972926220, -86073992441543,\n", - " 22045980827559, 4491870038315, 6641766124207, -55543264340776,\n", - " -41736636970115, 23671078654926, -24869162319256, 16410704404076,\n", - " -9730287511525, 94768289625541, 109861819356995, -70891427648082],\n", - " [ 116804010453248, 60503265100564, -112710955152682, 126888227914592,\n", - " -104831560868555, 12800177436538, -67091481533778, -121809366681463,\n", - " 33047461688871, 124048872586605, 131754259871630, -132092660148971,\n", - " -104098037363125, 133067523930206, 63709774860683, 117051494575337,\n", - " -84071442093666, -134046287225625, -25504913510647, 124269544358526]])\n", - "Rank: 0 Shares after ReLU: tensor([[ -20335834269325, 1862188223396, 22422596809382, 122992649581334,\n", - " 10942144071745, 92661931292462, -36370634712460, 4303917339562,\n", - " 95427716826396, -29753629289758, 132682053306326, -4382837259337,\n", - " -43569227988272, -56871160109942, 96186304349222, 91283597244885,\n", - " -52829263550631, -55452337381297, -126612973214354, -15568818343686],\n", - " [ 17053860104619, -104771133945462, 60277585718388, -35958852283156,\n", - " 566669727872, 132755904050627, -76984972891512, 86073992517171,\n", - " -22045980813609, -4491870038315, -6641766124207, 55543264379939,\n", - " 41736636970115, -23671078654926, 24869162387491, -16410704404076,\n", - " 9730287527072, -94768289625541, -109861819356995, 70891427765264],\n", - " [-116804010453248, -60503265061133, 112710955304822, -126888227825270,\n", - " 104831560868555, -12800177436538, 67091481533778, 121809366765457,\n", - " -33047461688871, -124048872511227, -131754259787485, 132092660148971,\n", - " 104098037363125, -133067523930206, -63709774860683, -117051494575337,\n", - " 84071442093666, 134046287225625, 25504913573259, -124269544358526]])\n", - "\n", - "\n", - "Rank: 0 Second Linear layer:\n", - " Output Encrypted: True\n", - "Rank: 1 Second Linear layer:\n", - " Output Encrypted: True\n", - "\n", - "\n", - "Rank: 1 Shares after Second Linear layer:tensor([[1882203379329708255, 177137915967743634],\n", - " [1882366010665404070, 177083972450471081],\n", - " [1882280922776987770, 177180435755488709]])\n", - "Rank: 0 Shares after Second Linear layer:tensor([[-1882203379329880952, -177137915967574144],\n", - " [-1882366010665264043, -177083972450557034],\n", - " [-1882280922776701637, -177180435755712083]])\n", - "\n", - "\n", - "Decrypted output:\n", - " Output Encrypted: False\n", - "Tensors:\n", - " tensor([[-2.6351, 2.5862],\n", - " [ 2.1366, -1.3115],\n", - " [ 4.3660, -3.4084]])\n" - ] - } - ], + "outputs": [], "source": [ "@mpc.run_multiprocess(world_size=2)\n", "def step_through_two_layers(): \n", " rank = comm.get().get_rank()\n", "\n", " # Load and encrypt the network\n", - " model = crypten.load(sample_trained_model_file, dummy_model=AliceNet(), src=ALICE)\n", + " model = crypten.load_from_party(sample_trained_model_file, dummy_model=AliceNet(), src=ALICE)\n", " private_model = crypten.nn.from_pytorch(model, dummy_input=torch.empty((1, 50)))\n", " private_model.encrypt(src=ALICE)\n", "\n", " # Load and encrypt the data\n", - " data_enc = crypten.load(sample_data_bob_file, src=BOB)\n", + " data_enc = crypten.load_from_party(sample_data_bob_file, src=BOB)\n", "\n", " # Forward through the first layer\n", " out_enc = private_model._modules['5'].forward(data_enc)\n", @@ -604,40 +431,9 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Name: 24 \tModule: \n", - "Name: 25 \tModule: \n", - "Name: 26 \tModule: \n", - "Name: 27 \tModule: \n", - "Name: 28 \tModule: \n", - "Name: 29 \tModule: \n", - "Name: 30 \tModule: \n", - "Name: 31 \tModule: \n", - "Name: 32 \tModule: \n", - "Name: 33 \tModule: \n", - "Name: 34 \tModule: \n", - "Name: 35 \tModule: \n", - "Name: 36 \tModule: \n", - "Name: 37 \tModule: \n", - "Name: 38 \tModule: \n", - "Name: 39 \tModule: \n", - "Name: 40 \tModule: \n", - "Name: 41 \tModule: \n", - "Name: 42 \tModule: \n", - "Name: 43 \tModule: \n", - "Name: 44 \tModule: \n", - "Name: 45 \tModule: \n", - "Name: 46 \tModule: \n", - "Name: output \tModule: \n" - ] - } - ], + "outputs": [], "source": [ "# Define Alice's network\n", "class AliceNet2(nn.Module):\n", @@ -693,7 +489,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -719,7 +515,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_6_CrypTen_on_AWS_instances.ipynb b/tutorials/Tutorial_6_CrypTen_on_AWS_instances.ipynb index 5948fa9e..4ff9f945 100644 --- a/tutorials/Tutorial_6_CrypTen_on_AWS_instances.ipynb +++ b/tutorials/Tutorial_6_CrypTen_on_AWS_instances.ipynb @@ -27,216 +27,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Running world size 2 with instances: [ec2.Instance(id='i-0615648acb65e87ed'), ec2.Instance(id='i-0c9ae083275ab0b73')]\n", - "Connecting to i-0615648acb65e87ed...\n", - "Connected to i-0615648acb65e87ed\n", - "Connecting to i-0c9ae083275ab0b73...\n", - "Connected to i-0c9ae083275ab0b73\n", - "Uploading `/private/home/shobha/CrypTen/examples/mpc_linear_svm/launcher.py` to i-0615648acb65e87ed...\n", - "Uploading `/private/home/shobha/CrypTen/examples/mpc_linear_svm/mpc_linear_svm.py` to i-0615648acb65e87ed...\n", - "Uploading `/private/home/shobha/CrypTen/examples/mpc_linear_svm/launcher.py` to i-0c9ae083275ab0b73...\n", - "Uploading `/private/home/shobha/CrypTen/examples/mpc_linear_svm/mpc_linear_svm.py` to i-0c9ae083275ab0b73...\n", - "`/private/home/shobha/CrypTen/examples/mpc_linear_svm/launcher.py` uploaded to i-0615648acb65e87ed.\n", - "`/private/home/shobha/CrypTen/examples/mpc_linear_svm/mpc_linear_svm.py` uploaded to i-0615648acb65e87ed.\n", - "`/private/home/shobha/CrypTen/examples/mpc_linear_svm/launcher.py` uploaded to i-0c9ae083275ab0b73.\n", - "`/private/home/shobha/CrypTen/examples/mpc_linear_svm/mpc_linear_svm.py` uploaded to i-0c9ae083275ab0b73.\n", - "[i-0615648acb65e87ed] total 16\r\n", - "[i-0615648acb65e87ed] drwxrwxr-x 2 ec2-user ec2-user 4096 Sep 4 20:41 .\r\n", - "[i-0615648acb65e87ed] drwx------ 22 ec2-user ec2-user 4096 Sep 4 20:41 ..\r\n", - "[i-0615648acb65e87ed] -rwxrwxr-x 1 ec2-user ec2-user 2698 Sep 4 20:41 launcher.py\r\n", - "[i-0615648acb65e87ed] -rw-rw-r-- 1 ec2-user ec2-user 3397 Sep 4 20:41 mpc_linear_svm.py\r\n", - "[i-0615648acb65e87ed] \n", - "[i-0c9ae083275ab0b73] total 16\r\n", - "[i-0c9ae083275ab0b73] drwxrwxr-x 2 ec2-user ec2-user 4096 Sep 4 20:41 .\r\n", - "[i-0c9ae083275ab0b73] drwx------ 22 ec2-user ec2-user 4096 Sep 4 20:41 ..\r\n", - "[i-0c9ae083275ab0b73] -rwxrwxr-x 1 ec2-user ec2-user 2698 Sep 4 20:41 launcher.py\r\n", - "[i-0c9ae083275ab0b73] -rw-rw-r-- 1 ec2-user ec2-user 3397 Sep 4 20:41 mpc_linear_svm.py\r\n", - "[i-0c9ae083275ab0b73] \n", - "Run command: export WORLD_SIZE=2; export RENDEZVOUS=env://; export MASTER_ADDR=172.31.67.210; export MASTER_PORT=29500; export RANK=0; cd aws-launcher-tmp-57f5182c-cf54-11e9-8e9f-90e2badb2844 ; ./launcher.py --features 50 --examples 100 --epochs 50 --lr 0.5 --skip_plaintext\n", - "Run command: export WORLD_SIZE=2; export RENDEZVOUS=env://; export MASTER_ADDR=172.31.67.210; export MASTER_PORT=29500; export RANK=1; cd aws-launcher-tmp-57f5182c-cf54-11e9-8e9f-90e2badb2844 ; ./launcher.py --features 50 --examples 100 --epochs 50 --lr 0.5 --skip_plaintext\n", - "[i-0c9ae083275ab0b73] INFO:root:==================\r\n", - "[i-0c9ae083275ab0b73] INFO:root:DistributedCommunicator with rank 1\r\n", - "[i-0c9ae083275ab0b73] INFO:root:==================\r\n", - "[i-0c9ae083275ab0b73] INFO:root:World size = 2\r\n", - "[i-0c9ae083275ab0b73] \n", - "[i-0615648acb65e87ed] INFO:root:==================\r\n", - "[i-0615648acb65e87ed] INFO:root:DistributedCommunicator with rank 0\r\n", - "[i-0615648acb65e87ed] INFO:root:==================\r\n", - "[i-0615648acb65e87ed] INFO:root:World size = 2\r\n", - "[i-0615648acb65e87ed] INFO:root:==================\r\n", - "[i-0615648acb65e87ed] INFO:root:CrypTen Training\r\n", - "[i-0615648acb65e87ed] INFO:root:==================\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 1\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 46.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.028704 (0.028704)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 2\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 49.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015724 (0.022214)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 3\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 49.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015827 (0.020085)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 4\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 50.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015229 (0.018871)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 5\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 53.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014997 (0.018096)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 6\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 54.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015650 (0.017688)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 7\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 54.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015314 (0.017349)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 8\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 55.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015085 (0.017066)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 9\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 58.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015701 (0.016915)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 10\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 59.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015011 (0.016724)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 11\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 60.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014846 (0.016553)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 12\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 63.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015544 (0.016469)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 13\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 64.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015662 (0.016407)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 14\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 66.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015975 (0.016376)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 15\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 68.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015527 (0.016320)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 16\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 70.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015474 (0.016267)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 17\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 71.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.016068 (0.016255)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 18\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 73.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015703 (0.016224)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 19\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 73.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015182 (0.016170)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 20\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 77.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015349 (0.016129)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 21\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 74.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015506 (0.016099)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 22\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 76.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015579 (0.016075)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 23\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 78.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015471 (0.016049)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 24\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 79.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015229 (0.016015)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 25\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 78.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014884 (0.015970)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 26\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 80.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015489 (0.015951)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 27\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 79.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015419 (0.015931)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 28\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 83.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015446 (0.015914)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 29\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 85.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015117 (0.015887)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 30\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 85.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015447 (0.015872)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 31\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 88.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015865 (0.015872)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 32\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 89.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015109 (0.015848)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 33\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 87.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015537 (0.015838)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 34\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 93.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015223 (0.015820)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 35\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 89.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014812 (0.015792)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 36\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 95.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015444 (0.015782)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 37\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 98.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015514 (0.015775)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 38\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 94.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015790 (0.015775)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 39\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 95.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015150 (0.015759)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 40\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 97.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015664 (0.015757)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 41\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 98.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015070 (0.015740)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 42\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 98.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015453 (0.015733)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 43\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 98.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014809 (0.015712)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 44\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 97.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015203 (0.015700)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 45\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015045 (0.015685)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 46\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015024 (0.015671)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 47\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015204 (0.015661)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 48\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015640 (0.015661)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 49\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.014968 (0.015647)\r\n", - "[i-0615648acb65e87ed] INFO:root:Epoch 50\r\n", - "[i-0615648acb65e87ed] INFO:root:--- Accuracy 100.00%\r\n", - "[i-0615648acb65e87ed] INFO:root: Time 0.015066 (0.015635)\r\n", - "[i-0615648acb65e87ed] INFO:root:CrypTen Weights:\r\n", - "[i-0615648acb65e87ed] INFO:root:tensor([[ 0.6266, 0.0708, -0.8273, 1.1054, 2.2259, 1.0269, -0.2454, 0.3465,\r\n", - "[i-0615648acb65e87ed] -0.2064, 1.1096, -0.4470, -0.9675, 0.8815, -0.0456, -0.3211, -0.4172,\r\n", - "[i-0615648acb65e87ed] -0.1068, -0.4309, 1.6191, 0.9273, 1.3629, -0.4860, -0.4709, 0.1397,\r\n", - "[i-0615648acb65e87ed] -0.1461, -1.2914, 0.5050, -0.2048, 0.1133, -0.6340, 0.1254, -0.7410,\r\n", - "[i-0615648acb65e87ed] 0.1307, 1.9361, -1.3594, -0.3963, -1.2906, 1.4484, -0.7685, 0.2926,\r\n", - "[i-0615648acb65e87ed] 0.8602, 0.3248, 0.0922, -0.4171, 0.7996, 0.2740, 0.5352, 0.6995,\r\n", - "[i-0615648acb65e87ed] 0.6882, 0.6521]])\r\n", - "[i-0615648acb65e87ed] INFO:root:CrypTen Bias:\r\n", - "[i-0615648acb65e87ed] INFO:root:tensor([0.2052])\r\n", - "[i-0615648acb65e87ed] \n" - ] - } - ], + "outputs": [], "source": [ "%%script bash\n", "python3 [PATH_TO_CRYPTEN]/CrypTen/scripts/aws_launcher.py \\\n", @@ -250,6 +43,13 @@ "--lr 0.5 \\\n", "--skip_plaintext" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -268,7 +68,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/tutorials/Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb b/tutorials/Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb index a0ffacac..89bec05a 100644 --- a/tutorials/Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb +++ b/tutorials/Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -96,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -107,30 +107,19 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load Alice's data \n", - "data_alice_enc = crypten.load('/tmp/alice_train.pth', src=ALICE)" + "data_alice_enc = crypten.load_from_party('/tmp/alice_train.pth', src=ALICE)" ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 0, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# We'll now set up the data for our small example below\n", "# For illustration purposes, we will create toy data\n", @@ -155,18 +144,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch: 0 Loss: 0.5206\n", - "Epoch: 1 Loss: 0.4807\n" - ] - } - ], + "outputs": [], "source": [ "# Example: Stochastic Gradient Descent in CrypTen\n", "\n", @@ -210,48 +190,9 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 0 in progress:\n", - "\tBatch 1 of 10 Loss 0.4977\n", - "\tBatch 2 of 10 Loss 0.4340\n", - "\tBatch 3 of 10 Loss 0.3488\n", - "\tBatch 4 of 10 Loss 0.3358\n", - "\tBatch 5 of 10 Loss 0.2479\n", - "\tBatch 6 of 10 Loss 0.2365\n", - "\tBatch 7 of 10 Loss 0.2739\n", - "\tBatch 8 of 10 Loss 0.2007\n", - "\tBatch 9 of 10 Loss 0.2303\n", - "\tBatch 10 of 10 Loss 0.1538\n", - "Epoch 1 in progress:\n", - "\tBatch 1 of 10 Loss 0.1557\n", - "\tBatch 2 of 10 Loss 0.1142\n", - "\tBatch 3 of 10 Loss 0.1306\n", - "\tBatch 4 of 10 Loss 0.1756\n", - "\tBatch 5 of 10 Loss 0.0804\n", - "\tBatch 6 of 10 Loss 0.1284\n", - "\tBatch 7 of 10 Loss 0.2113\n", - "\tBatch 8 of 10 Loss 0.1103\n", - "\tBatch 9 of 10 Loss 0.1578\n", - "\tBatch 10 of 10 Loss 0.0928\n" - ] - }, - { - "data": { - "text/plain": [ - "[None, None]" - ] - }, - "execution_count": 0, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import crypten.mpc as mpc\n", "import crypten.communicator as comm\n", @@ -265,8 +206,8 @@ "@mpc.run_multiprocess(world_size=2)\n", "def run_encrypted_training():\n", " # Load data:\n", - " x_alice_enc = crypten.load('/tmp/alice_train.pth', src=ALICE)\n", - " x_bob_enc = crypten.load('/tmp/bob_train.pth', src=BOB)\n", + " x_alice_enc = crypten.load_from_party('/tmp/alice_train.pth', src=ALICE)\n", + " x_bob_enc = crypten.load_from_party('/tmp/bob_train.pth', src=BOB)\n", " \n", " # Combine the feature sets: identical to Tutorial 3\n", " x_combined_enc = crypten.cat([x_alice_enc, x_bob_enc], dim=2)\n", @@ -337,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -371,7 +312,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.7.6" } }, "nbformat": 4,