|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 | 5 | "execution_count": 1,
|
6 |
| - "id": "excited-registration", |
| 6 | + "id": "exciting-romance", |
7 | 7 | "metadata": {},
|
8 |
| - "outputs": [ |
9 |
| - { |
10 |
| - "ename": "ImportError", |
11 |
| - "evalue": "libtorch_cpu.so: cannot open shared object file: No such file or directory", |
12 |
| - "output_type": "error", |
13 |
| - "traceback": [ |
14 |
| - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
15 |
| - "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", |
16 |
| - "\u001b[0;32m<ipython-input-1-ebded2444677>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 23\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mtorchcsprng\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mcsprng\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mopacus\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mPrivacyEngine\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
17 |
| - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchcsprng/__init__.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mtorchcsprng\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_C\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
18 |
| - "\u001b[0;31mImportError\u001b[0m: libtorch_cpu.so: cannot open shared object file: No such file or directory" |
19 |
| - ] |
20 |
| - } |
21 |
| - ], |
| 8 | + "outputs": [], |
22 | 9 | "source": [
|
23 | 10 | "import numpy as np # linear algebra\n",
|
24 | 11 | "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
|
|
42 | 29 | "import os\n",
|
43 | 30 | "import sys\n",
|
44 | 31 | "\n",
|
45 |
| - "import torchcsprng as csprng\n", |
| 32 | + "# import torchcsprng as csprng\n", |
46 | 33 | "\n",
|
47 | 34 | "from opacus import PrivacyEngine\n",
|
48 |
| - "from collections import OrderedDict" |
| 35 | + "# from collections import OrderedDict" |
49 | 36 | ]
|
50 | 37 | },
|
51 | 38 | {
|
52 | 39 | "cell_type": "code",
|
53 | 40 | "execution_count": 2,
|
54 |
| - "id": "elegant-carolina", |
55 |
| - "metadata": {}, |
56 |
| - "outputs": [], |
57 |
| - "source": [ |
58 |
| - "import torch" |
59 |
| - ] |
60 |
| - }, |
61 |
| - { |
62 |
| - "cell_type": "code", |
63 |
| - "execution_count": 3, |
64 |
| - "id": "british-hopkins", |
| 41 | + "id": "wicked-cyprus", |
65 | 42 | "metadata": {},
|
66 | 43 | "outputs": [
|
67 | 44 | {
|
|
81 | 58 | {
|
82 | 59 | "cell_type": "code",
|
83 | 60 | "execution_count": null,
|
84 |
| - "id": "controlled-boxing", |
| 61 | + "id": "regulation-witch", |
85 | 62 | "metadata": {},
|
86 | 63 | "outputs": [],
|
87 | 64 | "source": [
|
88 |
| - "try: privacy_engine\n", |
89 |
| - "except NameError: print(\"The Privacy Engine is already Detached\")\n", |
90 |
| - "else: privacy_engine.detach()" |
| 65 | + "# This is to check if the Differential Privacy engine is attached to the optimizer.\n", |
| 66 | + "\n", |
| 67 | + "# try: privacy_engine\n", |
| 68 | + "# except NameError: print(\"The Privacy Engine is already Detached\")\n", |
| 69 | + "# else: privacy_engine.detach()" |
91 | 70 | ]
|
92 | 71 | },
|
93 | 72 | {
|
94 | 73 | "cell_type": "code",
|
95 | 74 | "execution_count": 3,
|
96 |
| - "id": "opponent-figure", |
| 75 | + "id": "cosmetic-undergraduate", |
97 | 76 | "metadata": {},
|
98 | 77 | "outputs": [
|
99 | 78 | {
|
|
236 | 215 | {
|
237 | 216 | "cell_type": "code",
|
238 | 217 | "execution_count": 4,
|
239 |
| - "id": "demonstrated-problem", |
| 218 | + "id": "continental-chemistry", |
240 | 219 | "metadata": {},
|
241 | 220 | "outputs": [],
|
242 | 221 | "source": [
|
243 | 222 | "# We could move this block to a Researcher's notebook\n",
|
244 | 223 | "\n",
|
| 224 | + "# Define model architecture\n", |
| 225 | + "\n", |
245 | 226 | "model = nn.Sequential(\n",
|
246 | 227 | " nn.Linear(8, 4),\n",
|
247 | 228 | " nn.Sigmoid(),\n",
|
|
259 | 240 | "# nn.Linear(2, 1),\n",
|
260 | 241 | "# nn.Sigmoid()\n",
|
261 | 242 | "# )\n",
|
262 |
| - "# define model architecture\n", |
| 243 | + "\n", |
263 | 244 | "# model = nn.Sequential(OrderedDict([\n",
|
264 | 245 | "# ('fc1', nn.Linear(8, 4)),\n",
|
265 | 246 | "# ('relu1', nn.ReLU()),\n",
|
|
269 | 250 | "# ('sigmoid', nn.Sigmoid())\n",
|
270 | 251 | "# ]))\n",
|
271 | 252 | "\n",
|
| 253 | + "\n", |
| 254 | + "# Save the Model\n", |
| 255 | + "\n", |
272 | 256 | "torch.save(model, \"untrained_model.pt\")\n",
|
273 | 257 | "\n",
|
274 | 258 | "# In a Researcher's notebook after saving the model, we have to send it to the Hospitals"
|
|
277 | 261 | {
|
278 | 262 | "cell_type": "code",
|
279 | 263 | "execution_count": 5,
|
280 |
| - "id": "announced-witness", |
281 |
| - "metadata": {}, |
| 264 | + "id": "amateur-allowance", |
| 265 | + "metadata": { |
| 266 | + "scrolled": true |
| 267 | + }, |
282 | 268 | "outputs": [
|
283 | 269 | {
|
284 | 270 | "name": "stdout",
|
|
303 | 289 | {
|
304 | 290 | "cell_type": "code",
|
305 | 291 | "execution_count": 6,
|
306 |
| - "id": "hungarian-consumption", |
| 292 | + "id": "focal-radical", |
307 | 293 | "metadata": {
|
308 | 294 | "scrolled": true
|
309 | 295 | },
|
|
334 | 320 | {
|
335 | 321 | "cell_type": "code",
|
336 | 322 | "execution_count": 7,
|
337 |
| - "id": "changing-ivory", |
| 323 | + "id": "sized-proceeding", |
338 | 324 | "metadata": {},
|
339 | 325 | "outputs": [],
|
340 | 326 | "source": [
|
|
367 | 353 | {
|
368 | 354 | "cell_type": "code",
|
369 | 355 | "execution_count": 8,
|
370 |
| - "id": "appreciated-tender", |
| 356 | + "id": "alternative-logan", |
371 | 357 | "metadata": {},
|
372 | 358 | "outputs": [
|
373 | 359 | {
|
374 | 360 | "name": "stdout",
|
375 | 361 | "output_type": "stream",
|
376 | 362 | "text": [
|
377 |
| - "loss at epoch 0 : tensor(0.2560)\n", |
378 |
| - "loss at epoch 5000 : tensor(0.1331)\n", |
379 |
| - "loss at epoch 10000 : tensor(0.1229)\n", |
380 |
| - "loss at epoch 15000 : tensor(0.1140)\n", |
381 |
| - "loss at epoch 20000 : tensor(0.1120)\n", |
382 |
| - "loss at epoch 25000 : tensor(0.1109)\n", |
383 |
| - "loss at epoch 30000 : tensor(0.1102)\n", |
384 |
| - "loss at epoch 35000 : tensor(0.1094)\n", |
385 |
| - "loss at epoch 40000 : tensor(0.1088)\n", |
386 |
| - "loss at epoch 45000 : tensor(0.1084)\n" |
| 363 | + "loss at epoch 0 : tensor(0.2467)\n", |
| 364 | + "loss at epoch 5000 : tensor(0.1213)\n", |
| 365 | + "loss at epoch 10000 : tensor(0.1138)\n", |
| 366 | + "loss at epoch 15000 : tensor(0.1111)\n", |
| 367 | + "loss at epoch 20000 : tensor(0.1095)\n", |
| 368 | + "loss at epoch 25000 : tensor(0.1082)\n", |
| 369 | + "loss at epoch 30000 : tensor(0.1073)\n", |
| 370 | + "loss at epoch 35000 : tensor(0.1064)\n", |
| 371 | + "loss at epoch 40000 : tensor(0.1056)\n", |
| 372 | + "loss at epoch 45000 : tensor(0.1049)\n" |
387 | 373 | ]
|
388 | 374 | }
|
389 | 375 | ],
|
|
394 | 380 | {
|
395 | 381 | "cell_type": "code",
|
396 | 382 | "execution_count": null,
|
397 |
| - "id": "rubber-insight", |
| 383 | + "id": "instant-insulin", |
398 | 384 | "metadata": {},
|
399 | 385 | "outputs": [],
|
400 | 386 | "source": []
|
|
416 | 402 | "name": "python",
|
417 | 403 | "nbconvert_exporter": "python",
|
418 | 404 | "pygments_lexer": "ipython3",
|
419 |
| - "version": "3.7.6" |
| 405 | + "version": "3.8.5" |
420 | 406 | }
|
421 | 407 | },
|
422 | 408 | "nbformat": 4,
|
|
0 commit comments