From 3e84bb5648df39fd6d57f7f9e36b3e232d8d0a65 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 30 Jan 2024 14:31:23 +0200 Subject: [PATCH 1/3] update Model docstrings --- giza_actions/model.py | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/giza_actions/model.py b/giza_actions/model.py index f47dc7c..c948622 100644 --- a/giza_actions/model.py +++ b/giza_actions/model.py @@ -15,6 +15,27 @@ class GizaModel: + """ + A class to manage the lifecycle and predictions of models using both local ONNX runtime sessions and + remote deployments via the Giza SDK. + + Attributes: + session (ort.InferenceSession | None): An ONNX runtime inference session for local model predictions. + model_client (ModelsClient): Client to interact with the models endpoint of the Giza API. + version_client (VersionsClient): Client to interact with the versions endpoint of the Giza API. + api_client (ApiClient): General client for interacting with the Giza API. + uri (str): The URI for making prediction requests to a deployed model. + + Args: + model_path (Optional[str]): The file path to a local ONNX model. Defaults to None. + id (Optional[int]): The unique identifier of the model in the Giza platform. Defaults to None. + version (Optional[int]): The version number of the model in the Giza platform. Defaults to None. + output_path (Optional[str]): The file path where the downloaded model should be saved. Defaults to None. + + Raises: + ValueError: If the necessary combination of parameters is not provided. + """ + def __init__( self, model_path: Optional[str] = None, @@ -46,6 +67,17 @@ def __init__( self._download_model(id, version, output_path) def _download_model(self, model_id: int, version_id: int, output_path: str): + """ + Downloads the model specified by model_id and version_id to the given output_path. + + Args: + model_id (int): The unique identifier of the model. + version_id (int): The version number of the model. + output_path (str): The file path where the downloaded model should be saved. + + Raises: + ValueError: If the model version status is not completed. + """ version = self.version_client.get(model_id, version_id) if version.status != VersionStatus.COMPLETED: @@ -67,6 +99,9 @@ def _download_model(self, model_id: int, version_id: int, output_path: str): print("Model ready for inference with ONNX Runtime! ✅") def _get_credentials(self): + """ + Retrieves and sets the necessary credentials for API access. + """ self.api_client.retrieve_token() self.api_client.retrieve_api_key() @@ -78,6 +113,24 @@ def predict( fp_impl="FP16x16", output_dtype: str = "tensor_fixed_point", ): + """ + Makes a prediction using either a local ONNX session or a remote deployed model, depending on the + instance configuration. + + Args: + input_file (Optional[str]): The path to the input file for prediction. Defaults to None. + input_feed (Optional[Dict]): A dictionary containing the input data for prediction. Defaults to None. + verifiable (bool): A flag indicating whether to use the verifiable computation endpoint. Defaults to False. + fp_impl (str): The fixed point implementation to use, when computed in verifiable mode. Defaults to "FP16x16". + output_dtype (str): The data type of the result when computed in verifiable mode. Defaults to "tensor_fixed_point". + + Returns: + A tuple (predictions, request_id) where predictions is the result of the prediction and request_id + is the identifier of the prediction request if verifiable computation is used, otherwise None. + + Raises: + ValueError: If required parameters are not provided or the session is not initialized. + """ try: if verifiable: if not self.uri: @@ -118,6 +171,17 @@ def predict( def _format_inputs_for_cairo( self, input_file: Optional[str], input_feed: Optional[Dict], fp_impl ): + """ + Formats the inputs for a prediction request for OrionRunner. + + Args: + input_file (Optional[str]): The path to the input file for prediction. Defaults to None. + input_feed (Optional[Dict]): A dictionary containing the input data for prediction. Defaults to None. + fp_impl (str): The fixed point implementation to use. + + Returns: + dict: A dictionary representing the formatted inputs for the Cairo prediction request. + """ serialized = None if input_file is not None: @@ -135,4 +199,15 @@ def _format_inputs_for_cairo( return {"job_size": "M", "args": serialized} def _parse_cairo_response(self, response, data_type: str, fp_impl): + """ + Parses the response from a OrionRunner prediction request. + + Args: + response (str): The serialized response from the Cairo prediction request. + data_type (str): The data type to which the response should be deserialized. + fp_impl (str): The fixed point implementation used. + + Returns: + The deserialized prediction result. + """ return deserialize(response, data_type, fp_impl) From 759b5a2e47c23612d972588c15e85d0dfadfb72c Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 30 Jan 2024 19:26:01 +0200 Subject: [PATCH 2/3] add zero.png --- examples/verifiable_mnist/imgs/zero.png | Bin 0 -> 592 bytes .../verifiable_mnist/verifiable_mnist.ipynb | 159 ++++++++++-------- giza_actions/model.py | 2 + 3 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 examples/verifiable_mnist/imgs/zero.png diff --git a/examples/verifiable_mnist/imgs/zero.png b/examples/verifiable_mnist/imgs/zero.png new file mode 100644 index 0000000000000000000000000000000000000000..9fcfdc1d53ebe252e7d8be7515c382627dcb0ffb GIT binary patch literal 592 zcmV-W0gv=4-_35A08bV92_7dE+-%&EF&BoC^soAFflYVG#@89JvcHvE;BST|G)qX2ml-a z9036l0RO}Q9{>OW1pxs80RaI300000000010s{mE1_uZU3Jd?l0JRVR0s#X90t5pE z1q1{D00Dgg0s{a95d{(Xb($mz{*4NnC+Tr5k8Q-G={7L6)%1n-kr*A1 zZgG>?WY))tel2QaUAA8c%Gy4WrYVNX2*4`qg1g;LRFVnm4m$PbwZ0g5lf?S=v97+U zf2iK+O{UyE?&jQzc6_+c3f*u9JNC_Z^?DD&y>~{iyw$W%5YHqUUbSoXc_vocBVm%P zPf^s5PI=?mU*kPcXH3Zvg~%|qg^6L??2{s*7Iz6-o- e$?sov{-CGtFG9J;IRFeV1D@pP$Ec!;EC1QoZ}d$7 literal 0 HcmV?d00001 diff --git a/examples/verifiable_mnist/verifiable_mnist.ipynb b/examples/verifiable_mnist/verifiable_mnist.ipynb index ff30348..862888a 100644 --- a/examples/verifiable_mnist/verifiable_mnist.ipynb +++ b/examples/verifiable_mnist/verifiable_mnist.ipynb @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -1775,17 +1775,35 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 4, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/raphaeldoukhan/Library/Caches/pypoetry/virtualenvs/giza-actions-mYf3m_Lk-py3.11/lib/python3.11/site-packages/prefect/tasks.py:337: UserWarning: A task named 'Preprocess Image' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/task.py:5' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:\n", + "\n", + " `@task(name='my_unique_name', ...)`\n", + " warnings.warn(\n", + "/Users/raphaeldoukhan/Library/Caches/pypoetry/virtualenvs/giza-actions-mYf3m_Lk-py3.11/lib/python3.11/site-packages/prefect/tasks.py:337: UserWarning: A task named 'Prediction with ONNX' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/task.py:19' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:\n", + "\n", + " `@task(name='my_unique_name', ...)`\n", + " warnings.warn(\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: Prediction with ONNX' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/action.py:37' 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:33.803 | INFO    | Created flow run 'analytic-pig' for flow 'Execution: Prediction with ONNX'\n",
+       "
18:27:34.088 | INFO    | Created flow run 'sturdy-tuatara' 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" + "18:27:34.088 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'sturdy-tuatara'\u001b[0m for flow\u001b[1;35m 'Execution: Prediction with ONNX'\u001b[0m\n" ] }, "metadata": {}, @@ -1794,11 +1812,11 @@ { "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",
+       "
18:27:34.089 | INFO    | Action run 'sturdy-tuatara' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/7a459701-cad9-4ba8-bc87-99d9487de28c\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" + "18:27:34.089 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/7a459701-cad9-4ba8-bc87-99d9487de28c\u001b[0m\n" ] }, "metadata": {}, @@ -1807,11 +1825,11 @@ { "data": { "text/html": [ - "
13:32:34.442 | INFO    | Action run 'analytic-pig' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n",
+       "
18:27:34.418 | INFO    | Action run 'sturdy-tuatara' - 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" + "18:27:34.418 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n" ] }, "metadata": {}, @@ -1820,11 +1838,11 @@ { "data": { "text/html": [ - "
13:32:34.446 | INFO    | Action run 'analytic-pig' - Executing 'Preprocess Image-0' immediately...\n",
+       "
18:27:34.421 | INFO    | Action run 'sturdy-tuatara' - 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" + "18:27:34.421 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Executing 'Preprocess Image-0' immediately...\n" ] }, "metadata": {}, @@ -1833,11 +1851,11 @@ { "data": { "text/html": [ - "
13:32:35.200 | INFO    | Task run 'Preprocess Image-0' - Finished in state Completed()\n",
+       "
18:27:34.797 | 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" + "18:27:34.797 | \u001b[36mINFO\u001b[0m | Task run 'Preprocess Image-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -1846,11 +1864,11 @@ { "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",
+       "
18:27:34.917 | INFO    | Action run 'sturdy-tuatara' - 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" + "18:27:34.917 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Created task run 'Prediction with ONNX-0' for task 'Prediction with ONNX'\n" ] }, "metadata": {}, @@ -1859,11 +1877,11 @@ { "data": { "text/html": [ - "
13:32:35.437 | INFO    | Action run 'analytic-pig' - Executing 'Prediction with ONNX-0' immediately...\n",
+       "
18:27:34.920 | INFO    | Action run 'sturdy-tuatara' - 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" + "18:27:34.920 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Executing 'Prediction with ONNX-0' immediately...\n" ] }, "metadata": {}, @@ -1872,11 +1890,11 @@ { "data": { "text/html": [ - "
13:32:36.163 | INFO    | Task run 'Prediction with ONNX-0' - Finished in state Completed()\n",
+       "
18:27:35.293 | 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" + "18:27:35.293 | \u001b[36mINFO\u001b[0m | Task run 'Prediction with ONNX-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -1885,11 +1903,11 @@ { "data": { "text/html": [ - "
13:32:36.165 | INFO    | Action run 'analytic-pig' - Predicted Digit: 0\n",
+       "
18:27:35.296 | INFO    | Action run 'sturdy-tuatara' - Predicted Digit: 0\n",
        "
\n" ], "text/plain": [ - "13:32:36.165 | \u001b[36mINFO\u001b[0m | Action run 'analytic-pig' - Predicted Digit: 0\n" + "18:27:35.296 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Predicted Digit: 0\n" ] }, "metadata": {}, @@ -1898,11 +1916,11 @@ { "data": { "text/html": [ - "
13:32:36.478 | INFO    | Action run 'analytic-pig' - Finished in state Completed()\n",
+       "
18:27:35.423 | INFO    | Action run 'sturdy-tuatara' - 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" + "18:27:35.423 | \u001b[36mINFO\u001b[0m | Action run 'sturdy-tuatara' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -1914,7 +1932,7 @@ "0" ] }, - "execution_count": 11, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -1958,7 +1976,7 @@ "\n", "@action(name=f'Execution: Prediction with ONNX', log_prints=True )\n", "def execution():\n", - " image = preprocess_image(\"./zero.jpg\")\n", + " image = preprocess_image(\"./imgs/zero.png\")\n", " predicted_digit = prediction(image)\n", " print(f\"Predicted Digit: {predicted_digit}\")\n", "\n", @@ -1977,17 +1995,31 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 5, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/raphaeldoukhan/Library/Caches/pypoetry/virtualenvs/giza-actions-mYf3m_Lk-py3.11/lib/python3.11/site-packages/prefect/tasks.py:337: UserWarning: A task named 'Prediction with Cairo' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/task.py:5' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:\n", + "\n", + " `@task(name='my_unique_name', ...)`\n", + " warnings.warn(\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: Prediction with Cairo' and defined at '/Users/raphaeldoukhan/Desktop/Orion-Giza/Tools/actions-sdk/giza_actions/action.py:16' 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:39.123 | INFO    | Created flow run 'hilarious-fox' for flow 'Execution: Prediction with Cairo'\n",
+       "
18:27:39.837 | INFO    | Created flow run 'blond-mouse' 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" + "18:27:39.837 | \u001b[36mINFO\u001b[0m | Created flow run\u001b[35m 'blond-mouse'\u001b[0m for flow\u001b[1;35m 'Execution: Prediction with Cairo'\u001b[0m\n" ] }, "metadata": {}, @@ -1996,11 +2028,11 @@ { "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",
+       "
18:27:39.838 | INFO    | Action run 'blond-mouse' - View at https://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/db31f3a9-87d8-4e5b-8bec-4d25513c5235\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" + "18:27:39.838 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - View at \u001b[94mhttps://actions-server-raphael-doukhan-dblzzhtf5q-ew.a.run.app/flow-runs/flow-run/db31f3a9-87d8-4e5b-8bec-4d25513c5235\u001b[0m\n" ] }, "metadata": {}, @@ -2009,11 +2041,11 @@ { "data": { "text/html": [ - "
13:32:39.945 | INFO    | Action run 'hilarious-fox' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n",
+       "
18:27:40.177 | INFO    | Action run 'blond-mouse' - 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" + "18:27:40.177 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Created task run 'Preprocess Image-0' for task 'Preprocess Image'\n" ] }, "metadata": {}, @@ -2022,11 +2054,11 @@ { "data": { "text/html": [ - "
13:32:39.946 | INFO    | Action run 'hilarious-fox' - Executing 'Preprocess Image-0' immediately...\n",
+       "
18:27:40.180 | INFO    | Action run 'blond-mouse' - 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" + "18:27:40.180 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Executing 'Preprocess Image-0' immediately...\n" ] }, "metadata": {}, @@ -2035,11 +2067,11 @@ { "data": { "text/html": [ - "
13:32:40.556 | INFO    | Task run 'Preprocess Image-0' - Finished in state Completed()\n",
+       "
18:27:40.554 | 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" + "18:27:40.554 | \u001b[36mINFO\u001b[0m | Task run 'Preprocess Image-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -2048,11 +2080,11 @@ { "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",
+       "
18:27:40.675 | INFO    | Action run 'blond-mouse' - 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" + "18:27:40.675 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Created task run 'Prediction with Cairo-0' for task 'Prediction with Cairo'\n" ] }, "metadata": {}, @@ -2061,11 +2093,11 @@ { "data": { "text/html": [ - "
13:32:40.682 | INFO    | Action run 'hilarious-fox' - Executing 'Prediction with Cairo-0' immediately...\n",
+       "
18:27:40.676 | INFO    | Action run 'blond-mouse' - 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" + "18:27:40.676 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Executing 'Prediction with Cairo-0' immediately...\n" ] }, "metadata": {}, @@ -2082,11 +2114,11 @@ { "data": { "text/html": [ - "
13:32:47.291 | INFO    | Task run 'Prediction with Cairo-0' - Finished in state Completed()\n",
+       "
18:27:45.510 | 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" + "18:27:45.510 | \u001b[36mINFO\u001b[0m | Task run 'Prediction with Cairo-0' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -2095,15 +2127,13 @@ { "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",
+       "
18:27:45.513 | INFO    | Action run 'blond-mouse' - Result:  [  9.22331238 -17.78359985  -1.26280212   0.61476135 -19.04953003\n",
+       "   5.17411804 -10.98361206  -7.69139099  -1.38302612  -7.62950134]\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" + "18:27:45.513 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Result: [ 9.22331238 -17.78359985 -1.26280212 0.61476135 -19.04953003\n", + " 5.17411804 -10.98361206 -7.69139099 -1.38302612 -7.62950134]\n" ] }, "metadata": {}, @@ -2112,11 +2142,11 @@ { "data": { "text/html": [ - "
13:32:47.294 | INFO    | Action run 'hilarious-fox' - Request id:  \"aec2192b8b2d4381889270707b9b9ff2\"\n",
+       "
18:27:45.514 | INFO    | Action run 'blond-mouse' - Request id:  \"2c97ef6b2c464f668b2fe8748e77a3a9\"\n",
        "
\n" ], "text/plain": [ - "13:32:47.294 | \u001b[36mINFO\u001b[0m | Action run 'hilarious-fox' - Request id: \"aec2192b8b2d4381889270707b9b9ff2\"\n" + "18:27:45.514 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Request id: \"2c97ef6b2c464f668b2fe8748e77a3a9\"\n" ] }, "metadata": {}, @@ -2125,11 +2155,11 @@ { "data": { "text/html": [ - "
13:32:47.431 | INFO    | Action run 'hilarious-fox' - Finished in state Completed()\n",
+       "
18:27:45.638 | INFO    | Action run 'blond-mouse' - 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" + "18:27:45.638 | \u001b[36mINFO\u001b[0m | Action run 'blond-mouse' - Finished in state \u001b[32mCompleted\u001b[0m()\n" ] }, "metadata": {}, @@ -2138,22 +2168,20 @@ { "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]),\n", - " '\"aec2192b8b2d4381889270707b9b9ff2\"')" + "(array([ 9.22331238, -17.78359985, -1.26280212, 0.61476135,\n", + " -19.04953003, 5.17411804, -10.98361206, -7.69139099,\n", + " -1.38302612, -7.62950134]),\n", + " '\"2c97ef6b2c464f668b2fe8748e77a3a9\"')" ] }, - "execution_count": 12, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "\n", - "\n", - "MODEL_ID = 49 # Update with your model ID\n", - "VERSION_ID = 3 # Update with your version ID\n", + "MODEL_ID = 199 # Update with your model ID\n", + "VERSION_ID = 5 # Update with your version ID\n", "\n", "\n", "@task(name=f'Prediction with Cairo')\n", @@ -2169,7 +2197,7 @@ "\n", "@action(name=f'Execution: Prediction with Cairo', log_prints=True)\n", "def execution():\n", - " image = preprocess_image(\"./zero.jpg\")\n", + " image = preprocess_image(\"./imgs/zero.png\")\n", " (result, request_id) = prediction(image, MODEL_ID, VERSION_ID)\n", " print(\"Result: \", result)\n", " print(\"Request id: \", request_id)\n", @@ -2203,16 +2231,16 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "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", + "MODEL_ID = 199 # Update with your model ID\n", + "VERSION_ID = 5 # Update with your version ID\n", + "DEPLOYMENT_ID = 3 # 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", @@ -2224,7 +2252,6 @@ "\n", "proof = requests.get(d_url)\n", "\n", - "\n", "with open(\"zk.proof\", \"wb\") as f:\n", " f.write(proof.content)" ] diff --git a/giza_actions/model.py b/giza_actions/model.py index c948622..cdbe57c 100644 --- a/giza_actions/model.py +++ b/giza_actions/model.py @@ -148,6 +148,8 @@ def predict( serialized_output = json.dumps(response.json()["result"]) request_id = json.dumps(response.json()["request_id"]) + logging.info("Serialized: ", serialized_output) + preds = self._parse_cairo_response( serialized_output, output_dtype, fp_impl ) From 42a8180a6e710cd4489a90c4d80c017b921b25ad Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 30 Jan 2024 20:52:31 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 77 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 131bbeb..85ff26e 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,52 @@ # Actions SDK -The Actions SDK is a Python library designed to facilitate the development of applications on the Giza platform. It provides a set of decorators and classes to define tasks, actions, and models, and to handle data inputs. +The Actions SDK is a Python library designed to facilitate the development of ZKML applications on the Giza platform. It provides a set of decorators and classes to define tasks, actions, and models, and to handle data inputs. + +## Where to start? +Check out our extensive [documentation](https://actions.gizatech.xyz/welcome/giza-actions-sdk) to understand concepts and follow how-to-guides. ## Installation -The Actions SDK can be installed using [Poetry](https://python-poetry.org/): +Start by creating a virtual environment in your project directory and activate it: +```bash +$ python -m venv .env + +# Activate the virtual environment. On Linux and MacOs +$ source .env/bin/activate +# Activate Virtual environment on Windows: +$ .env/Scripts/activate ``` -poetry install +Now you’re ready to install ⚡Actions with the following command: + +```bash +$ pip install giza-actions ``` -Be sure you're logged into the [Giza CLI](https://cli.gizatech.xyz/resources/users) and have created a workspace: +## Setup +From your terminal, create a Giza user through our CLI in order to access the Giza Platform: +```bash +$ giza users create +``` +After creating your user, log into Giza: +```bash +$ giza users login +``` +Optional: you can create an API Key for your user in order to not regenerate your access token every few hours. +```bash +$ giza users create-api-key ``` -giza workspaces create +To create Actions Runs you will need a Giza Workspace, create it executing the following command in your terminal: +```bash +$ giza workspaces create ``` ## Usage ### Defining Tasks +A task is a function that represents a distinct segment of work in a Giza Actions workflow. Tasks provide a way to encapsulate parts of your workflow logic in traceable, reusable units across actions. Tasks are defined using the `@task` decorator. Here's an example: ```python @@ -30,38 +57,48 @@ def preprocess(): print(f"Preprocessing...") ``` -## Defining Actions +### Defining Actions +An action serves as a framework for coding ML inferencing workflow logic, enabling users to tailor the behaviour of their workflows. Actions are defined using the `@action` decorator. Here's an example: ```python from giza.action import action -@action +@action(name="My Action") def inference(): print(f"Running inference...") ``` -## Running Actions +### Deploy Actions -Actions can be deployed executing the Python script defining the Action. For example, if the Action is defined in `example.py`, you can run it using: +Deployments are server-side representations of actions. They keep essential metadata required for remote orchestration, including when, where, and how a workflow should run. Deployments transform workflows from functions that need to be manually activated to API-managed entities capable of being triggered remotely. -``` -python example.py -``` +We can easily create a deployment by creating the Action object and then calling the serve function in the entrypoint script: -Then, you can execute the Action using the Prefect UI: +```python +from giza_actions.action import Action, action +from giza_actions.task import task -``` -prefect server start -``` +@task +def print_hello(): + print(f"Hello Action!") -## Examples +@action +def hello_world(): + print_hello() + +if __name__ == '__main__': + action_deploy = Action(entrypoint=hello_world, name="hello-world-action") + action_deploy.serve(name="hello-world-action-deployment") +``` -Examples of how to use the Actions SDK can be found in the `examples` directory. Each example includes a README with detailed instructions on how to run the example. +Running this script will do two things: +- Create a deployment called "hello-world-action" for your action in the Giza Platform. +- Stay running to listen for action runs for this deployment; when a run is found, it will be asynchronously executed within a subprocess locally. -For instance, the `imagenet` example demonstrates how to use the Giza SDK to perform image classification using a pre-trained ResNet-50 model from the ONNX model zoo. +## Examples -To understand how to execute these examples, please refer to the README file in each example's directory. +Examples of how to use the Actions SDK can be found in the `examples` directory. Each example includes a README or a Notebook with detailed instructions on how to run the example. ## Contributing