Skip to content

Commit

Permalink
chore: linting and code ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
jcabrero committed Jun 14, 2024
1 parent fc9898a commit bda7c50
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 280 deletions.
8 changes: 6 additions & 2 deletions examples/complex_model/network/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))

import nada_algebra.client as na_client

# Import helper functions for creating nillion client and getting keys
from nillion_python_helpers import (create_nillion_client, getNodeKeyFromFile,
getUserKeyFromFile)
from nillion_python_helpers import (
create_nillion_client,
getNodeKeyFromFile,
getUserKeyFromFile,
)

# Load environment variables from a .env file
load_dotenv()
Expand Down
8 changes: 6 additions & 2 deletions examples/linear_regression/network/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))

import nada_algebra.client as na_client

# Import helper functions for creating nillion client and getting keys
from nillion_python_helpers import (create_nillion_client, getNodeKeyFromFile,
getUserKeyFromFile)
from nillion_python_helpers import (
create_nillion_client,
getNodeKeyFromFile,
getUserKeyFromFile,
)

# Load environment variables from a .env file
load_dotenv()
Expand Down
307 changes: 161 additions & 146 deletions examples/multi_layer_perceptron/01_model_provider.ipynb

Large diffs are not rendered by default.

86 changes: 46 additions & 40 deletions examples/multi_layer_perceptron/02_model_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -74,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -83,7 +83,7 @@
"True"
]
},
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -98,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -112,24 +112,24 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Program ID: NhjEBNWqnAVfYvsp4atCjstZPtSKnjx1nQF9Z95zw8vocEztByKoGZbyhY4Fs6F38RWJuLgFniQkzZTqN4vimXr/main\n",
"Model Store ID: a301b88a-5bf5-43fc-b2cd-3ce3c63bab2c\n",
"Model Provider Party ID: 12D3KooWGzPps56nqg5VxtsKjfiGMBR4gPoPybjKJ5fjoNZgNqgQ\n"
"Program ID: 5GnDBJ4brQtS7U3YsUdweoKUfbN7t9CNDaZ7AnVLarwWcRNfQUwr1Ct2aTQsMhhvjb1xeYPfiKAahMz7i5D85ZUd/main\n",
"Model Store ID: d6002305-15f9-4e76-b5aa-510560f89e75\n",
"Model Provider Party ID: 12D3KooWQLbKxRFoa3rcA8do1R2o96yhgxGnJS5RbTr3ZJwQiQay\n"
]
}
],
"source": [
"# This information was provided by the model provider\n",
"with open(\"tmp.json\", \"r\") as provider_variables_file:\n",
"with open(\"data/tmp.json\", \"r\") as provider_variables_file:\n",
" provider_variables = json.load(provider_variables_file)\n",
" \n",
"\n",
"program_id = provider_variables[\"program_id\"]\n",
"model_store_id = provider_variables[\"model_store_id\"]\n",
"model_provider_party_id = provider_variables[\"model_provider_party_id\"]\n",
Expand All @@ -155,22 +155,22 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"test_image = transforms.Compose(\n",
" [\n",
" transforms.Grayscale(),\n",
" transforms.Resize((16,16)),\n",
" transforms.Resize((16, 16)),\n",
" transforms.ToTensor(),\n",
" ]\n",
")(Image.open(\"data/COVID-19_Lung_CT_Scans/COVID-19/COVID-19_0001.png\"))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -179,7 +179,7 @@
"(1, 1, 16, 16)"
]
},
"execution_count": 14,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -225,7 +225,9 @@
" Returns:\n",
" Dict[str, str]: Resulting `model_user_party_id` and `images_store_id`.\n",
" \"\"\"\n",
" secrets = nillion.Secrets(na_client.array(images, \"my_input\", nada_type=na.SecretRational))\n",
" secrets = nillion.Secrets(\n",
" na_client.array(images, \"my_input\", nada_type=na.SecretRational)\n",
" )\n",
"\n",
" secret_bindings = nillion.ProgramBindings(program_id)\n",
" secret_bindings.add_input_party(\"Party1\", party_id)\n",
Expand All @@ -242,16 +244,16 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Images uploaded successfully!\n",
"model_user_user_id: 37Qew8NyqKYEjVCeDNMohPKKj4VSMxZMxRCYV6Snm8wvs1nJxRkynyUKMrXVk8Vkz2eoKpz8BaA58nGdA1SLyJAq\n",
"images_store_id: 00ecd070-3878-4bfa-a4b8-92b11975221a\n"
"model_user_user_id: unDxCapdG2Dp7w2FwajbBWEF6wrinZp1ArKPvqeMxGt32WbkoXcZGQcSJHwDUMvKr4AG6zQnW4GGDaBcCFqtsu3\n",
"images_store_id: 3465b7fe-062e-4528-9fc3-e20bdff86008\n"
]
}
],
Expand Down Expand Up @@ -282,7 +284,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -332,25 +334,25 @@
"\n",
" return {\n",
" \"compute_id\": compute_event.uuid,\n",
" \"output_0\": inference_result[\"my_output_0_0\"] / (2 ** na.get_log_scale()),\n",
" \"output_1\": inference_result[\"my_output_0_1\"] / (2 ** na.get_log_scale()),\n",
" \"output_0\": inference_result[\"my_output_0_0\"] / (2 ** na.get_log_scale()),\n",
" \"output_1\": inference_result[\"my_output_0_1\"] / (2 ** na.get_log_scale()),\n",
" }"
]
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'compute_id': 'e814f72b-55e8-49dd-b68c-4060516357f3',\n",
" 'output_0': -1.10308837890625,\n",
" 'output_1': 0.5345001220703125}"
"{'compute_id': '42b1bcc4-fa08-4260-aa2e-213fb9702f10',\n",
" 'output_0': -1.40350341796875,\n",
" 'output_1': 0.935302734375}"
]
},
"execution_count": 32,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -377,7 +379,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -388,11 +390,13 @@
" def __init__(self) -> None:\n",
" \"\"\"Model is a two layers and an activations\"\"\"\n",
" super(MyNN, self).__init__()\n",
" self.conv1 = torch.nn.Conv2d(in_channels=1, out_channels=2, kernel_size=3, stride=4, padding=1)\n",
" self.conv1 = torch.nn.Conv2d(\n",
" in_channels=1, out_channels=2, kernel_size=3, stride=4, padding=1\n",
" )\n",
" self.pool = torch.nn.AvgPool2d(kernel_size=2, stride=2)\n",
"\n",
" self.fc1 = torch.nn.Linear(in_features=8, out_features=2 )\n",
" \n",
" self.fc1 = torch.nn.Linear(in_features=8, out_features=2)\n",
"\n",
" self.relu = torch.nn.ReLU()\n",
" self.flatten = torch.nn.Flatten()\n",
"\n",
Expand All @@ -407,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -416,7 +420,7 @@
"<All keys matched successfully>"
]
},
"execution_count": 35,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -428,16 +432,16 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.1628, 0.8372], grad_fn=<SoftmaxBackward0>)"
"tensor([0.0880, 0.9120], grad_fn=<SoftmaxBackward0>)"
]
},
"execution_count": 42,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -448,22 +452,24 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.1628, 0.8372])"
"tensor([0.0880, 0.9120])"
]
},
"execution_count": 43,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"torch.softmax(torch.Tensor([result_inference[\"output_0\"], result_inference[\"output_1\"]]), dim=0)"
"torch.softmax(\n",
" torch.Tensor([result_inference[\"output_0\"], result_inference[\"output_1\"]]), dim=0\n",
")"
]
}
],
Expand Down
74 changes: 0 additions & 74 deletions examples/multi_layer_perceptron/helpers.py

This file was deleted.

Loading

0 comments on commit bda7c50

Please sign in to comment.