From 86ea6587acd1a4df8dba7757b81110cf24491e8b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 30 Jan 2024 13:42:25 +0200 Subject: [PATCH] update mnist tuto with proof --- .gitignore | 3 +- .../verifiable_mnist/verifiable_mnist.ipynb | 1925 ++++++++++++++--- giza_actions/model.py | 56 +- poetry.lock | 62 +- pyproject.toml | 2 +- 5 files changed, 1739 insertions(+), 309 deletions(-) diff --git a/.gitignore b/.gitignore index b7f38a6..edecb2c 100644 --- a/.gitignore +++ b/.gitignore @@ -139,4 +139,5 @@ dmypy.json **/*.jpg **/*.whl **/data -*.sierra \ No newline at end of file +*.sierra +*.proof \ No newline at end of file diff --git a/examples/verifiable_mnist/verifiable_mnist.ipynb b/examples/verifiable_mnist/verifiable_mnist.ipynb index 64761b0..ff30348 100644 --- a/examples/verifiable_mnist/verifiable_mnist.ipynb +++ b/examples/verifiable_mnist/verifiable_mnist.ipynb @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -189,14 +189,14 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def resize_images(images):\n", " return np.array([zoom(image[0], (0.5, 0.5)) for image in images])\n", "\n", - "@task(name=f'Prepare Datasets {uuid.uuid4()}')\n", + "@task(name=f'Prepare Datasets')\n", "def prepare_datasets():\n", " print(\"Prepare dataset...\")\n", " train_dataset = torchvision.datasets.MNIST(root='./data', train=True, download=True)\n", @@ -218,11 +218,11 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "@task(name=f'Create Loaders {uuid.uuid4()}')\n", + "@task(name=f'Create Loaders')\n", "def create_data_loaders(x_train, y_train, x_test, y_test):\n", " print(\"Create loaders...\")\n", "\n", @@ -245,11 +245,11 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "@task(name=f'Train model {uuid.uuid4()}')\n", + "@task(name=f'Train model')\n", "def train_model(train_loader):\n", " print(\"Train model...\")\n", "\n", @@ -287,11 +287,11 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "@task(name=f'Test model {uuid.uuid4()}')\n", + "@task(name=f'Test model')\n", "def test_model(model, test_loader):\n", " print(\"Test model...\")\n", " with torch.no_grad():\n", @@ -337,228 +337,1323 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 8, "metadata": {}, "outputs": [ { - "name": "stdout", + "data": { + "text/html": [ + "
13:32:10.085 | INFO    | Created flow run 'analytic-python' for flow 'Execution'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:10.085 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'analytic-python'\u001b[0m for flow\u001b[1;35m 'Execution'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:10.093 | INFO    | Action run 'analytic-python' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/90cd0605-a006-449e-a118-a05e9c13d710\n",
+       "
\n" + ], + "text/plain": [ + "13:32:10.093 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/90cd0605-a006-449e-a118-a05e9c13d710\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:10.587 | INFO    | Action run 'analytic-python' - Created task run 'Prepare Datasets-0' for task 'Prepare Datasets'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:10.587 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Created task run 'Prepare Datasets-0' for task 'Prepare Datasets'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:10.589 | INFO    | Action run 'analytic-python' - Executing 'Prepare Datasets-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:10.589 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Executing 'Prepare Datasets-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:11.350 | INFO    | Task run 'Prepare Datasets-0' - Prepare dataset...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:11.350 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - Prepare dataset...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:14.699 | INFO    | Task run 'Prepare Datasets-0' - ✅ Datasets prepared successfully\n",
+       "
\n" + ], + "text/plain": [ + "13:32:14.699 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - ✅ Datasets prepared successfully\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:14.921 | INFO    | Task run 'Prepare Datasets-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:14.921 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.076 | INFO    | Action run 'analytic-python' - Created task run 'Create Loaders-0' for task 'Create Loaders'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.076 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Created task run 'Create Loaders-0' for task 'Create Loaders'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.077 | INFO    | Action run 'analytic-python' - Executing 'Create Loaders-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.077 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Executing 'Create Loaders-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.373 | INFO    | Task run 'Create Loaders-0' - Create loaders...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.373 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - Create loaders...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.376 | INFO    | Task run 'Create Loaders-0' - ✅ Loaders created!\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.376 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - ✅ Loaders created!\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.535 | INFO    | Task run 'Create Loaders-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.535 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.662 | INFO    | Action run 'analytic-python' - Created task run 'Train model-0' for task 'Train model'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.662 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Created task run 'Train model-0' for task 'Train model'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:15.665 | INFO    | Action run 'analytic-python' - Executing 'Train model-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:15.665 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Executing 'Train model-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.000 | INFO    | Task run 'Train model-0' - Train model...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.000 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Train model...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.148 | INFO    | Task run 'Train model-0' - Epoch [1/10], Step [100/235], Loss: 1.8331\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.148 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [1/10], Step [100/235], Loss: 1.8331\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.249 | INFO    | Task run 'Train model-0' - Epoch [1/10], Step [200/235], Loss: 1.2023\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.249 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [1/10], Step [200/235], Loss: 1.2023\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.379 | INFO    | Task run 'Train model-0' - Epoch [2/10], Step [100/235], Loss: 0.7310\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.379 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [2/10], Step [100/235], Loss: 0.7310\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.475 | INFO    | Task run 'Train model-0' - Epoch [2/10], Step [200/235], Loss: 0.5814\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.475 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [2/10], Step [200/235], Loss: 0.5814\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.605 | INFO    | Task run 'Train model-0' - Epoch [3/10], Step [100/235], Loss: 0.5005\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.605 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [3/10], Step [100/235], Loss: 0.5005\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.699 | INFO    | Task run 'Train model-0' - Epoch [3/10], Step [200/235], Loss: 0.4724\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.699 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [3/10], Step [200/235], Loss: 0.4724\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.829 | INFO    | Task run 'Train model-0' - Epoch [4/10], Step [100/235], Loss: 0.3806\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.829 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [4/10], Step [100/235], Loss: 0.3806\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:16.925 | INFO    | Task run 'Train model-0' - Epoch [4/10], Step [200/235], Loss: 0.3426\n",
+       "
\n" + ], + "text/plain": [ + "13:32:16.925 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [4/10], Step [200/235], Loss: 0.3426\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.054 | INFO    | Task run 'Train model-0' - Epoch [5/10], Step [100/235], Loss: 0.2829\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.054 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [5/10], Step [100/235], Loss: 0.2829\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.150 | INFO    | Task run 'Train model-0' - Epoch [5/10], Step [200/235], Loss: 0.3104\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.150 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [5/10], Step [200/235], Loss: 0.3104\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.278 | INFO    | Task run 'Train model-0' - Epoch [6/10], Step [100/235], Loss: 0.3393\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.278 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [6/10], Step [100/235], Loss: 0.3393\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.375 | INFO    | Task run 'Train model-0' - Epoch [6/10], Step [200/235], Loss: 0.2847\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.375 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [6/10], Step [200/235], Loss: 0.2847\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.506 | INFO    | Task run 'Train model-0' - Epoch [7/10], Step [100/235], Loss: 0.3399\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.506 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [7/10], Step [100/235], Loss: 0.3399\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.602 | INFO    | Task run 'Train model-0' - Epoch [7/10], Step [200/235], Loss: 0.2392\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.602 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [7/10], Step [200/235], Loss: 0.2392\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.731 | INFO    | Task run 'Train model-0' - Epoch [8/10], Step [100/235], Loss: 0.3694\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.731 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [8/10], Step [100/235], Loss: 0.3694\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:17.826 | INFO    | Task run 'Train model-0' - Epoch [8/10], Step [200/235], Loss: 0.2688\n",
+       "
\n" + ], + "text/plain": [ + "13:32:17.826 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [8/10], Step [200/235], Loss: 0.2688\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.025 | INFO    | Task run 'Train model-0' - Epoch [9/10], Step [100/235], Loss: 0.1915\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.025 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [9/10], Step [100/235], Loss: 0.1915\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.122 | INFO    | Task run 'Train model-0' - Epoch [9/10], Step [200/235], Loss: 0.2370\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.122 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [9/10], Step [200/235], Loss: 0.2370\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.252 | INFO    | Task run 'Train model-0' - Epoch [10/10], Step [100/235], Loss: 0.2531\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.252 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [10/10], Step [100/235], Loss: 0.2531\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.349 | INFO    | Task run 'Train model-0' - Epoch [10/10], Step [200/235], Loss: 0.3103\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.349 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [10/10], Step [200/235], Loss: 0.3103\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.384 | INFO    | Task run 'Train model-0' - ✅ Model trained successfully\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.384 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - ✅ Model trained successfully\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.619 | INFO    | Task run 'Train model-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.619 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.858 | INFO    | Action run 'analytic-python' - Created task run 'Test model-0' for task 'Test model'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.858 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Created task run 'Test model-0' for task 'Test model'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:18.861 | INFO    | Action run 'analytic-python' - Executing 'Test model-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:18.861 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Executing 'Test model-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:19.229 | INFO    | Task run 'Test model-0' - Test model...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:19.229 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Test model...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:19.282 | INFO    | Task run 'Test model-0' - Accuracy of the network on the 10000 test images: 91.65 %\n",
+       "
\n" + ], + "text/plain": [ + "13:32:19.282 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Accuracy of the network on the 10000 test images: 91.65 %\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:19.486 | INFO    | Task run 'Test model-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:19.486 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:19.648 | INFO    | Action run 'analytic-python' - Finished in state Completed('All states completed.')\n",
+       "
\n" + ], + "text/plain": [ + "13:32:19.648 | \u001b[36mINFO\u001b[0m | Action run 'analytic-python' - Finished in state \u001b[32mCompleted\u001b[0m('All states completed.')\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "[Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `tuple`')),\n", + " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `tuple`')),\n", + " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `NeuralNet`')),\n", + " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `NoneType`'))]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "@action(name=f'Execution', log_prints=True )\n", + "def execution():\n", + " x_train, y_train, x_test, y_test = prepare_datasets()\n", + " train_loader, test_loader = create_data_loaders(\n", + " x_train, y_train, x_test, y_test)\n", + " model = train_model(train_loader)\n", + " test_model(model, test_loader)\n", + "\n", + "\n", + "execution()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When you return to your workspace and refresh it, you will observe your action currently in the execution process.\n", + "\n", + "To view all the actions you have run, navigate to the Action Runs section within your workspace. Each action run represents a single occurrence of executing the action.\n", + "\n", + "![Action runs](./imgs/action_runs.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Furthermore, by clicking on a particular action, you can closely monitor its progress. You'll have the ability to view logs, individual tasks, and associated metadata.\n", + "\n", + "![Action](./imgs/action.png)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Deploy your action" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Giza Action enables you to deploy workflows, turning them from manual activation into API-managed entities that can be triggered remotely. Once a workflow is deployed, it creates a deployment within your Giza Workspace, which remains active, awaiting action runs associated with that deployment. When a run is detected, it is asynchronously executed in a local subprocess.\n", + "\n", + "All your deployments can be found in the 'Deployments' section of your Workspace.\n", + "\n", + "![Deployment](./imgs/deployments.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stderr", "output_type": "stream", "text": [ - "Prepare dataset...\n", - "✅ Datasets prepared successfully\n", - "Create loaders...\n", - "✅ Loaders created!\n", - "Train model...\n", - "Epoch [1/10], Step [100/235], Loss: 1.8091\n", - "Epoch [1/10], Step [200/235], Loss: 1.1378\n", - "Epoch [2/10], Step [100/235], Loss: 0.7580\n", - "Epoch [2/10], Step [200/235], Loss: 0.5322\n", - "Epoch [3/10], Step [100/235], Loss: 0.5158\n", - "Epoch [3/10], Step [200/235], Loss: 0.5252\n", - "Epoch [4/10], Step [100/235], Loss: 0.3461\n", - "Epoch [4/10], Step [200/235], Loss: 0.3616\n", - "Epoch [5/10], Step [100/235], Loss: 0.3054\n", - "Epoch [5/10], Step [200/235], Loss: 0.3283\n", - "Epoch [6/10], Step [100/235], Loss: 0.3933\n", - "Epoch [6/10], Step [200/235], Loss: 0.3382\n", - "Epoch [7/10], Step [100/235], Loss: 0.4457\n", - "Epoch [7/10], Step [200/235], Loss: 0.2492\n", - "Epoch [8/10], Step [100/235], Loss: 0.3833\n", - "Epoch [8/10], Step [200/235], Loss: 0.2938\n", - "Epoch [9/10], Step [100/235], Loss: 0.4024\n", - "Epoch [9/10], Step [200/235], Loss: 0.2159\n", - "Epoch [10/10], Step [100/235], Loss: 0.4806\n", - "Epoch [10/10], Step [200/235], Loss: 0.2324\n", - "✅ Model trained successfully\n", - "Test model...\n", - "Accuracy of the network on the 10000 test images: 91.84 %\n" + "/Users/raphaeldoukhan/Library/Caches/pypoetry/virtualenvs/giza-actions-mYf3m_Lk-py3.11/lib/python3.11/site-packages/prefect/flows.py:338: UserWarning: A flow named 'Execution' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/action.py:1' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:\n", + "\n", + " `@flow(name='my_unique_name', ...)`\n", + " warnings.warn(\n", + "/var/folders/s3/6c0gmns50x36dt6vvfhv6jhc0000gn/T/ipykernel_83695/3391579529.py:12: RuntimeWarning: coroutine 'Action.serve' was never awaited\n", + " action_deploy.serve(name=\"pytorch-mnist-deployment\")\n", + "RuntimeWarning: Enable tracemalloc to get the object allocation traceback\n" ] + } + ], + "source": [ + "@action(name=f'Execution', log_prints=True)\n", + "def execution():\n", + " x_train, y_train, x_test, y_test = prepare_datasets()\n", + " train_loader, test_loader = create_data_loaders(\n", + " x_train, y_train, x_test, y_test)\n", + " model = train_model(train_loader)\n", + " test_model(model, test_loader)\n", + "\n", + "# This can only be executed in a Python script, not in a notebook\n", + "if __name__ == '__main__':\n", + " action_deploy = Action(entrypoint=execution, name=\"pytorch-mnist-action\")\n", + " action_deploy.serve(name=\"pytorch-mnist-deployment\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Run and Prove!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Up to this point, we have primarily focused on training and testing our model using PyTorch while monitoring its execution through the Giza platform. However, if you are here, it's likely because you want to harness the capabilities of ZKML (Zero-Knowledge Machine Learning) and have the ability to demonstrate the integrity of your model's inferences.\n", + "\n", + "In this section, we will delve into what it means to prove the integrity of inferences, what setup is required to make this possible, and how to verify the proof." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "ZKML leverages validity proofs like SNARKs and STARKs, which enables the verification of the correctness of computational processes. By deploying such proof systems in machine learning applications, we gain the ability to validate the inference of ML models or to confirm that a specific input produced a certain output with a given model.\n", + "\n", + "To generate ZK proofs for your model inferences, you must first convert your model into ZK circuits. This conversion process involves leveraging programming languages that specialize in building ZK circuits, such as [Cairo-lang](https://www.cairo-lang.org/). Subsequently, using the Giza-CLI, you can transpile your model from ONNX to Cairo. This process will be covered in the upcoming sections.\n", + "\n", + "It's worth mentioning that at present, Orion and Action-SDK exclusively supports Cairo as a ZK backend. However, we are actively working on expanding support for other ZK backends (e.g; EZKL, Noir ...).\n", + "\n", + "![Giza Stack](./imgs/giza_stack.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Convert to ONNX\n", + "\n", + "Before invoking the Giza transpiler to convert your model into Cairo, you must first ensure that your model is converted to ONNX. We will explore this process in the following section.\n", + "\n", + "ONNX, short for Open Neural Network Exchange, is an open format for representing and exchanging machine learning models between different frameworks and libraries. It serves as an intermediary format that allows you to move models seamlessly between various platforms and tools, facilitating interoperability and flexibility in the machine learning ecosystem." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
13:32:20.668 | INFO    | Created flow run 'magenta-griffin' for flow 'Action: Convert To ONNX'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:20.668 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'magenta-griffin'\u001b[0m for flow\u001b[1;35m 'Action: Convert To ONNX'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:20.671 | INFO    | Action run 'magenta-griffin' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/7adf7710-5563-4c1d-8557-503257cf387c\n",
+       "
\n" + ], + "text/plain": [ + "13:32:20.671 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/7adf7710-5563-4c1d-8557-503257cf387c\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:21.109 | INFO    | Action run 'magenta-griffin' - Created task run 'Prepare Datasets-0' for task 'Prepare Datasets'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:21.109 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Created task run 'Prepare Datasets-0' for task 'Prepare Datasets'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:21.112 | INFO    | Action run 'magenta-griffin' - Executing 'Prepare Datasets-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:21.112 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Executing 'Prepare Datasets-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:21.396 | INFO    | Task run 'Prepare Datasets-0' - Prepare dataset...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:21.396 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - Prepare dataset...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:24.718 | INFO    | Task run 'Prepare Datasets-0' - ✅ Datasets prepared successfully\n",
+       "
\n" + ], + "text/plain": [ + "13:32:24.718 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - ✅ Datasets prepared successfully\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:24.888 | INFO    | Task run 'Prepare Datasets-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:24.888 | \u001b[36mINFO\u001b[0m | Task run 'Prepare Datasets-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:25.057 | INFO    | Action run 'magenta-griffin' - Created task run 'Create Loaders-0' for task 'Create Loaders'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:25.057 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Created task run 'Create Loaders-0' for task 'Create Loaders'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:25.058 | INFO    | Action run 'magenta-griffin' - Executing 'Create Loaders-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:25.058 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Executing 'Create Loaders-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:25.622 | INFO    | Task run 'Create Loaders-0' - Create loaders...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:25.622 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - Create loaders...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:25.625 | INFO    | Task run 'Create Loaders-0' - ✅ Loaders created!\n",
+       "
\n" + ], + "text/plain": [ + "13:32:25.625 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - ✅ Loaders created!\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:25.778 | INFO    | Task run 'Create Loaders-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:25.778 | \u001b[36mINFO\u001b[0m | Task run 'Create Loaders-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:26.039 | INFO    | Action run 'magenta-griffin' - Created task run 'Train model-0' for task 'Train model'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:26.039 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Created task run 'Train model-0' for task 'Train model'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:26.042 | INFO    | Action run 'magenta-griffin' - Executing 'Train model-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:26.042 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Executing 'Train model-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:26.648 | INFO    | Task run 'Train model-0' - Train model...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:26.648 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Train model...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:26.781 | INFO    | Task run 'Train model-0' - Epoch [1/10], Step [100/235], Loss: 1.7287\n",
+       "
\n" + ], + "text/plain": [ + "13:32:26.781 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [1/10], Step [100/235], Loss: 1.7287\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:26.880 | INFO    | Task run 'Train model-0' - Epoch [1/10], Step [200/235], Loss: 1.0847\n",
+       "
\n" + ], + "text/plain": [ + "13:32:26.880 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [1/10], Step [200/235], Loss: 1.0847\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.013 | INFO    | Task run 'Train model-0' - Epoch [2/10], Step [100/235], Loss: 0.6697\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.013 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [2/10], Step [100/235], Loss: 0.6697\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.110 | INFO    | Task run 'Train model-0' - Epoch [2/10], Step [200/235], Loss: 0.5229\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.110 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [2/10], Step [200/235], Loss: 0.5229\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.243 | INFO    | Task run 'Train model-0' - Epoch [3/10], Step [100/235], Loss: 0.4847\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.243 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [3/10], Step [100/235], Loss: 0.4847\n" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { + "text/html": [ + "
13:32:27.340 | INFO    | Task run 'Train model-0' - Epoch [3/10], Step [200/235], Loss: 0.4414\n",
+       "
\n" + ], "text/plain": [ - "[Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `tuple`')),\n", - " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `tuple`')),\n", - " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `NeuralNet`')),\n", - " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `NoneType`'))]" + "13:32:27.340 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [3/10], Step [200/235], Loss: 0.4414\n" ] }, - "execution_count": 42, "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\n", - "@action(name=f'Execution {uuid.uuid4()}', )\n", - "def execution():\n", - " x_train, y_train, x_test, y_test = prepare_datasets()\n", - " train_loader, test_loader = create_data_loaders(\n", - " x_train, y_train, x_test, y_test)\n", - " model = train_model(train_loader)\n", - " test_model(model, test_loader)\n", - "\n", - "\n", - "execution()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When you return to your workspace and refresh it, you will observe your action currently in the execution process.\n", - "\n", - "To view all the actions you have run, navigate to the Action Runs section within your workspace. Each action run represents a single occurrence of executing the action.\n", - "\n", - "![Action runs](./imgs/action_runs.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Furthermore, by clicking on a particular action, you can closely monitor its progress. You'll have the ability to view logs, individual tasks, and associated metadata.\n", - "\n", - "![Action](./imgs/action.png)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploy your action" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Giza Action enables you to deploy workflows, turning them from manual activation into API-managed entities that can be triggered remotely. Once a workflow is deployed, it creates a deployment within your Giza Workspace, which remains active, awaiting action runs associated with that deployment. When a run is detected, it is asynchronously executed in a local subprocess.\n", - "\n", - "All your deployments can be found in the 'Deployments' section of your Workspace.\n", - "\n", - "![Deployment](./imgs/deployments.png)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ + "output_type": "display_data" + }, { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/s3/6c0gmns50x36dt6vvfhv6jhc0000gn/T/ipykernel_16225/3902433836.py:12: RuntimeWarning: coroutine 'Action.serve' was never awaited\n", - " action_deploy.serve(name=\"pytorch-mnist-deployment\")\n", - "RuntimeWarning: Enable tracemalloc to get the object allocation traceback\n" - ] - } - ], - "source": [ - "@action()\n", - "def execution():\n", - " x_train, y_train, x_test, y_test = prepare_datasets()\n", - " train_loader, test_loader = create_data_loaders(\n", - " x_train, y_train, x_test, y_test)\n", - " model = train_model(train_loader)\n", - " test_model(model, test_loader)\n", - "\n", - "# This can only be executed in a Python script, not in a notebook\n", - "if __name__ == '__main__':\n", - " action_deploy = Action(entrypoint=execution, name=\"pytorch-mnist-action\")\n", - " action_deploy.serve(name=\"pytorch-mnist-deployment\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Run and Prove!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Up to this point, we have primarily focused on training and testing our model using PyTorch while monitoring its execution through the Giza platform. However, if you are here, it's likely because you want to harness the capabilities of ZKML (Zero-Knowledge Machine Learning) and have the ability to demonstrate the integrity of your model's inferences.\n", - "\n", - "In this section, we will delve into what it means to prove the integrity of inferences, what setup is required to make this possible, and how to verify the proof." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "ZKML leverages validity proofs like SNARKs and STARKs, which enables the verification of the correctness of computational processes. By deploying such proof systems in machine learning applications, we gain the ability to validate the inference of ML models or to confirm that a specific input produced a certain output with a given model.\n", - "\n", - "To generate ZK proofs for your model inferences, you must first convert your model into ZK circuits. This conversion process involves leveraging programming languages that specialize in building ZK circuits, such as [Cairo-lang](https://www.cairo-lang.org/). Subsequently, using the Giza-CLI, you can transpile your model from ONNX to Cairo. This process will be covered in the upcoming sections.\n", - "\n", - "It's worth mentioning that at present, Orion and Action-SDK exclusively supports Cairo as a ZK backend. However, we are actively working on expanding support for other ZK backends (e.g; EZKL, Noir ...).\n", - "\n", - "![Giza Stack](./imgs/giza_stack.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Convert to ONNX\n", - "\n", - "Before invoking the Giza transpiler to convert your model into Cairo, you must first ensure that your model is converted to ONNX. We will explore this process in the following section.\n", - "\n", - "ONNX, short for Open Neural Network Exchange, is an open format for representing and exchanging machine learning models between different frameworks and libraries. It serves as an intermediary format that allows you to move models seamlessly between various platforms and tools, facilitating interoperability and flexibility in the machine learning ecosystem." - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ + "data": { + "text/html": [ + "
13:32:27.472 | INFO    | Task run 'Train model-0' - Epoch [4/10], Step [100/235], Loss: 0.3871\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.472 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [4/10], Step [100/235], Loss: 0.3871\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.568 | INFO    | Task run 'Train model-0' - Epoch [4/10], Step [200/235], Loss: 0.3003\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.568 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [4/10], Step [200/235], Loss: 0.3003\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.701 | INFO    | Task run 'Train model-0' - Epoch [5/10], Step [100/235], Loss: 0.4412\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.701 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [5/10], Step [100/235], Loss: 0.4412\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.798 | INFO    | Task run 'Train model-0' - Epoch [5/10], Step [200/235], Loss: 0.3453\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.798 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [5/10], Step [200/235], Loss: 0.3453\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:27.930 | INFO    | Task run 'Train model-0' - Epoch [6/10], Step [100/235], Loss: 0.3426\n",
+       "
\n" + ], + "text/plain": [ + "13:32:27.930 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [6/10], Step [100/235], Loss: 0.3426\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.026 | INFO    | Task run 'Train model-0' - Epoch [6/10], Step [200/235], Loss: 0.3413\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.026 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [6/10], Step [200/235], Loss: 0.3413\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.227 | INFO    | Task run 'Train model-0' - Epoch [7/10], Step [100/235], Loss: 0.3012\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.227 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [7/10], Step [100/235], Loss: 0.3012\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.325 | INFO    | Task run 'Train model-0' - Epoch [7/10], Step [200/235], Loss: 0.2877\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.325 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [7/10], Step [200/235], Loss: 0.2877\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.457 | INFO    | Task run 'Train model-0' - Epoch [8/10], Step [100/235], Loss: 0.3666\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.457 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [8/10], Step [100/235], Loss: 0.3666\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.556 | INFO    | Task run 'Train model-0' - Epoch [8/10], Step [200/235], Loss: 0.3500\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.556 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [8/10], Step [200/235], Loss: 0.3500\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.688 | INFO    | Task run 'Train model-0' - Epoch [9/10], Step [100/235], Loss: 0.2855\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.688 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [9/10], Step [100/235], Loss: 0.2855\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.789 | INFO    | Task run 'Train model-0' - Epoch [9/10], Step [200/235], Loss: 0.3008\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.789 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [9/10], Step [200/235], Loss: 0.3008\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:28.963 | INFO    | Task run 'Train model-0' - Epoch [10/10], Step [100/235], Loss: 0.3128\n",
+       "
\n" + ], + "text/plain": [ + "13:32:28.963 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [10/10], Step [100/235], Loss: 0.3128\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:29.078 | INFO    | Task run 'Train model-0' - Epoch [10/10], Step [200/235], Loss: 0.3523\n",
+       "
\n" + ], + "text/plain": [ + "13:32:29.078 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Epoch [10/10], Step [200/235], Loss: 0.3523\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:29.119 | INFO    | Task run 'Train model-0' - ✅ Model trained successfully\n",
+       "
\n" + ], + "text/plain": [ + "13:32:29.119 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - ✅ Model trained successfully\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:29.385 | INFO    | Task run 'Train model-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:29.385 | \u001b[36mINFO\u001b[0m | Task run 'Train model-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:29.614 | INFO    | Action run 'magenta-griffin' - Created task run 'Test model-0' for task 'Test model'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:29.614 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Created task run 'Test model-0' for task 'Test model'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:29.615 | INFO    | Action run 'magenta-griffin' - Executing 'Test model-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:29.615 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Executing 'Test model-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/raphaeldoukhan/Library/Caches/pypoetry/virtualenvs/giza-actions-mYf3m_Lk-py3.11/lib/python3.11/site-packages/prefect/flows.py:338: UserWarning: A flow named 'Action: Convert To ONNX' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/action.py:12' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:\n", - "\n", - " `@flow(name='my_unique_name', ...)`\n", - " warnings.warn(\n" - ] + "data": { + "text/html": [ + "
13:32:31.289 | INFO    | Task run 'Test model-0' - Test model...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:31.289 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Test model...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "Prepare dataset...\n", - "✅ Datasets prepared successfully\n", - "Create loaders...\n", - "✅ Loaders created!\n", - "Train model...\n", - "Epoch [1/10], Step [100/235], Loss: 1.7943\n", - "Epoch [1/10], Step [200/235], Loss: 1.1904\n", - "Epoch [2/10], Step [100/235], Loss: 0.7732\n", - "Epoch [2/10], Step [200/235], Loss: 0.6201\n", - "Epoch [3/10], Step [100/235], Loss: 0.4574\n", - "Epoch [3/10], Step [200/235], Loss: 0.3970\n", - "Epoch [4/10], Step [100/235], Loss: 0.3728\n", - "Epoch [4/10], Step [200/235], Loss: 0.3808\n", - "Epoch [5/10], Step [100/235], Loss: 0.4304\n", - "Epoch [5/10], Step [200/235], Loss: 0.4226\n", - "Epoch [6/10], Step [100/235], Loss: 0.2514\n", - "Epoch [6/10], Step [200/235], Loss: 0.3149\n", - "Epoch [7/10], Step [100/235], Loss: 0.2774\n", - "Epoch [7/10], Step [200/235], Loss: 0.3136\n", - "Epoch [8/10], Step [100/235], Loss: 0.3052\n", - "Epoch [8/10], Step [200/235], Loss: 0.2545\n", - "Epoch [9/10], Step [100/235], Loss: 0.2400\n", - "Epoch [9/10], Step [200/235], Loss: 0.2815\n", - "Epoch [10/10], Step [100/235], Loss: 0.2724\n", - "Epoch [10/10], Step [200/235], Loss: 0.2534\n", - "✅ Model trained successfully\n", - "Test model...\n", - "Accuracy of the network on the 10000 test images: 91.49 %\n", - "Model has been converted to ONNX and saved as mnist_model.onnx\n" - ] + "data": { + "text/html": [ + "
13:32:31.324 | INFO    | Task run 'Test model-0' - Accuracy of the network on the 10000 test images: 91.64 %\n",
+       "
\n" + ], + "text/plain": [ + "13:32:31.324 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Accuracy of the network on the 10000 test images: 91.64 %\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:31.524 | INFO    | Task run 'Test model-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:31.524 | \u001b[36mINFO\u001b[0m | Task run 'Test model-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:31.707 | INFO    | Action run 'magenta-griffin' - Created task run 'Convert To ONNX-0' for task 'Convert To ONNX'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:31.707 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Created task run 'Convert To ONNX-0' for task 'Convert To ONNX'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:31.708 | INFO    | Action run 'magenta-griffin' - Executing 'Convert To ONNX-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:31.708 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Executing 'Convert To ONNX-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:32.093 | INFO    | Task run 'Convert To ONNX-0' - Model has been converted to ONNX and saved as mnist_model.onnx\n",
+       "
\n" + ], + "text/plain": [ + "13:32:32.093 | \u001b[36mINFO\u001b[0m | Task run 'Convert To ONNX-0' - Model has been converted to ONNX and saved as mnist_model.onnx\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:32.360 | INFO    | Task run 'Convert To ONNX-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:32.360 | \u001b[36mINFO\u001b[0m | Task run 'Convert To ONNX-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:32.606 | INFO    | Action run 'magenta-griffin' - Finished in state Completed('All states completed.')\n",
+       "
\n" + ], + "text/plain": [ + "13:32:32.606 | \u001b[36mINFO\u001b[0m | Action run 'magenta-griffin' - Finished in state \u001b[32mCompleted\u001b[0m('All states completed.')\n" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -570,7 +1665,7 @@ " Completed(message=None, type=COMPLETED, result=UnpersistedResult(type='unpersisted', artifact_type='result', artifact_description='Unpersisted result of type `NoneType`'))]" ] }, - "execution_count": 43, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -578,7 +1673,7 @@ "source": [ "import torch.onnx\n", "\n", - "@task(name=f'Convert To ONNX {uuid.uuid4()}')\n", + "@task(name=f'Convert To ONNX')\n", "def convert_to_onnx(model, onnx_file_path):\n", " dummy_input = torch.randn(1, input_size).to(device)\n", " torch.onnx.export(model, dummy_input, onnx_file_path,\n", @@ -587,7 +1682,7 @@ " print(f\"Model has been converted to ONNX and saved as {onnx_file_path}\")\n", "\n", "\n", - "@action(name=\"Action: Convert To ONNX\", )\n", + "@action(name=\"Action: Convert To ONNX\", log_prints=True)\n", "def execution():\n", " x_train, y_train, x_test, y_test = prepare_datasets()\n", " train_loader, test_loader = create_data_loaders(\n", @@ -680,17 +1775,138 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 11, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[ 8.584354 -13.583519 -2.6759582 1.494859 -19.907509 5.371609\n", - " -9.260434 -4.6332397 -3.057909 -8.678334 ]]\n", - "Predicted Digit: 0\n" - ] + "data": { + "text/html": [ + "
13:32:33.803 | INFO    | Created flow run 'analytic-pig' for flow 'Execution: Prediction with ONNX'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:33.803 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'analytic-pig'\u001b[0m for flow\u001b[1;35m 'Execution: Prediction with ONNX'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:33.804 | INFO    | Action run 'analytic-pig' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/df705e47-dae2-415e-8786-ac08120d3b39\n",
+       "
\n" + ], + "text/plain": [ + "13:32:33.804 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/df705e47-dae2-415e-8786-ac08120d3b39\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:34.442 | INFO    | Action run 'analytic-pig' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:34.442 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:34.446 | INFO    | Action run 'analytic-pig' - Executing 'Preprocess Image-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:34.446 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Executing 'Preprocess Image-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:35.200 | INFO    | Task run 'Preprocess Image-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:35.200 | \u001b[36mINFO\u001b[0m | Task run 'Preprocess Image-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:35.435 | INFO    | Action run 'analytic-pig' - Created task run 'Prediction with ONNX-0' for task 'Prediction with ONNX'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:35.435 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Created task run 'Prediction with ONNX-0' for task 'Prediction with ONNX'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:35.437 | INFO    | Action run 'analytic-pig' - Executing 'Prediction with ONNX-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:35.437 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Executing 'Prediction with ONNX-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:36.163 | INFO    | Task run 'Prediction with ONNX-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:36.163 | \u001b[36mINFO\u001b[0m | Task run 'Prediction with ONNX-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:36.165 | INFO    | Action run 'analytic-pig' - Predicted Digit: 0\n",
+       "
\n" + ], + "text/plain": [ + "13:32:36.165 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Predicted Digit: 0\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:36.478 | INFO    | Action run 'analytic-pig' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:36.478 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -698,7 +1914,7 @@ "0" ] }, - "execution_count": 46, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -708,7 +1924,7 @@ "import torch.nn.functional as F\n", "\n", "\n", - "@task(name=f'Preprocess Image {uuid.uuid4()}')\n", + "@task(name=f'Preprocess Image')\n", "def preprocess_image(image_path):\n", " from PIL import Image\n", " import numpy as np\n", @@ -722,7 +1938,7 @@ " return image\n", "\n", "\n", - "@task(name=f'Prediction with ONNX {uuid.uuid4()}')\n", + "@task(name=f'Prediction with ONNX')\n", "def prediction(image):\n", " model = GizaModel(model_path=\"./mnist_model.onnx\")\n", "\n", @@ -740,7 +1956,7 @@ " return predicted_class.item()\n", "\n", "\n", - "@action(name=f'Execution: Prediction with ONNX {uuid.uuid4()}', )\n", + "@action(name=f'Execution: Prediction with ONNX', log_prints=True )\n", "def execution():\n", " image = preprocess_image(\"./zero.jpg\")\n", " predicted_digit = prediction(image)\n", @@ -756,36 +1972,179 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now, let's make a prediction with the Cairo model (`veriable=True`).\n", - "\n", - "DISCLAIMER: This section is still a work in progress and may not function correctly with certain Cairo programs. We are diligently working to resolve any issues and ensure it operates smoothly as soon as possible." + "Now, let's make a prediction with the Cairo model (`veriable=True`)." ] }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 12, "metadata": {}, "outputs": [ + { + "data": { + "text/html": [ + "
13:32:39.123 | INFO    | Created flow run 'hilarious-fox' for flow 'Execution: Prediction with Cairo'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:39.123 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'hilarious-fox'\u001b[0m for flow\u001b[1;35m 'Execution: Prediction with Cairo'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:39.125 | INFO    | Action run 'hilarious-fox' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/8df8bcf5-8904-4385-bb56-89980c22962d\n",
+       "
\n" + ], + "text/plain": [ + "13:32:39.125 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/8df8bcf5-8904-4385-bb56-89980c22962d\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:39.945 | INFO    | Action run 'hilarious-fox' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:39.945 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:39.946 | INFO    | Action run 'hilarious-fox' - Executing 'Preprocess Image-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:39.946 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Executing 'Preprocess Image-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:40.556 | INFO    | Task run 'Preprocess Image-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:40.556 | \u001b[36mINFO\u001b[0m | Task run 'Preprocess Image-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:40.681 | INFO    | Action run 'hilarious-fox' - Created task run 'Prediction with Cairo-0' for task 'Prediction with Cairo'\n",
+       "
\n" + ], + "text/plain": [ + "13:32:40.681 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Created task run 'Prediction with Cairo-0' for task 'Prediction with Cairo'\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:40.682 | INFO    | Action run 'hilarious-fox' - Executing 'Prediction with Cairo-0' immediately...\n",
+       "
\n" + ], + "text/plain": [ + "13:32:40.682 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Executing 'Prediction with Cairo-0' immediately...\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdout", "output_type": "stream", "text": [ "🚀 Starting deserialization process...\n", - "✅ Deserialization completed! 🎉\n", - "Result: [ 1.02122345e+01 -1.45135193e+01 -1.16250610e+00 1.70765686e+00\n", - " -1.23049927e+01 5.87187195e+00 -9.11688232e+00 -3.19342041e+00\n", - " -1.10015869e-02 -7.16711426e+00]\n" + "✅ Deserialization completed! 🎉\n" ] }, + { + "data": { + "text/html": [ + "
13:32:47.291 | INFO    | Task run 'Prediction with Cairo-0' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:47.291 | \u001b[36mINFO\u001b[0m | Task run 'Prediction with Cairo-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:47.293 | INFO    | Action run 'hilarious-fox' - Result:  [ 1.02122345e+01 -1.45135193e+01 -1.16250610e+00  1.70765686e+00\n",
+       " -1.23049927e+01  5.87187195e+00 -9.11688232e+00 -3.19342041e+00\n",
+       " -1.10015869e-02 -7.16711426e+00]\n",
+       "
\n" + ], + "text/plain": [ + "13:32:47.293 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Result: [ 1.02122345e+01 -1.45135193e+01 -1.16250610e+00 1.70765686e+00\n", + " -1.23049927e+01 5.87187195e+00 -9.11688232e+00 -3.19342041e+00\n", + " -1.10015869e-02 -7.16711426e+00]\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:47.294 | INFO    | Action run 'hilarious-fox' - Request id:  \"aec2192b8b2d4381889270707b9b9ff2\"\n",
+       "
\n" + ], + "text/plain": [ + "13:32:47.294 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Request id: \"aec2192b8b2d4381889270707b9b9ff2\"\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
13:32:47.431 | INFO    | Action run 'hilarious-fox' - Finished in state Completed()\n",
+       "
\n" + ], + "text/plain": [ + "13:32:47.431 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Finished in state \u001b[32mCompleted\u001b[0m()\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "data": { "text/plain": [ - "array([ 1.02122345e+01, -1.45135193e+01, -1.16250610e+00, 1.70765686e+00,\n", - " -1.23049927e+01, 5.87187195e+00, -9.11688232e+00, -3.19342041e+00,\n", - " -1.10015869e-02, -7.16711426e+00])" + "(array([ 1.02122345e+01, -1.45135193e+01, -1.16250610e+00, 1.70765686e+00,\n", + " -1.23049927e+01, 5.87187195e+00, -9.11688232e+00, -3.19342041e+00,\n", + " -1.10015869e-02, -7.16711426e+00]),\n", + " '\"aec2192b8b2d4381889270707b9b9ff2\"')" ] }, - "execution_count": 48, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -793,27 +2152,29 @@ "source": [ "\n", "\n", - "model_id = 49 # Update with your model ID\n", - "version_id = 3 # Update with your version ID\n", + "MODEL_ID = 49 # Update with your model ID\n", + "VERSION_ID = 3 # Update with your version ID\n", "\n", - "@task(name=f'Prediction with Cairo {uuid.uuid4()}')\n", + "\n", + "@task(name=f'Prediction with Cairo')\n", "def prediction(image, model_id, version_id):\n", - " model = GizaModel(id=49, version=3)\n", + " model = GizaModel(id=model_id, version=version_id)\n", "\n", - " result = model.predict(\n", + " (result, request_id) = model.predict(\n", " input_feed={\"image\": image}, verifiable=True, output_dtype=\"arr_fixed_point\"\n", " )\n", "\n", - " return result\n", + " return result, request_id\n", "\n", "\n", - "@action(name=f'Execution: Prediction with Cairo {uuid.uuid4()}')\n", + "@action(name=f'Execution: Prediction with Cairo', log_prints=True)\n", "def execution():\n", " image = preprocess_image(\"./zero.jpg\")\n", - " result = prediction(image, model_id, 1)\n", + " (result, request_id) = prediction(image, MODEL_ID, VERSION_ID)\n", " print(\"Result: \", result)\n", + " print(\"Request id: \", request_id)\n", "\n", - " return result\n", + " return result, request_id\n", "\n", "\n", "execution()" @@ -823,7 +2184,67 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**TODO: prover and verifier section (coming soon)**" + "## Download and Verify the proof" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When you ran your model, CairoVM generated trace and memory files under the hood to prove your program. We have initiated a proof job on your behalf and completed the proof." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the code below, we will download the ZK proof generated in the proof-job." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "from giza import API_HOST\n", + "\n", + "MODEL_ID = 49 # Update with your model ID\n", + "VERSION_ID = 3 # Update with your version ID\n", + "DEPLOYMENT_ID = 10 # Update with your deployment id\n", + "REQUEST_ID = \"YOUR_REQUEST_ID\" # Update with your request id\n", + "API_KEY = 'YOUR_API_KEY' # Update with your API key\n", + "\n", + "url = f'{API_HOST}/api/v1/models/{MODEL_ID}/versions/{VERSION_ID}/deployments/{DEPLOYMENT_ID}/proofs/{REQUEST_ID}:download'\n", + "\n", + "headers = {\"X-API-KEY\": API_KEY}\n", + "\n", + "d_url = requests.get(url, headers=headers).json()[\"download_url\"]\n", + "\n", + "proof = requests.get(d_url)\n", + "\n", + "\n", + "with open(\"zk.proof\", \"wb\") as f:\n", + " f.write(proof.content)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, let's verify the proof!\n", + "All you need to do is simply running: \n", + "```bash\n", + "giza verify --proof PATH_TO_PROOF\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Voilà 🎉! You've learned how to use the entire Giza stack, from training your model to transpiling it to Cairo for verifiable execution. You've also learned how to verify the proof. We hope you've enjoyed this journey! If you have any questions, please feel free to join us in our [Discord](https://discord.gg/zF2dxSYk6Z), or [open an issue](https://github.com/gizatechxyz/actions-sdk/issues). " ] } ], diff --git a/giza_actions/model.py b/giza_actions/model.py index 002b820..f47dc7c 100644 --- a/giza_actions/model.py +++ b/giza_actions/model.py @@ -1,4 +1,5 @@ import json +import logging from pathlib import Path from typing import Dict, Optional @@ -77,35 +78,42 @@ def predict( fp_impl="FP16x16", output_dtype: str = "tensor_fixed_point", ): - - if verifiable: - if not self.uri: - raise ValueError("Model has not been deployed") + try: + if verifiable: + if not self.uri: + raise ValueError("Model has not been deployed") - endpoint = f"{self.uri}/cairo_run" + endpoint = f"{self.uri}/cairo_run" - cairo_payload = self._format_inputs_for_cairo( - input_file, input_feed, fp_impl - ) + cairo_payload = self._format_inputs_for_cairo( + input_file, input_feed, fp_impl + ) - response = requests.post(endpoint, json=cairo_payload) + response = requests.post(endpoint, json=cairo_payload) - if response.status_code == 200: - serialized_output = json.dumps(response.json()["result"]) + if response.status_code == 200: + serialized_output = json.dumps(response.json()["result"]) + request_id = json.dumps(response.json()["request_id"]) - preds = self._parse_cairo_response( - serialized_output, output_dtype, fp_impl - ) - else: - raise Exception(f"OrionRunner service error: {response.text}") + preds = self._parse_cairo_response( + serialized_output, output_dtype, fp_impl + ) + return (preds, request_id) + else: + error_message = f"OrionRunner service error: {response.text}" + logging.error(error_message) + raise Exception(error_message) - else: - if self.session is None: - raise ValueError("Session is not initialized.") - if input_feed is None: - raise ValueError("Input feed is none") - preds = self.session.run(None, input_feed)[0] - return preds + else: + if self.session is None: + raise ValueError("Session is not initialized.") + if input_feed is None: + raise ValueError("Input feed is none") + preds = self.session.run(None, input_feed)[0] + return preds + except Exception as e: + logging.error(f"An error occurred in predict: {e}") + return (None, None) def _format_inputs_for_cairo( self, input_file: Optional[str], input_feed: Optional[Dict], fp_impl @@ -124,7 +132,7 @@ def _format_inputs_for_cairo( else: serialized = serializer(value) - return {"job_size": "L", "args": serialized} + return {"job_size": "M", "args": serialized} def _parse_cairo_response(self, response, data_type: str, fp_impl): return deserialize(response, data_type, fp_impl) diff --git a/poetry.lock b/poetry.lock index 5fd8ecb..e188a24 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1005,13 +1005,13 @@ tqdm = ["tqdm"] [[package]] name = "giza-cli" -version = "0.7.0" +version = "0.8.1" description = "CLI for interacting with Giza" optional = false python-versions = ">=3.11,<4.0" files = [ - {file = "giza_cli-0.7.0-py3-none-any.whl", hash = "sha256:3fe3ad1d30c169cca520e5948ea49b66fd08d073a26a759c2aa7a4dc85126b00"}, - {file = "giza_cli-0.7.0.tar.gz", hash = "sha256:ab33d7ba8040755278a3030a2ae15192b49eceb748012cee139cdbb0bb75a87b"}, + {file = "giza_cli-0.8.1-py3-none-any.whl", hash = "sha256:cc35d66ad2cafc306514b79906ef87fd974e99bc06eabb2b73d1478d65517331"}, + {file = "giza_cli-0.8.1.tar.gz", hash = "sha256:c525c8419b5a88079c71a70d9e498eed93c1d31d36d2947e38ea831b94b1c527"}, ] [package.dependencies] @@ -1048,13 +1048,13 @@ typer = {version = "0.7.0", extras = ["all"]} [[package]] name = "google-api-core" -version = "2.15.0" +version = "2.16.0" description = "Google API client core library" optional = false python-versions = ">=3.7" files = [ - {file = "google-api-core-2.15.0.tar.gz", hash = "sha256:abc978a72658f14a2df1e5e12532effe40f94f868f6e23d95133bd6abcca35ca"}, - {file = "google_api_core-2.15.0-py3-none-any.whl", hash = "sha256:2aa56d2be495551e66bbff7f729b790546f87d5c90e74781aa77233bcb395a8a"}, + {file = "google-api-core-2.16.0.tar.gz", hash = "sha256:d1fc42e52aa4042ad812827b7aad858394e2bf73da8329af95ad8efa30bc886b"}, + {file = "google_api_core-2.16.0-py3-none-any.whl", hash = "sha256:c424f9f271c7f55366254708e0d0383963a72376286018af0a04f322be843400"}, ] [package.dependencies] @@ -3217,13 +3217,13 @@ unidecode = ["Unidecode (>=1.1.1)"] [[package]] name = "pytz" -version = "2023.3.post1" +version = "2023.4" description = "World timezone definitions, modern and historical" optional = false python-versions = "*" files = [ - {file = "pytz-2023.3.post1-py2.py3-none-any.whl", hash = "sha256:ce42d816b81b68506614c11e8937d3aa9e41007ceb50bfdcb0749b921bf646c7"}, - {file = "pytz-2023.3.post1.tar.gz", hash = "sha256:7b4fddbeb94a1eba4b557da24f19fdf9db575192544270a9101d8509f9f43d7b"}, + {file = "pytz-2023.4-py2.py3-none-any.whl", hash = "sha256:f90ef520d95e7c46951105338d918664ebfd6f1d995bd7d153127ce90efafa6a"}, + {file = "pytz-2023.4.tar.gz", hash = "sha256:31d4583c4ed539cd037956140d695e42c033a19e984bfce9964a3f7d59bc2b40"}, ] [[package]] @@ -3708,28 +3708,28 @@ files = [ [[package]] name = "ruff" -version = "0.1.14" +version = "0.1.15" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.1.14-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:96f76536df9b26622755c12ed8680f159817be2f725c17ed9305b472a757cdbb"}, - {file = "ruff-0.1.14-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ab3f71f64498c7241123bb5a768544cf42821d2a537f894b22457a543d3ca7a9"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7060156ecc572b8f984fd20fd8b0fcb692dd5d837b7606e968334ab7ff0090ab"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a53d8e35313d7b67eb3db15a66c08434809107659226a90dcd7acb2afa55faea"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bea9be712b8f5b4ebed40e1949379cfb2a7d907f42921cf9ab3aae07e6fba9eb"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:2270504d629a0b064247983cbc495bed277f372fb9eaba41e5cf51f7ba705a6a"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:80258bb3b8909b1700610dfabef7876423eed1bc930fe177c71c414921898efa"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:653230dd00aaf449eb5ff25d10a6e03bc3006813e2cb99799e568f55482e5cae"}, - {file = "ruff-0.1.14-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:87b3acc6c4e6928459ba9eb7459dd4f0c4bf266a053c863d72a44c33246bfdbf"}, - {file = "ruff-0.1.14-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:6b3dadc9522d0eccc060699a9816e8127b27addbb4697fc0c08611e4e6aeb8b5"}, - {file = "ruff-0.1.14-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:1c8eca1a47b4150dc0fbec7fe68fc91c695aed798532a18dbb1424e61e9b721f"}, - {file = "ruff-0.1.14-py3-none-musllinux_1_2_i686.whl", hash = "sha256:62ce2ae46303ee896fc6811f63d6dabf8d9c389da0f3e3f2bce8bc7f15ef5488"}, - {file = "ruff-0.1.14-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b2027dde79d217b211d725fc833e8965dc90a16d0d3213f1298f97465956661b"}, - {file = "ruff-0.1.14-py3-none-win32.whl", hash = "sha256:722bafc299145575a63bbd6b5069cb643eaa62546a5b6398f82b3e4403329cab"}, - {file = "ruff-0.1.14-py3-none-win_amd64.whl", hash = "sha256:e3d241aa61f92b0805a7082bd89a9990826448e4d0398f0e2bc8f05c75c63d99"}, - {file = "ruff-0.1.14-py3-none-win_arm64.whl", hash = "sha256:269302b31ade4cde6cf6f9dd58ea593773a37ed3f7b97e793c8594b262466b67"}, - {file = "ruff-0.1.14.tar.gz", hash = "sha256:ad3f8088b2dfd884820289a06ab718cde7d38b94972212cc4ba90d5fbc9955f3"}, + {file = "ruff-0.1.15-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:5fe8d54df166ecc24106db7dd6a68d44852d14eb0729ea4672bb4d96c320b7df"}, + {file = "ruff-0.1.15-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:6f0bfbb53c4b4de117ac4d6ddfd33aa5fc31beeaa21d23c45c6dd249faf9126f"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e0d432aec35bfc0d800d4f70eba26e23a352386be3a6cf157083d18f6f5881c8"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9405fa9ac0e97f35aaddf185a1be194a589424b8713e3b97b762336ec79ff807"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c66ec24fe36841636e814b8f90f572a8c0cb0e54d8b5c2d0e300d28a0d7bffec"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:6f8ad828f01e8dd32cc58bc28375150171d198491fc901f6f98d2a39ba8e3ff5"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:86811954eec63e9ea162af0ffa9f8d09088bab51b7438e8b6488b9401863c25e"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fd4025ac5e87d9b80e1f300207eb2fd099ff8200fa2320d7dc066a3f4622dc6b"}, + {file = "ruff-0.1.15-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b17b93c02cdb6aeb696effecea1095ac93f3884a49a554a9afa76bb125c114c1"}, + {file = "ruff-0.1.15-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:ddb87643be40f034e97e97f5bc2ef7ce39de20e34608f3f829db727a93fb82c5"}, + {file = "ruff-0.1.15-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:abf4822129ed3a5ce54383d5f0e964e7fef74a41e48eb1dfad404151efc130a2"}, + {file = "ruff-0.1.15-py3-none-musllinux_1_2_i686.whl", hash = "sha256:6c629cf64bacfd136c07c78ac10a54578ec9d1bd2a9d395efbee0935868bf852"}, + {file = "ruff-0.1.15-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:1bab866aafb53da39c2cadfb8e1c4550ac5340bb40300083eb8967ba25481447"}, + {file = "ruff-0.1.15-py3-none-win32.whl", hash = "sha256:2417e1cb6e2068389b07e6fa74c306b2810fe3ee3476d5b8a96616633f40d14f"}, + {file = "ruff-0.1.15-py3-none-win_amd64.whl", hash = "sha256:3837ac73d869efc4182d9036b1405ef4c73d9b1f88da2413875e34e0d6919587"}, + {file = "ruff-0.1.15-py3-none-win_arm64.whl", hash = "sha256:9a933dfb1c14ec7a33cceb1e49ec4a16b51ce3c20fd42663198746efc0427360"}, + {file = "ruff-0.1.15.tar.gz", hash = "sha256:f6dfa8c1b21c913c326919056c390966648b680966febcb796cc9d1aaab8564e"}, ] [[package]] @@ -4277,13 +4277,13 @@ zstd = ["zstandard (>=0.18.0)"] [[package]] name = "uvicorn" -version = "0.27.0" +version = "0.27.0.post1" description = "The lightning-fast ASGI server." optional = false python-versions = ">=3.8" files = [ - {file = "uvicorn-0.27.0-py3-none-any.whl", hash = "sha256:890b00f6c537d58695d3bb1f28e23db9d9e7a17cbcc76d7457c499935f933e24"}, - {file = "uvicorn-0.27.0.tar.gz", hash = "sha256:c855578045d45625fd027367f7653d249f7c49f9361ba15cf9624186b26b8eb6"}, + {file = "uvicorn-0.27.0.post1-py3-none-any.whl", hash = "sha256:4b85ba02b8a20429b9b205d015cbeb788a12da527f731811b643fd739ef90d5f"}, + {file = "uvicorn-0.27.0.post1.tar.gz", hash = "sha256:54898fcd80c13ff1cd28bf77b04ec9dbd8ff60c5259b499b4b12bb0917f22907"}, ] [package.dependencies] @@ -4413,4 +4413,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = ">=3.11,<4.0" -content-hash = "c3b3c0aef3bc74856cc0f6cac57e5aba16e90ad4a0a12cbc5179b6065b69830c" +content-hash = "4e1932262b12efd4c6cd325858a369a933c34319c5cee3ac993181beb69ad9ea" diff --git a/pyproject.toml b/pyproject.toml index 159dc28..d277ff4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ prefect-gcp = "^0.5.4" pyyaml = "^6.0.1" prefect-docker = "^0.4.1" distlib = "^0.3.8" -giza-cli = "^0.7.0" +giza-cli = "^0.8.1" giza-osiris = "^0.2.1" [tool.poetry.dev-dependencies]