diff --git a/program/cohort.ipynb b/program/cohort.ipynb index 8353afc..3781cf4 100644 --- a/program/cohort.ipynb +++ b/program/cohort.ipynb @@ -46,25 +46,14 @@ }, { "cell_type": "code", - "execution_count": 341, + "execution_count": 1, "id": "4b2265b0", "metadata": { "tags": [ "hide-cell" ] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n", - "The dotenv extension is already loaded. To reload it, use:\n", - " %reload_ext dotenv\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", @@ -104,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 342, + "execution_count": 2, "id": "32c4d764", "metadata": { "tags": [] @@ -124,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 343, + "execution_count": 3, "id": "3164a3af", "metadata": {}, "outputs": [], @@ -148,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 344, + "execution_count": 4, "id": "7bc40d28", "metadata": {}, "outputs": [], @@ -170,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 345, + "execution_count": 5, "id": "3b3f17e5", "metadata": {}, "outputs": [], @@ -213,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 346, + "execution_count": 6, "id": "942a01b5", "metadata": {}, "outputs": [], @@ -248,7 +237,7 @@ }, { "cell_type": "code", - "execution_count": 347, + "execution_count": 7, "id": "f1cd2f0e-446d-48a9-a008-b4f1cc593bfc", "metadata": { "tags": [] @@ -355,7 +344,7 @@ "4 3450.0 FEMALE " ] }, - "execution_count": 347, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -398,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 348, + "execution_count": 8, "id": "f2107c25-e730-4e22-a1b8-5bda53e61124", "metadata": { "tags": [] @@ -577,7 +566,7 @@ "max 6300.000000 NaN " ] }, - "execution_count": 348, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -596,7 +585,7 @@ }, { "cell_type": "code", - "execution_count": 349, + "execution_count": 9, "id": "1242122a-726e-4c37-a718-dd8e873d1612", "metadata": { "tags": [] @@ -652,7 +641,7 @@ }, { "cell_type": "code", - "execution_count": 350, + "execution_count": 10, "id": "cf1cf582-8831-4f83-bb17-2175afb193e8", "metadata": { "tags": [] @@ -667,7 +656,7 @@ "Name: count, dtype: int64" ] }, - "execution_count": 350, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -690,7 +679,7 @@ }, { "cell_type": "code", - "execution_count": 351, + "execution_count": 11, "id": "cc42cb08-275c-4b05-9d2b-77052da2f336", "metadata": { "tags": [] @@ -709,7 +698,7 @@ "dtype: int64" ] }, - "execution_count": 351, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -728,7 +717,7 @@ }, { "cell_type": "code", - "execution_count": 352, + "execution_count": 12, "id": "3c57d55d-afd6-467a-a7a8-ff04132770ed", "metadata": { "tags": [] @@ -747,7 +736,7 @@ "dtype: int64" ] }, - "execution_count": 352, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -772,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 353, + "execution_count": 13, "id": "2852c740", "metadata": {}, "outputs": [ @@ -818,7 +807,7 @@ }, { "cell_type": "code", - "execution_count": 354, + "execution_count": 14, "id": "707cc972", "metadata": {}, "outputs": [ @@ -866,7 +855,7 @@ }, { "cell_type": "code", - "execution_count": 355, + "execution_count": 15, "id": "3daf3ba1-d218-4ad4-b862-af679b91273f", "metadata": { "tags": [] @@ -946,7 +935,7 @@ "body_mass_g 640316.716388 " ] }, - "execution_count": 355, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -977,7 +966,7 @@ }, { "cell_type": "code", - "execution_count": 356, + "execution_count": 16, "id": "1d793e09-2cb9-47ff-a0e6-199a0f4fc1b3", "metadata": { "tags": [] @@ -1057,7 +1046,7 @@ "body_mass_g 1.000000 " ] }, - "execution_count": 356, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -1088,7 +1077,7 @@ }, { "cell_type": "code", - "execution_count": 357, + "execution_count": 17, "id": "1258c99d", "metadata": {}, "outputs": [ @@ -1128,7 +1117,7 @@ }, { "cell_type": "code", - "execution_count": 358, + "execution_count": 18, "id": "45b0a87f-028d-477f-9b65-199728c0b7ee", "metadata": { "tags": [] @@ -1198,7 +1187,7 @@ }, { "cell_type": "code", - "execution_count": 359, + "execution_count": 19, "id": "78fe069e", "metadata": {}, "outputs": [], @@ -1217,7 +1206,7 @@ }, { "cell_type": "code", - "execution_count": 360, + "execution_count": 20, "id": "fb6ba7c0-1bd6-4fe5-8b7f-f6cbdfd3846c", "metadata": { "tags": [ @@ -1444,7 +1433,7 @@ }, { "cell_type": "code", - "execution_count": 361, + "execution_count": 21, "id": "d1f122a4-acff-4687-91b9-bfef13567d88", "metadata": { "tags": [ @@ -1457,7 +1446,7 @@ "output_type": "stream", "text": [ "\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\n", - "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.21s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.16s\u001b[0m\u001b[0m\n" ] } ], @@ -1580,7 +1569,7 @@ }, { "cell_type": "code", - "execution_count": 362, + "execution_count": 22, "id": "d88e9ccf", "metadata": {}, "outputs": [], @@ -1602,7 +1591,7 @@ }, { "cell_type": "code", - "execution_count": 363, + "execution_count": 23, "id": "331fe373", "metadata": {}, "outputs": [], @@ -1638,22 +1627,14 @@ }, { "cell_type": "code", - "execution_count": 364, + "execution_count": 24, "id": "3aa4471a", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:Defaulting to only available Python version: py3\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.sklearn.processing import SKLearnProcessor\n", "\n", @@ -1685,7 +1666,7 @@ }, { "cell_type": "code", - "execution_count": 365, + "execution_count": 25, "id": "cdbd9303", "metadata": { "tags": [ @@ -1765,7 +1746,7 @@ }, { "cell_type": "code", - "execution_count": 366, + "execution_count": 26, "id": "e140642a", "metadata": { "tags": [ @@ -1777,16 +1758,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session3-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '33e834eb-1456-41a2-9ad1-6f55cc21e552',\n", + " 'ResponseMetadata': {'RequestId': 'ae1f315d-f268-483b-a670-6e7491cd3a13',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '33e834eb-1456-41a2-9ad1-6f55cc21e552',\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'ae1f315d-f268-483b-a670-6e7491cd3a13',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:07 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:45:47 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 366, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -1841,7 +1822,7 @@ }, { "cell_type": "code", - "execution_count": 367, + "execution_count": 27, "id": "ac0b891c", "metadata": {}, "outputs": [], @@ -1860,7 +1841,7 @@ }, { "cell_type": "code", - "execution_count": 368, + "execution_count": 28, "id": "d92b121d-dcb9-43e8-9ee3-3ececb583e7e", "metadata": { "tags": [ @@ -2039,7 +2020,7 @@ }, { "cell_type": "code", - "execution_count": 369, + "execution_count": 29, "id": "14ea27ce-c453-4cb0-b309-dbecd732957e", "metadata": { "tags": [ @@ -2059,23 +2040,23 @@ "output_type": "stream", "text": [ "Keras version: 2.14.0\n", - "8/8 - 0s - loss: 1.1168 - accuracy: 0.2803 - val_loss: 1.0989 - val_accuracy: 0.4314 - 247ms/epoch - 31ms/step\n", + "8/8 - 0s - loss: 1.1231 - accuracy: 0.4937 - val_loss: 1.0338 - val_accuracy: 0.5490 - 255ms/epoch - 32ms/step\n", "2/2 [==============================] - 0s 1ms/step\n", - "Validation accuracy: 0.43137254901960786\n" + "Validation accuracy: 0.5490196078431373\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmp8tdths9g/model/001/assets\n" + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpn2jk6ol0/model/001/assets\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[32m.\u001b[0mKeras version: 2.14.0\n" + "\u001b[32m.\u001b[0m" ] }, { @@ -2089,24 +2070,25 @@ "name": "stdout", "output_type": "stream", "text": [ - "8/8 - 0s - loss: 1.1583 - accuracy: 0.2594 - val_loss: 1.1217 - val_accuracy: 0.3137 - 234ms/epoch - 29ms/step\n", - "2/2 [==============================] - 0s 3ms/step\n", - "Validation accuracy: 0.3137254901960784\n" + "Keras version: 2.14.0\n", + "8/8 - 0s - loss: 1.0947 - accuracy: 0.3473 - val_loss: 1.0409 - val_accuracy: 0.3725 - 207ms/epoch - 26ms/step\n", + "2/2 [==============================] - 0s 1ms/step\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpcpi85j8s/model/001/assets\n" + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpdmda78an/model/001/assets\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ + "Validation accuracy: 0.37254901960784315\n", "\u001b[32m.\u001b[0m\n", - "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 1.09s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 1.19s\u001b[0m\u001b[0m\n" ] } ], @@ -2186,7 +2168,7 @@ }, { "cell_type": "code", - "execution_count": 370, + "execution_count": 30, "id": "d00eda86", "metadata": { "tags": [ @@ -2230,7 +2212,7 @@ }, { "cell_type": "code", - "execution_count": 371, + "execution_count": 31, "id": "90fe82ae-6a2c-4461-bc83-bb52d8871e3b", "metadata": { "tags": [] @@ -2296,7 +2278,7 @@ }, { "cell_type": "code", - "execution_count": 372, + "execution_count": 32, "id": "99e4850c-83d6-4f4e-a813-d5a3f4bb7486", "metadata": { "tags": [ @@ -2365,7 +2347,7 @@ }, { "cell_type": "code", - "execution_count": 373, + "execution_count": 33, "id": "d92cac3d", "metadata": { "tags": [ @@ -2385,16 +2367,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session4-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '2d25d06c-d582-428e-a6ea-985e47324a3c',\n", + " 'ResponseMetadata': {'RequestId': '42ceacf9-3b68-4727-a8be-82da3aac0a64',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '2d25d06c-d582-428e-a6ea-985e47324a3c',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '42ceacf9-3b68-4727-a8be-82da3aac0a64',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:10 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:45:52 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 373, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -2438,7 +2420,7 @@ }, { "cell_type": "code", - "execution_count": 374, + "execution_count": 34, "id": "57c2915c", "metadata": {}, "outputs": [ @@ -2448,7 +2430,7 @@ "PosixPath('code/containers/training/train.py')" ] }, - "execution_count": 374, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -2475,7 +2457,7 @@ }, { "cell_type": "code", - "execution_count": 375, + "execution_count": 35, "id": "3ffa9250", "metadata": { "tags": [ @@ -2517,7 +2499,7 @@ }, { "cell_type": "code", - "execution_count": 376, + "execution_count": 36, "id": "de5d473c", "metadata": { "tags": [ @@ -2572,7 +2554,7 @@ }, { "cell_type": "code", - "execution_count": 377, + "execution_count": 37, "id": "e37a06ac", "metadata": { "tags": [ @@ -2622,21 +2604,23 @@ "\u001b[0m\u001b[34m => [internal] load .dockerignore 0.0s\n", "\u001b[0m\u001b[34m => => transferring context: 2B 0.0s\n", "\u001b[0m => [internal] load metadata for docker.io/library/python:3.10-slim 0.8s\n", - "\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Building 1.0s (3/3) \n", + "\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Building 1.0s (4/10) \n", "\u001b[34m => [internal] load build definition from Dockerfile 0.0s\n", "\u001b[0m\u001b[34m => => transferring dockerfile: 647B 0.0s\n", "\u001b[0m\u001b[34m => [internal] load .dockerignore 0.0s\n", "\u001b[0m\u001b[34m => => transferring context: 2B 0.0s\n", - "\u001b[0m\u001b[34m => [internal] load metadata for docker.io/library/python:3.10-slim 0.9s\n", - "\u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Building 1.0s (11/11) FINISHED \n", + "\u001b[0m\u001b[34m => [internal] load metadata for docker.io/library/python:3.10-slim 0.8s\n", + "\u001b[0m => [internal] load build context 0.0s\n", + "\u001b[34m => [1/6] FROM docker.io/library/python:3.10-slim@sha256:f80e619e067eebe4 0.0s\n", + "\u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Building 1.0s (11/11) FINISHED \n", "\u001b[34m => [internal] load build definition from Dockerfile 0.0s\n", "\u001b[0m\u001b[34m => => transferring dockerfile: 647B 0.0s\n", "\u001b[0m\u001b[34m => [internal] load .dockerignore 0.0s\n", "\u001b[0m\u001b[34m => => transferring context: 2B 0.0s\n", - "\u001b[0m\u001b[34m => [internal] load metadata for docker.io/library/python:3.10-slim 0.9s\n", - "\u001b[0m\u001b[34m => [1/6] FROM docker.io/library/python:3.10-slim@sha256:f80e619e067eebe4 0.0s\n", + "\u001b[0m\u001b[34m => [internal] load metadata for docker.io/library/python:3.10-slim 0.8s\n", "\u001b[0m\u001b[34m => [internal] load build context 0.0s\n", "\u001b[0m\u001b[34m => => transferring context: 4.95kB 0.0s\n", + "\u001b[0m\u001b[34m => [1/6] FROM docker.io/library/python:3.10-slim@sha256:f80e619e067eebe4 0.0s\n", "\u001b[0m\u001b[34m => CACHED [2/6] RUN apt-get -y update && apt-get install -y --no-install 0.0s\n", "\u001b[0m\u001b[34m => CACHED [3/6] COPY requirements.txt . 0.0s\n", "\u001b[0m\u001b[34m => CACHED [4/6] RUN pip install --user --upgrade pip 0.0s\n", @@ -2646,14 +2630,7 @@ "\u001b[0m\u001b[34m => => exporting layers 0.0s\n", "\u001b[0m\u001b[34m => => writing image sha256:952fdf459612946969bb2cdf46ca507616c57dd316232 0.0s\n", "\u001b[0m\u001b[34m => => naming to docker.io/library/keras-custom-training-container 0.0s\n", - "\u001b[0m\u001b[?25h" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", + "\u001b[0m\u001b[?25h\n", "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them\n" ] } @@ -2692,7 +2669,7 @@ }, { "cell_type": "code", - "execution_count": 378, + "execution_count": 38, "id": "ceede5e2", "metadata": { "tags": [ @@ -2716,21 +2693,21 @@ "884af60a304e: Preparing\n", "c8f253aef560: Preparing\n", "a483da8ab3e9: Preparing\n", - "9362be696331: Waiting\n", "23cef6a8f8d1: Waiting\n", "884af60a304e: Waiting\n", - "c8f253aef560: Waiting\n", + "9362be696331: Waiting\n", "a483da8ab3e9: Waiting\n", + "c8f253aef560: Waiting\n", "d2e84e969834: Layer already exists\n", + "78ea0a62e625: Layer already exists\n", "dc9f227d801d: Layer already exists\n", "56cff974c816: Layer already exists\n", "25f8ff0f81d0: Layer already exists\n", - "78ea0a62e625: Layer already exists\n", - "9362be696331: Layer already exists\n", - "23cef6a8f8d1: Layer already exists\n", "884af60a304e: Layer already exists\n", - "a483da8ab3e9: Layer already exists\n", + "23cef6a8f8d1: Layer already exists\n", + "9362be696331: Layer already exists\n", "c8f253aef560: Layer already exists\n", + "a483da8ab3e9: Layer already exists\n", "latest: digest: sha256:66434da50d99b87f7c1956ad680873e2921b23938a4090d7df8977446bccddeb size: 2422\n" ] } @@ -2788,7 +2765,7 @@ }, { "cell_type": "code", - "execution_count": 379, + "execution_count": 39, "id": "49d9ab0e", "metadata": {}, "outputs": [ @@ -2798,7 +2775,7 @@ "'325223348818.dkr.ecr.us-east-1.amazonaws.com/keras-custom-training-container:latest'" ] }, - "execution_count": 379, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -2830,7 +2807,7 @@ }, { "cell_type": "code", - "execution_count": 380, + "execution_count": 40, "id": "f4e17204", "metadata": { "tags": [ @@ -2873,7 +2850,7 @@ }, { "cell_type": "code", - "execution_count": 381, + "execution_count": 41, "id": "86056197", "metadata": { "tags": [ @@ -2885,16 +2862,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session5-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '9a35c31b-3a23-45b7-9ea2-0a5822d704cd',\n", + " 'ResponseMetadata': {'RequestId': '0ab27679-26ed-4319-b1c4-ed92c6183540',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '9a35c31b-3a23-45b7-9ea2-0a5822d704cd',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '0ab27679-26ed-4319-b1c4-ed92c6183540',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:29 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:01 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 381, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -2940,7 +2917,7 @@ }, { "cell_type": "code", - "execution_count": 382, + "execution_count": 42, "id": "f367d0e3", "metadata": {}, "outputs": [], @@ -2975,7 +2952,7 @@ }, { "cell_type": "code", - "execution_count": 383, + "execution_count": 43, "id": "c8c82750", "metadata": {}, "outputs": [], @@ -3008,21 +2985,12 @@ }, { "cell_type": "code", - "execution_count": 384, + "execution_count": 44, "id": "038ff2e5-ed28-445b-bc03-4e996ec2286f", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/svpino/dev/ml.school/.venv/lib/python3.10/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.workflow.steps import TuningStep\n", "\n", @@ -3066,7 +3034,7 @@ }, { "cell_type": "code", - "execution_count": 385, + "execution_count": 45, "id": "9799ab39-fcae-41f4-a68b-85ab71b3ba9a", "metadata": { "tags": [ @@ -3081,13 +3049,7 @@ "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", "WARNING:sagemaker.estimator:No finished training job found associated with this estimator. Please make sure this estimator is only used for building workflow config\n", "WARNING:sagemaker.estimator:No finished training job found associated with this estimator. Please make sure this estimator is only used for building workflow config\n", - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", "WARNING:sagemaker.estimator:No finished training job found associated with this estimator. Please make sure this estimator is only used for building workflow config\n", "WARNING:sagemaker.estimator:No finished training job found associated with this estimator. Please make sure this estimator is only used for building workflow config\n", @@ -3098,16 +3060,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session6-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'a87eeb8c-686e-43e2-8ab5-4e4a57033325',\n", + " 'ResponseMetadata': {'RequestId': '465ede44-428a-4bf9-bd30-16a224949c72',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'a87eeb8c-686e-43e2-8ab5-4e4a57033325',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '465ede44-428a-4bf9-bd30-16a224949c72',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:31 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:03 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 385, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -3163,7 +3125,7 @@ }, { "cell_type": "code", - "execution_count": 386, + "execution_count": 46, "id": "0590fcfa", "metadata": {}, "outputs": [], @@ -3182,7 +3144,7 @@ }, { "cell_type": "code", - "execution_count": 387, + "execution_count": 47, "id": "3ee3ab26-afa5-4ceb-9f7a-005d5fdea646", "metadata": { "tags": [ @@ -3259,7 +3221,7 @@ }, { "cell_type": "code", - "execution_count": 388, + "execution_count": 48, "id": "9a2540d8-278a-4953-bc54-0469d154427d", "metadata": { "tags": [ @@ -3279,16 +3241,28 @@ "output_type": "stream", "text": [ "Keras version: 2.14.0\n", - "8/8 - 0s - loss: 1.5299 - accuracy: 0.4477 - val_loss: 1.4370 - val_accuracy: 0.3922 - 249ms/epoch - 31ms/step\n", - "2/2 [==============================] - 0s 3ms/step\n", - "Validation accuracy: 0.39215686274509803\n" + "8/8 - 0s - loss: 0.9825 - accuracy: 0.5272 - val_loss: 0.9976 - val_accuracy: 0.4706 - 221ms/epoch - 28ms/step\n", + "2/2 [==============================] - 0s 2ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpsozh1nwx/model/001/assets\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validation accuracy: 0.47058823529411764\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpexv52705/model/001/assets\n", "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.RestoredOptimizer` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.RestoredOptimizer`.\n", "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" ] @@ -3297,8 +3271,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "2/2 [==============================] - 0s 3ms/step\n", - "Test accuracy: 0.43137254901960786\n", + "2/2 [==============================] - 0s 1ms/step\n", + "Test accuracy: 0.5882352941176471\n", "\u001b[32m.\u001b[0m" ] }, @@ -3314,28 +3288,54 @@ "output_type": "stream", "text": [ "Keras version: 2.14.0\n", - "8/8 - 0s - loss: 1.3392 - accuracy: 0.1883 - val_loss: 1.2168 - val_accuracy: 0.1765 - 231ms/epoch - 29ms/step\n", - "2/2 [==============================] - 0s 2ms/step\n", - "Validation accuracy: 0.17647058823529413\n" + "8/8 - 0s - loss: 1.3414 - accuracy: 0.2343 - val_loss: 1.1537 - val_accuracy: 0.3333 - 214ms/epoch - 27ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:tensorflow:5 out of the last 9 calls to .predict_function at 0x2b372b0a0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2/2 [==============================] - 0s 2ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmps71h92cf/model/001/assets\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validation accuracy: 0.3333333333333333\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpusf9ay5r/model/001/assets\n", "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.RestoredOptimizer` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.RestoredOptimizer`.\n", - "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n", + "WARNING:tensorflow:6 out of the last 11 calls to .predict_function at 0x2b372beb0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "2/2 [==============================] - 0s 4ms/step\n", - "Test accuracy: 0.21568627450980393\n", + "2/2 [==============================] - 0s 2ms/step\n", + "Test accuracy: 0.39215686274509803\n", "\u001b[32m.\u001b[0m\n", - "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 1.46s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 1.25s\u001b[0m\u001b[0m\n" ] } ], @@ -3418,7 +3418,7 @@ }, { "cell_type": "code", - "execution_count": 389, + "execution_count": 49, "id": "4f19e15b", "metadata": {}, "outputs": [], @@ -3445,7 +3445,7 @@ }, { "cell_type": "code", - "execution_count": 390, + "execution_count": 50, "id": "1f27b2ef", "metadata": {}, "outputs": [], @@ -3471,7 +3471,7 @@ }, { "cell_type": "code", - "execution_count": 391, + "execution_count": 51, "id": "2fdff07f", "metadata": { "tags": [ @@ -3512,7 +3512,7 @@ }, { "cell_type": "code", - "execution_count": 392, + "execution_count": 52, "id": "48139a07-5c8e-4bc6-b666-bf9531f7f520", "metadata": { "tags": [ @@ -3576,7 +3576,7 @@ }, { "cell_type": "code", - "execution_count": 393, + "execution_count": 53, "id": "21a1ab1f", "metadata": { "tags": [ @@ -3600,16 +3600,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session7-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '98937049-ca98-4951-8e90-65ac69b77dd2',\n", + " 'ResponseMetadata': {'RequestId': 'c9cd2981-f5f4-4732-8f79-9640c4433902',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '98937049-ca98-4951-8e90-65ac69b77dd2',\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'c9cd2981-f5f4-4732-8f79-9640c4433902',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:34 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:06 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 393, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -3654,7 +3654,7 @@ }, { "cell_type": "code", - "execution_count": 394, + "execution_count": 54, "id": "bb70f907", "metadata": {}, "outputs": [], @@ -3674,7 +3674,7 @@ }, { "cell_type": "code", - "execution_count": 395, + "execution_count": 55, "id": "4ca4cb61", "metadata": {}, "outputs": [], @@ -3701,7 +3701,7 @@ }, { "cell_type": "code", - "execution_count": 396, + "execution_count": 56, "id": "8c05a7e1", "metadata": {}, "outputs": [], @@ -3737,7 +3737,7 @@ }, { "cell_type": "code", - "execution_count": 397, + "execution_count": 57, "id": "c9773a4a", "metadata": { "tags": [ @@ -3802,7 +3802,7 @@ }, { "cell_type": "code", - "execution_count": 398, + "execution_count": 58, "id": "4d09cc85", "metadata": { "tags": [ @@ -3814,13 +3814,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session8-pipeline/code/c90fe2477ad62c58fbc0c004cc5ab07f/sourcedir.tar.gz\n", "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/session8-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n", "WARNING:sagemaker.workflow._utils:Popping out 'CertifyForMarketplace' from the pipeline definition since it will be overridden in pipeline execution time.\n", @@ -3833,16 +3827,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session8-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '851c81af-eabe-4eb5-8187-484437999eef',\n", + " 'ResponseMetadata': {'RequestId': '09e144e1-2dba-4d07-9cc0-e4f048eb19b0',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '851c81af-eabe-4eb5-8187-484437999eef',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '09e144e1-2dba-4d07-9cc0-e4f048eb19b0',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:36 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:08 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 398, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -3890,7 +3884,7 @@ }, { "cell_type": "code", - "execution_count": 399, + "execution_count": 59, "id": "745486b5", "metadata": {}, "outputs": [], @@ -3912,7 +3906,7 @@ }, { "cell_type": "code", - "execution_count": 400, + "execution_count": 60, "id": "c4431bbf", "metadata": {}, "outputs": [], @@ -3943,7 +3937,7 @@ }, { "cell_type": "code", - "execution_count": 401, + "execution_count": 61, "id": "bebeecab", "metadata": {}, "outputs": [], @@ -3973,7 +3967,7 @@ }, { "cell_type": "code", - "execution_count": 402, + "execution_count": 62, "id": "36e2a2b1-6711-4266-95d8-d2aebd52e199", "metadata": { "tags": [] @@ -4002,7 +3996,7 @@ }, { "cell_type": "code", - "execution_count": 403, + "execution_count": 63, "id": "f70bcd33-b499-4e2b-953e-94d1ed96c10a", "metadata": { "tags": [ @@ -4026,16 +4020,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session9-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '98d320f5-57fb-402a-885d-30b1829c8477',\n", + " 'ResponseMetadata': {'RequestId': 'a78e446d-619f-42b1-b69b-89cf2827ce6c',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '98d320f5-57fb-402a-885d-30b1829c8477',\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'a78e446d-619f-42b1-b69b-89cf2827ce6c',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Thu, 28 Mar 2024 14:14:56 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:10 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 403, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -4083,7 +4077,7 @@ }, { "cell_type": "code", - "execution_count": 405, + "execution_count": 64, "id": "a67726d7", "metadata": {}, "outputs": [ @@ -4098,7 +4092,7 @@ " 'ModelApprovalStatus': 'Approved'}" ] }, - "execution_count": 405, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -4140,7 +4134,7 @@ }, { "cell_type": "code", - "execution_count": 406, + "execution_count": 65, "id": "f2e94adc", "metadata": {}, "outputs": [], @@ -4158,7 +4152,7 @@ }, { "cell_type": "code", - "execution_count": 407, + "execution_count": 66, "id": "bd12fbe9", "metadata": {}, "outputs": [], @@ -4188,7 +4182,7 @@ }, { "cell_type": "code", - "execution_count": 411, + "execution_count": 67, "id": "c79a0e74", "metadata": { "tags": [ @@ -4200,7 +4194,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing code/serving/app.py\n" + "Overwriting code/serving/app.py\n" ] } ], @@ -4313,7 +4307,7 @@ }, { "cell_type": "code", - "execution_count": 301, + "execution_count": 68, "id": "befd5ad3", "metadata": {}, "outputs": [], @@ -4335,7 +4329,7 @@ }, { "cell_type": "code", - "execution_count": 413, + "execution_count": 69, "id": "dee516e9", "metadata": {}, "outputs": [ @@ -4384,29 +4378,12 @@ }, { "cell_type": "code", - "execution_count": 303, + "execution_count": 70, "id": "7c8852d5-818a-406c-944d-30bf6de90288", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker:Creating model with name: basic-penguins-2024-03-27-20-03-59-182\n", - "INFO:sagemaker:Creating endpoint-config with name penguins-endpoint\n", - "INFO:sagemaker:Creating endpoint with name penguins-endpoint\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-----!" - ] - } - ], + "outputs": [], "source": [ "%%script false --no-raise-error\n", "# | eval: false\n", @@ -4434,7 +4411,7 @@ }, { "cell_type": "code", - "execution_count": 417, + "execution_count": 71, "id": "ba7da291", "metadata": {}, "outputs": [], @@ -4456,7 +4433,7 @@ }, { "cell_type": "code", - "execution_count": 418, + "execution_count": 72, "id": "0817a25e-8224-4911-830b-d659e7458b4a", "metadata": { "tags": [] @@ -4466,27 +4443,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{\n", - " \"predictions\": [\n", - " [\n", - " 0.00695773,\n", - " 0.012256721,\n", - " 0.980785549\n", - " ],\n", - " [\n", - " 0.603334665,\n", - " 0.303359121,\n", - " 0.0933062956\n", - " ],\n", - " [\n", - " 0.818286,\n", - " 0.157282069,\n", - " 0.0244319625\n", - " ]\n", - " ]\n", - "}\n", - "\n", - "Species: [2 0 0]\n" + "An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint penguins-endpoint of account 325223348818 not found.\n" ] } ], @@ -4534,7 +4491,7 @@ }, { "cell_type": "code", - "execution_count": 307, + "execution_count": 73, "id": "e1dbadb0", "metadata": {}, "outputs": [], @@ -4567,7 +4524,7 @@ }, { "cell_type": "code", - "execution_count": 308, + "execution_count": 74, "id": "ac7630ca", "metadata": {}, "outputs": [], @@ -4585,7 +4542,7 @@ }, { "cell_type": "code", - "execution_count": 309, + "execution_count": 75, "id": "44b651af", "metadata": { "tags": [ @@ -4597,7 +4554,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing code/lambda/lambda.py\n" + "Overwriting code/lambda/lambda.py\n" ] } ], @@ -4714,7 +4671,7 @@ }, { "cell_type": "code", - "execution_count": 310, + "execution_count": 76, "id": "200d0370", "metadata": { "tags": [ @@ -4785,7 +4742,7 @@ }, { "cell_type": "code", - "execution_count": 311, + "execution_count": 77, "id": "4a742974", "metadata": { "tags": [ @@ -4796,13 +4753,13 @@ { "data": { "text/plain": [ - "{'ResponseMetadata': {'RequestId': '675b127b-0deb-4fdc-94e9-a694ec5a5ecf',\n", + "{'ResponseMetadata': {'RequestId': '430ab54f-c8c6-4852-a5e8-42669f8acd34',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'date': 'Wed, 27 Mar 2024 20:24:49 GMT',\n", + " 'HTTPHeaders': {'date': 'Thu, 28 Mar 2024 15:46:13 GMT',\n", " 'content-type': 'application/json',\n", " 'content-length': '1593',\n", " 'connection': 'keep-alive',\n", - " 'x-amzn-requestid': '675b127b-0deb-4fdc-94e9-a694ec5a5ecf'},\n", + " 'x-amzn-requestid': '430ab54f-c8c6-4852-a5e8-42669f8acd34'},\n", " 'RetryAttempts': 0},\n", " 'FunctionName': 'deployment_fn',\n", " 'FunctionArn': 'arn:aws:lambda:us-east-1:325223348818:function:deployment_fn',\n", @@ -4813,15 +4770,15 @@ " 'Description': '',\n", " 'Timeout': 600,\n", " 'MemorySize': 128,\n", - " 'LastModified': '2024-03-27T20:24:49.000+0000',\n", - " 'CodeSha256': 'iF7lzUR6+0hwrrteBx0uizt/p4Yc3NebQxmkbjD9zx0=',\n", + " 'LastModified': '2024-03-28T15:46:13.000+0000',\n", + " 'CodeSha256': 'l4kFNMlylzvLEXPozhpRDuhWg63kP9XVkBfx+Ib9ZrY=',\n", " 'Version': '$LATEST',\n", " 'Environment': {'Variables': {'ROLE': 'arn:aws:iam::325223348818:role/service-role/AmazonSageMaker-ExecutionRole-20230312T160501',\n", " 'DATA_CAPTURE_PERCENTAGE': '100',\n", " 'DATA_CAPTURE_DESTINATION': 's3://mlschool/penguins/monitoring/data-capture',\n", " 'ENDPOINT': 'penguins-endpoint'}},\n", " 'TracingConfig': {'Mode': 'PassThrough'},\n", - " 'RevisionId': 'f63f8c3f-ed83-4d64-b49a-cec40a817c98',\n", + " 'RevisionId': 'ff10a1f2-a975-446d-8881-64493cbe5444',\n", " 'Layers': [],\n", " 'State': 'Active',\n", " 'LastUpdateStatus': 'InProgress',\n", @@ -4836,7 +4793,7 @@ " 'LogGroup': '/aws/lambda/deployment_fn'}}" ] }, - "execution_count": 311, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } @@ -4881,7 +4838,7 @@ }, { "cell_type": "code", - "execution_count": 316, + "execution_count": 78, "id": "1f86b997", "metadata": {}, "outputs": [], @@ -4914,7 +4871,7 @@ }, { "cell_type": "code", - "execution_count": 317, + "execution_count": 79, "id": "5cc3e44b", "metadata": {}, "outputs": [], @@ -4939,7 +4896,7 @@ }, { "cell_type": "code", - "execution_count": 318, + "execution_count": 80, "id": "3d86577a", "metadata": { "tags": [ @@ -4965,16 +4922,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session12-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'a7b94023-5c20-4a27-b606-79cf7e1dd386',\n", + " 'ResponseMetadata': {'RequestId': '68ba9372-19f6-4f97-9a88-a7a0d582cadf',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'a7b94023-5c20-4a27-b606-79cf7e1dd386',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '68ba9372-19f6-4f97-9a88-a7a0d582cadf',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '86',\n", - " 'date': 'Wed, 27 Mar 2024 20:28:11 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:16 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 318, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -5010,7 +4967,7 @@ }, { "cell_type": "code", - "execution_count": 329, + "execution_count": 81, "id": "1dd5bb33", "metadata": {}, "outputs": [ @@ -5018,27 +4975,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{\n", - " \"predictions\": [\n", - " [\n", - " 0.0403208546,\n", - " 0.0210227184,\n", - " 0.93865639\n", - " ],\n", - " [\n", - " 0.689678669,\n", - " 0.17514421,\n", - " 0.135177106\n", - " ],\n", - " [\n", - " 0.960919619,\n", - " 0.0248175282,\n", - " 0.0142629147\n", - " ]\n", - " ]\n", - "}\n", - "\n", - "Species: [2 0 0]\n" + "Waiter EndpointInService failed: Waiter encountered a terminal failure state: Matched expected service error code: ValidationException\n" ] } ], @@ -5086,7 +5023,7 @@ }, { "cell_type": "code", - "execution_count": 330, + "execution_count": 82, "id": "96751e71", "metadata": {}, "outputs": [], @@ -5106,7 +5043,7 @@ }, { "cell_type": "code", - "execution_count": 331, + "execution_count": 83, "id": "1ee4b9d5", "metadata": {}, "outputs": [], @@ -5133,7 +5070,7 @@ }, { "cell_type": "code", - "execution_count": 332, + "execution_count": 84, "id": "63f294bc", "metadata": {}, "outputs": [], @@ -5159,7 +5096,7 @@ }, { "cell_type": "code", - "execution_count": 333, + "execution_count": 85, "id": "9985bd49", "metadata": {}, "outputs": [], @@ -5187,7 +5124,7 @@ }, { "cell_type": "code", - "execution_count": 334, + "execution_count": 86, "id": "32302639", "metadata": {}, "outputs": [ @@ -5227,7 +5164,7 @@ }, { "cell_type": "code", - "execution_count": 335, + "execution_count": 87, "id": "18adeb93", "metadata": { "tags": [ @@ -5255,7 +5192,7 @@ }, { "cell_type": "code", - "execution_count": 336, + "execution_count": 88, "id": "fafb5514", "metadata": {}, "outputs": [], @@ -5280,7 +5217,7 @@ }, { "cell_type": "code", - "execution_count": 337, + "execution_count": 89, "id": "b95c22b2", "metadata": { "tags": [ @@ -5305,16 +5242,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session13-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '5da2f115-4b6e-481e-87d9-70ce6d8fd4f2',\n", + " 'ResponseMetadata': {'RequestId': 'd0f78f5d-7380-4d67-8ba1-ecff76a8d29a',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '5da2f115-4b6e-481e-87d9-70ce6d8fd4f2',\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'd0f78f5d-7380-4d67-8ba1-ecff76a8d29a',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '86',\n", - " 'date': 'Wed, 27 Mar 2024 20:46:58 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:46:19 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 337, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -5347,17 +5284,17 @@ "\n", "Deploying the model we trained directly to an endpoint doesn't lets us control the data that goes in and comes out of the endpoint. The TensorFlow model we trained requires transformed data, which makes it useless to other applications:\n", "\n", - " \"Prediction\n", + " \"Prediction\n", "\n", "To fix this, we can create an Inference Pipeline using SageMaker to control the data that goes in and comes out of the endpoint.\n", "\n", "Our inference pipeline will have three components:\n", "\n", - "1. A preprocessing transformer that will transform the input data into the format the model expects.\n", + "1. A preprocessing component that will transform the input data into the format the model expects.\n", "2. The TensorFlow model.\n", - "3. A postprocessing transformer that will transform the output of the model into a human-readable format.\n", + "3. A postprocessing component that will transform the output of the model into a human-readable format.\n", "\n", - " \"Inference\n", + " \"Inference\n", "\n", "We want our endpoint to handle unprocessed data in CSV and JSON format and return the penguin's species. Here is an example of the payload input we want the endpoint to support:\n", "\n", @@ -5367,7 +5304,7 @@ " \"culmen_length_mm\": 48.6,\n", " \"culmen_depth_mm\": 16.0,\n", " \"flipper_length_mm\": 230.0,\n", - " \"body_mass_g\": 5800.0,\n", + " \"body_mass_g\": 5800.0\n", "}\n", "```\n", "\n", @@ -5388,19 +5325,28 @@ "source": [ "### Step 1 - Creating the Preprocessing Script\n", "\n", - "The first component of our inference pipeline will transform the input data into the format the model expects. We'll use the Scikit-Learn transformer we saved when we split and transformed the data. To deploy this component as part of an inference pipeline, we need to write a script that loads the transformer, uses it to modify the input data, and returns the output in the format the TensorFlow model expects.\n", + "The first component of our inference pipeline will transform the input data into the format the model expects.\n", "\n", - "We'll store the scripts of every component in a folder called `inference`:\n" + "We'll use the Scikit-Learn transformer we saved when we split and transformed the data. To deploy this component as part of an inference pipeline, we need to write a script that loads the transformer, uses it to modify the input data, and returns the output in the format the TensorFlow model expects.\n" + ] + }, + { + "cell_type": "markdown", + "id": "7a1de322", + "metadata": {}, + "source": [ + "We'll store the scripts of every component in a folder called `pipeline` and add it to the system path so we can later import it as a module.\n" ] }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 90, "id": "a1f25973", "metadata": {}, "outputs": [], "source": [ - "(CODE_FOLDER / \"pipeline\").mkdir(parents=True, exist_ok=True)" + "(CODE_FOLDER / \"pipeline\").mkdir(parents=True, exist_ok=True)\n", + "sys.path.extend([f\"./{CODE_FOLDER}/pipeline\"])" ] }, { @@ -5413,7 +5359,7 @@ }, { "cell_type": "code", - "execution_count": 209, + "execution_count": 91, "id": "c480ae02", "metadata": { "tags": [ @@ -5425,7 +5371,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting code/pipeline/preprocessing_component.py\n" + "Writing code/pipeline/preprocessing_component.py\n" ] } ], @@ -5544,7 +5490,7 @@ }, { "cell_type": "code", - "execution_count": 210, + "execution_count": 92, "id": "34721e63", "metadata": { "tags": [ @@ -5557,7 +5503,7 @@ "output_type": "stream", "text": [ "\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n", - "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.05s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.06s\u001b[0m\u001b[0m\n" ] } ], @@ -5685,12 +5631,14 @@ "source": [ "### Step 2 - Creating the Postprocessing Script\n", "\n", - "The final component of our inference pipeline will transform the output from the model into a human-readable format. We'll use the Scikit-Learn target transformer we saved when we split and transformed the data. To deploy this component as part of an inference pipeline, we need to write a script that loads the transformer, uses it to modify the output from the model, and returns a human-readable format.\n" + "The final component of our inference pipeline will transform the output from the model into a human-readable format.\n", + "\n", + "We'll use the Scikit-Learn target transformer we saved when we split and transformed the data. To deploy this component as part of an inference pipeline, we need to write a script that loads the transformer, uses it to modify the output from the model, and returns a human-readable format.\n" ] }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 93, "id": "d23798aa", "metadata": { "tags": [ @@ -5702,7 +5650,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting code/pipeline/postprocessing_component.py\n" + "Writing code/pipeline/postprocessing_component.py\n" ] } ], @@ -5791,7 +5739,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 94, "id": "965a6be5", "metadata": { "tags": [ @@ -5860,12 +5808,20 @@ "\n", "We can now create a [PipelineModel](https://sagemaker.readthedocs.io/en/stable/api/inference/pipeline.html#sagemaker.pipeline.PipelineModel) to define our inference pipeline.\n", "\n", - "We'll use the model we generated from the first step of the inference pipeline as the input to the first and last components of the inference pipeline. This `model.tar.gz` file contains the two transformers we need to preprocess and postprocess the data. Let's create a variable with the URI to this file:\n" + "We'll use the model we generated in the Split and Transform step as the input to the first and last components of the inference pipeline. This `model.tar.gz` file contains the two transformers we need to preprocess and postprocess the data.\n" + ] + }, + { + "cell_type": "markdown", + "id": "0cf32c18", + "metadata": {}, + "source": [ + "Let's create a variable with the URI to this file:\n" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 95, "id": "82dafcd0", "metadata": {}, "outputs": [], @@ -5891,7 +5847,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 96, "id": "8c7dda7a", "metadata": {}, "outputs": [], @@ -5903,7 +5859,7 @@ " entry_point=\"preprocessing_component.py\",\n", " source_dir=(CODE_FOLDER / \"pipeline\").as_posix(),\n", " framework_version=\"1.2-1\",\n", - " sagemaker_session=config[\"session\"],\n", + " sagemaker_session=pipeline_session,\n", " role=role,\n", ")" ] @@ -5918,7 +5874,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 97, "id": "6c31090e", "metadata": {}, "outputs": [], @@ -5928,7 +5884,7 @@ " entry_point=\"postprocessing_component.py\",\n", " source_dir=(CODE_FOLDER / \"pipeline\").as_posix(),\n", " framework_version=\"1.2-1\",\n", - " sagemaker_session=config[\"session\"],\n", + " sagemaker_session=pipeline_session,\n", " role=role,\n", ")" ] @@ -5953,7 +5909,7 @@ "pipeline_model = PipelineModel(\n", " name=\"inference-model\",\n", " models=[preprocessing_model, tensorflow_model, postprocessing_model],\n", - " sagemaker_session=config[\"session\"],\n", + " sagemaker_session=pipeline_session,\n", " role=role,\n", ")" ] @@ -6002,7 +5958,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", + "/Users/svpino/dev/ml.school/.venv/lib/python3.10/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", " warnings.warn(\n" ] } @@ -6043,7 +5999,7 @@ "source": [ "### Step 7 - Modifying the Condition Step\n", "\n", - "Since we modified the registration step, we also need to modify the Condition Step to use the new registration:\n" + "Since we modified the Registration Step, we also need to modify the Condition Step to use the new registration:\n" ] }, { @@ -6058,7 +6014,7 @@ "condition_step = ConditionStep(\n", " name=\"check-model-accuracy\",\n", " conditions=[condition],\n", - " if_steps=[register_model_step, deploy_step] if not LOCAL_MODE else [],\n", + " if_steps=[register_model_step, deploy_step],\n", " else_steps=[fail_step],\n", ")" ] @@ -6088,17 +6044,11 @@ "output_type": "stream", "text": [ "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session14-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", + "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session14-pipeline/code/c90fe2477ad62c58fbc0c004cc5ab07f/sourcedir.tar.gz\n", "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/session14-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n", "WARNING:sagemaker.workflow._utils:Popping out 'CertifyForMarketplace' from the pipeline definition since it will be overridden in pipeline execution time.\n", - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session14-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", + "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", + "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session14-pipeline/code/c90fe2477ad62c58fbc0c004cc5ab07f/sourcedir.tar.gz\n", "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/session14-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n" ] }, @@ -6106,12 +6056,12 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session14-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '875206dc-45a4-4fd1-81b8-f188bdcfd4e6',\n", + " 'ResponseMetadata': {'RequestId': '14204982-5c91-4a7d-9a9f-d5ba792bad6c',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '875206dc-45a4-4fd1-81b8-f188bdcfd4e6',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '14204982-5c91-4a7d-9a9f-d5ba792bad6c',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '86',\n", - " 'date': 'Sat, 16 Mar 2024 14:25:28 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 15:53:09 GMT'},\n", " 'RetryAttempts': 0}}" ] }, @@ -6126,12 +6076,12 @@ " parameters=[dataset_location, accuracy_threshold],\n", " steps=[\n", " preprocessing_step,\n", - " tune_model_step if USE_TUNING_STEP else train_model_step,\n", + " train_model_step,\n", " evaluate_model_step,\n", " condition_step,\n", " ],\n", " pipeline_definition_config=pipeline_definition_config,\n", - " sagemaker_session=config[\"session\"],\n", + " sagemaker_session=pipeline_session,\n", ")\n", "\n", "session14_pipeline.upsert(role_arn=role)" @@ -6149,7 +6099,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 121, "id": "3cc966fb-b611-417f-a8b8-0c5d2f95252c", "metadata": { "tags": [] @@ -6164,7 +6114,20 @@ "Torgersen,39.5,17.4,186.0,3800.0,FEMALE\n", "Torgersen,40.3,18.0,195.0,3250.0,FEMALE\n", "\n", - "An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint penguins-endpoint of account 325223348818 not found.\n" + "[\n", + " {\n", + " \"prediction\": \"Adelie\",\n", + " \"confidence\": 0.988331139\n", + " },\n", + " {\n", + " \"prediction\": \"Adelie\",\n", + " \"confidence\": 0.982327223\n", + " },\n", + " {\n", + " \"prediction\": \"Adelie\",\n", + " \"confidence\": 0.955816865\n", + " }\n", + "]\n" ] } ], @@ -6203,7 +6166,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 127, "id": "ce3d33f0", "metadata": {}, "outputs": [ @@ -6211,7 +6174,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint penguins-endpoint of account 325223348818 not found.\n" + "{'prediction': 'Gentoo', 'confidence': 0.987513483}\n" ] } ], @@ -6250,18 +6213,10 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "id": "240aaff2", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint penguins-endpoint of account 325223348818 not found.\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " response = predictor.predict(sample, initial_args={\"Accept\": \"text/csv\"})\n", @@ -6275,9 +6230,9 @@ "id": "81a3b50c", "metadata": {}, "source": [ - "## Session 15 - Using a Custom Inference Script\n", + "## Session 15 - Custom Inference Script\n", "\n", - "Instead of building an inference pipeline, we can also create a custom inference script to control the inference process in the SageMaker endpoint.\n" + "This session creates a custom inference script to control the inference process in the SageMaker endpoint. This is an alternative to creating an inference pipeline to preprocess and postprocess the data that comes in and out of the model.\n" ] }, { @@ -6287,19 +6242,9 @@ "source": [ "### Step 1 - Creating the Inference Script\n", "\n", - "Let's create a script where we'll manage the inference process in the endpoint. We will include this code as part of the model assets to control the inference process on the SageMaker endpoint. SageMaker will automatically call the `handler()` function for every request to the endpoint. Check [How to implement the pre- and/or post-processing handler(s)](https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/deploying_tensorflow_serving.html#how-to-implement-the-pre-and-or-post-processing-handler-s) for more information.\n", + "Let's create a script where we'll manage the inference process in the endpoint.\n", "\n", - "We will store the script in a folder called `inference`:\n" - ] - }, - { - "cell_type": "code", - "execution_count": 177, - "id": "d9bed88f", - "metadata": {}, - "outputs": [], - "source": [ - "(CODE_FOLDER / \"inference\").mkdir(parents=True, exist_ok=True)" + "We'll' include this code as part of the model assets to control the inference process on the SageMaker endpoint. SageMaker will automatically call the `handler()` function for every request to the endpoint. Check [How to implement the pre- and/or post-processing handler(s)](https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/deploying_tensorflow_serving.html#how-to-implement-the-pre-and-or-post-processing-handler-s) for more information.\n" ] }, { @@ -6312,7 +6257,7 @@ }, { "cell_type": "code", - "execution_count": 218, + "execution_count": 114, "id": "97b3cd80", "metadata": { "tags": [ @@ -6324,12 +6269,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting code/inference/inference.py\n" + "Overwriting code/pipeline/inference.py\n" ] } ], "source": [ - "%%writefile {CODE_FOLDER}/inference/inference.py\n", + "%%writefile {CODE_FOLDER}/pipeline/inference.py\n", "#| filename: inference.py\n", "#| code-line-numbers: true\n", "\n", @@ -6443,9 +6388,17 @@ " return json.dumps(result), response_content_type" ] }, + { + "cell_type": "markdown", + "id": "19fbf40d", + "metadata": {}, + "source": [ + "Let's test the script to ensure everything is working as expected:\n" + ] + }, { "cell_type": "code", - "execution_count": 219, + "execution_count": 115, "id": "91786cc7", "metadata": { "tags": [ @@ -6464,23 +6417,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "Keras version: 2.15.0\n", - "8/8 - 0s - loss: 0.8019 - accuracy: 0.4937 - val_loss: 0.8159 - val_accuracy: 0.4314 - 180ms/epoch - 22ms/step\n", - "2/2 [==============================] - 0s 1ms/step\n" + "Keras version: 2.14.0\n", + "8/8 - 0s - loss: 1.3397 - accuracy: 0.3180 - val_loss: 1.2616 - val_accuracy: 0.2941 - 218ms/epoch - 27ms/step\n", + "2/2 [==============================] - 0s 2ms/step\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpsh2svsbz/model/001/assets\n" + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpsd37udrp/model/001/assets\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Validation accuracy: 0.43137254901960786\n", + "Validation accuracy: 0.29411764705882354\n", "Handling endpoint request\n", "Processing input data...\n", "Sending input data to model to make a prediction...\n" @@ -6498,135 +6451,195 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[31mF\u001b[0m\n", - "============================================= FAILURES =============================================\n", - "\u001b[31m\u001b[1m______________________________________________ test_x ______________________________________________\u001b[0m\n", - "\n", - "directory = PosixPath('/var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpsh2svsbz')\n", - "\n", - " \u001b[94mdef\u001b[39;49;00m \u001b[92mtest_x\u001b[39;49;00m(directory):\u001b[90m\u001b[39;49;00m\n", - " \u001b[90m\u001b[39;49;00m\n", - " payload2 = json.dumps([{\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33misland\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[33m\"\u001b[39;49;00m\u001b[33mBiscoe\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mculmen_length_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m48.6\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mculmen_depth_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m16.0\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mflipper_length_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m230.0\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mbody_mass_g\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m5800\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " }, {\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33misland\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[33m\"\u001b[39;49;00m\u001b[33mBiscoe\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mculmen_length_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m48.6\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mculmen_depth_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m16.0\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mflipper_length_mm\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m230.0\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " \u001b[33m\"\u001b[39;49;00m\u001b[33mbody_mass_g\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m: \u001b[94m5800\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " }]).encode(\u001b[33m\"\u001b[39;49;00m\u001b[33mutf-8\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m)\u001b[90m\u001b[39;49;00m\n", - " \u001b[90m\u001b[39;49;00m\n", - "> response = handler(\u001b[90m\u001b[39;49;00m\n", - " data=payload2,\u001b[90m\u001b[39;49;00m\n", - " context=\u001b[94mNone\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " directory=directory / \u001b[33m\"\u001b[39;49;00m\u001b[33mmodel\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m,\u001b[90m\u001b[39;49;00m\n", - " )\u001b[90m\u001b[39;49;00m\n", - "\n", - "\u001b[1m\u001b[31m/var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/ipykernel_9381/2527210736.py\u001b[0m:116: \n", - "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n", - "\u001b[1m\u001b[31mcode/inference/inference.py\u001b[0m:24: in handler\n", - " output = _predict(processed_input, context, directory) \u001b[94mif\u001b[39;49;00m processed_input \u001b[94melse\u001b[39;49;00m \u001b[94mNone\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n", - "\u001b[1m\u001b[31mcode/inference/inference.py\u001b[0m:73: in _predict\n", - " predictions = model.predict(np.array([instance]))\u001b[90m\u001b[39;49;00m\n", - "\u001b[1m\u001b[31m../.venv/lib/python3.9/site-packages/keras/src/utils/traceback_utils.py\u001b[0m:70: in error_handler\n", - " \u001b[94mraise\u001b[39;49;00m e.with_traceback(filtered_tb) \u001b[94mfrom\u001b[39;49;00m \u001b[94mNone\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n", - "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n", - "\n", - "iterator = \n", - "\n", - " \u001b[94mdef\u001b[39;49;00m \u001b[92mtf__predict_function\u001b[39;49;00m(iterator):\u001b[90m\u001b[39;49;00m\n", - " \u001b[90m \u001b[39;49;00m\u001b[33m\"\"\"Runs an evaluation execution with a single step.\"\"\"\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n", - " \u001b[94mwith\u001b[39;49;00m ag__.FunctionScope(\u001b[33m'\u001b[39;49;00m\u001b[33mpredict_function\u001b[39;49;00m\u001b[33m'\u001b[39;49;00m, \u001b[33m'\u001b[39;49;00m\u001b[33mfscope\u001b[39;49;00m\u001b[33m'\u001b[39;49;00m, ag__.ConversionOptions(recursive=\u001b[94mTrue\u001b[39;49;00m, user_requested=\u001b[94mTrue\u001b[39;49;00m, optional_features=(), internal_convert_user_code=\u001b[94mTrue\u001b[39;49;00m)) \u001b[94mas\u001b[39;49;00m fscope:\u001b[90m\u001b[39;49;00m\n", - " do_return = \u001b[94mFalse\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n", - " retval_ = ag__.UndefinedReturnValue()\u001b[90m\u001b[39;49;00m\n", - " \u001b[94mtry\u001b[39;49;00m:\u001b[90m\u001b[39;49;00m\n", - " do_return = \u001b[94mTrue\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n", - "> retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(\u001b[96mself\u001b[39;49;00m), ag__.ld(iterator)), \u001b[94mNone\u001b[39;49;00m, fscope)\u001b[90m\u001b[39;49;00m\n", - "\u001b[1m\u001b[31mE ValueError: in user code:\u001b[0m\n", - "\u001b[1m\u001b[31mE \u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/engine/training.py\", line 2440, in predict_function *\u001b[0m\n", - "\u001b[1m\u001b[31mE return step_function(self, iterator)\u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/engine/training.py\", line 2425, in step_function **\u001b[0m\n", - "\u001b[1m\u001b[31mE outputs = model.distribute_strategy.run(run_step, args=(data,))\u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/engine/training.py\", line 2413, in run_step **\u001b[0m\n", - "\u001b[1m\u001b[31mE outputs = model.predict_step(data)\u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/engine/training.py\", line 2381, in predict_step\u001b[0m\n", - "\u001b[1m\u001b[31mE return self(x, training=False)\u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/utils/traceback_utils.py\", line 70, in error_handler\u001b[0m\n", - "\u001b[1m\u001b[31mE raise e.with_traceback(filtered_tb) from None\u001b[0m\n", - "\u001b[1m\u001b[31mE File \"/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/keras/src/engine/input_spec.py\", line 298, in assert_input_compatibility\u001b[0m\n", - "\u001b[1m\u001b[31mE raise ValueError(\u001b[0m\n", - "\u001b[1m\u001b[31mE \u001b[0m\n", - "\u001b[1m\u001b[31mE ValueError: Input 0 of layer \"sequential_58\" is incompatible with the layer: expected shape=(None, 7), found shape=(None, 2, 7)\u001b[0m\n", - "\n", - "\u001b[1m\u001b[31m/var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/__autograph_generated_file2guvnyv0.py\u001b[0m:15: ValueError\n", - "---------------------------------------- Captured log setup ----------------------------------------\n", - "\u001b[33mWARNING \u001b[0m absl:optimizer.py:70 At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n", - "\u001b[32mINFO \u001b[0m tensorflow:builder_impl.py:801 Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpsh2svsbz/model/001/assets\n", - "---------------------------------------- Captured log call -----------------------------------------\n", - "\u001b[33mWARNING \u001b[0m absl:optimizer.py:70 At this time, the v2.11+ optimizer `tf.keras.optimizers.RestoredOptimizer` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.RestoredOptimizer`.\n", - "\u001b[33mWARNING \u001b[0m absl:optimizer.py:70 At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n", - "\u001b[36m\u001b[1m===================================== short test summary info ======================================\u001b[0m\n", - "\u001b[31mFAILED\u001b[0m t_f22f2adb06a64525be21523eb7b7cd5e.py::\u001b[1mtest_x\u001b[0m - ValueError: in user code:\n", - "\u001b[31m\u001b[31m\u001b[1m1 failed\u001b[0m\u001b[31m in 0.56s\u001b[0m\u001b[0m\n" + "1/1 [==============================] - 0s 25ms/step\n", + "Response: {'predictions': [[0.40967607498168945, 0.4577697217464447, 0.13255421817302704]]}\n", + "Processing prediction received from the model...\n", + "HERE {'predictions': [[0.40967607498168945, 0.4577697217464447, 0.13255421817302704]]}\n", + "{'prediction': 'Chinstrap', 'confidence': 0.4577697217464447}\n", + "\u001b[32m.\u001b[0m" ] }, { - "ename": "Error", - "evalue": "ipytest failed with exit_code 1", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[219], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mget_ipython\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_cell_magic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mipytest\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m-s\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m#| code-fold: true\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m#| output: false\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mimport os\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mimport shutil\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mimport tarfile\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mimport pytest\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mimport tempfile\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mfrom processing.script import preprocess\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mfrom training.script import train\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mfrom inference.inference import handler\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m@pytest.fixture(scope=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfunction\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, autouse=False)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mdef directory():\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m directory = tempfile.mkdtemp()\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m input_directory = Path(directory) / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minput\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m input_directory.mkdir(parents=True, exist_ok=True)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m shutil.copy2(DATA_FILEPATH, input_directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdata.csv\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m directory = Path(directory)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m preprocess(base_directory=directory)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m train(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m model_directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m train_path=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtrain\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m validation_path=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mvalidation\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m pipeline_path=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m experiment=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m epochs=1,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m # After training a model, we need to prepare a package just like\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m # SageMaker would. This package is what the evaluation script is\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m # expecting as an input.\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m with tarfile.open(directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel.tar.gz\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mw:gz\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m) as tar:\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m tar.add(directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m001\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, arcname=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m001\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m yield directory\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m shutil.rmtree(directory)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m@pytest.fixture(scope=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfunction\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, autouse=False)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mdef payload():\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m return json.dumps(\u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43misland\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBiscoe\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 48.6,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_depth_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 16.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mflipper_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 230.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbody_mass_g\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 5800,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m }).encode(\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mutf-8\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# def test_handler_response_contains_prediction_and_confidence(directory, payload):\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = handler(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# data=payload,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# context=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = json.loads(response[0])\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# assert \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprediction\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m in response\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# assert \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mconfidence\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m in response\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# def test_handler_response_includes_content_type(directory, payload):\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = handler(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# data=payload,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# context=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# assert response[1] == \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mapplication/json\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# def test_handler_response_prediction_is_categorical(directory, payload):\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = handler(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# data=payload,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# context=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = json.loads(response[0])\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# assert response[\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprediction\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m] in [\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mAdelie\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mGentoo\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mChinstrap\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m]\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# def test_handler_deals_with_an_invalid_payload(directory):\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = handler(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# data=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minvalid payload\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# context=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# response = json.loads(response[0])\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m# assert response[\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprediction\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m] is None\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43mdef test_x(directory):\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m payload2 = json.dumps([\u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43misland\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBiscoe\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 48.6,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_depth_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 16.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mflipper_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 230.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbody_mass_g\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 5800,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m }, \u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43misland\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBiscoe\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 48.6,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mculmen_depth_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 16.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mflipper_length_mm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 230.0,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbody_mass_g\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m: 5800,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m }]).encode(\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mutf-8\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m response = handler(\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m data=payload2,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m context=None,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m directory=directory / \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m )\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m print(response)\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/dev/ml.school/.venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2517\u001b[0m, in \u001b[0;36mInteractiveShell.run_cell_magic\u001b[0;34m(self, magic_name, line, cell)\u001b[0m\n\u001b[1;32m 2515\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuiltin_trap:\n\u001b[1;32m 2516\u001b[0m args \u001b[38;5;241m=\u001b[39m (magic_arg_s, cell)\n\u001b[0;32m-> 2517\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2519\u001b[0m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[1;32m 2520\u001b[0m \u001b[38;5;66;03m# when using magics with decorator @output_can_be_silenced\u001b[39;00m\n\u001b[1;32m 2521\u001b[0m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[1;32m 2522\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic\u001b[38;5;241m.\u001b[39mMAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n", - "File \u001b[0;32m~/dev/ml.school/.venv/lib/python3.9/site-packages/ipytest/_impl.py:162\u001b[0m, in \u001b[0;36mpytest_magic\u001b[0;34m(line, cell, module)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 155\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe ipytest magic cannot evaluate the cell. Most likely you \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 156\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mare running a modified ipython version. Consider using \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 157\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`ipytest.run` and `ipytest.clean` directly.\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 158\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m--> 162\u001b[0m \u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mrun_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mrun_kwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/dev/ml.school/.venv/lib/python3.9/site-packages/ipytest/_impl.py:85\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(module, plugins, run_in_thread, raise_on_error, addopts, defopts, display_columns, *args)\u001b[0m\n\u001b[1;32m 82\u001b[0m ipytest\u001b[38;5;241m.\u001b[39mexit_code \u001b[38;5;241m=\u001b[39m exit_code\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m raise_on_error \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m exit_code \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m---> 85\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m Error(exit_code)\n\u001b[1;32m 87\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m exit_code\n", - "\u001b[0;31mError\u001b[0m: ipytest failed with exit_code 1" + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" ] - } - ], - "source": [ - "%%ipytest -s\n", - "#| code-fold: true\n", - "\n", - "import os\n", - "import shutil\n", - "import tarfile\n", - "import pytest\n", - "import tempfile\n", - "\n", - "from processing.script import preprocess\n", - "from training.script import train\n", - "from inference.inference import handler\n", - "\n", - "\n", - "@pytest.fixture(scope=\"function\", autouse=False)\n", - "def directory():\n", - " directory = tempfile.mkdtemp()\n", - " input_directory = Path(directory) / \"input\"\n", - " input_directory.mkdir(parents=True, exist_ok=True)\n", - " shutil.copy2(DATA_FILEPATH, input_directory / \"data.csv\")\n", - "\n", - " directory = Path(directory)\n", - "\n", - " preprocess(base_directory=directory)\n", - "\n", - " train(\n", - " model_directory=directory / \"model\",\n", - " train_path=directory / \"train\",\n", - " validation_path=directory / \"validation\",\n", - " pipeline_path=directory / \"model\",\n", - " experiment=None,\n", - " epochs=1,\n", - " )\n", - "\n", - " # After training a model, we need to prepare a package just like\n", - " # SageMaker would. This package is what the evaluation script is\n", + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Keras version: 2.14.0\n", + "8/8 - 0s - loss: 1.3897 - accuracy: 0.1967 - val_loss: 1.2680 - val_accuracy: 0.2157 - 212ms/epoch - 26ms/step\n", + "2/2 [==============================] - 0s 1ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmp1rvwan40/model/001/assets\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validation accuracy: 0.21568627450980393\n", + "Handling endpoint request\n", + "Processing input data...\n", + "Sending input data to model to make a prediction...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.RestoredOptimizer` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.RestoredOptimizer`.\n", + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1/1 [==============================] - 0s 29ms/step\n", + "Response: {'predictions': [[0.00972421932965517, 0.8837649822235107, 0.10651086270809174]]}\n", + "Processing prediction received from the model...\n", + "HERE {'predictions': [[0.00972421932965517, 0.8837649822235107, 0.10651086270809174]]}\n", + "{'prediction': 'Chinstrap', 'confidence': 0.8837649822235107}\n", + "\u001b[32m.\u001b[0m" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Keras version: 2.14.0\n", + "8/8 - 0s - loss: 0.9700 - accuracy: 0.5063 - val_loss: 0.9822 - val_accuracy: 0.5098 - 215ms/epoch - 27ms/step\n", + "2/2 [==============================] - 0s 2ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmp3msq8crf/model/001/assets\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validation accuracy: 0.5098039215686274\n", + "Handling endpoint request\n", + "Processing input data...\n", + "Sending input data to model to make a prediction...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.RestoredOptimizer` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.RestoredOptimizer`.\n", + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1/1 [==============================] - 0s 29ms/step\n", + "Response: {'predictions': [[0.26935648918151855, 0.05234304443001747, 0.6783004999160767]]}\n", + "Processing prediction received from the model...\n", + "HERE {'predictions': [[0.26935648918151855, 0.05234304443001747, 0.6783004999160767]]}\n", + "{'prediction': 'Gentoo', 'confidence': 0.6783004999160767}\n", + "\u001b[32m.\u001b[0m" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Keras version: 2.14.0\n", + "8/8 - 0s - loss: 1.4065 - accuracy: 0.4059 - val_loss: 1.4185 - val_accuracy: 0.3725 - 216ms/epoch - 27ms/step\n", + "2/2 [==============================] - 0s 1ms/step\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpscclaeuh/model/001/assets\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validation accuracy: 0.37254901960784315\n", + "Handling endpoint request\n", + "Processing input data...\n", + "There was an error processing the input data. Expecting value: line 1 column 1 (char 0)\n", + "Processing prediction received from the model...\n", + "{'prediction': None}\n", + "\u001b[32m.\u001b[0m\n", + "\u001b[32m\u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 2.31s\u001b[0m\u001b[0m\n" + ] + } + ], + "source": [ + "%%ipytest -s\n", + "#| code-fold: true\n", + "\n", + "import os\n", + "import shutil\n", + "import tarfile\n", + "import pytest\n", + "import tempfile\n", + "\n", + "from processing.script import preprocess\n", + "from training.script import train\n", + "from pipeline.inference import handler\n", + "\n", + "\n", + "@pytest.fixture(scope=\"function\", autouse=False)\n", + "def directory():\n", + " directory = tempfile.mkdtemp()\n", + " input_directory = Path(directory) / \"input\"\n", + " input_directory.mkdir(parents=True, exist_ok=True)\n", + " shutil.copy2(DATA_FILEPATH, input_directory / \"data.csv\")\n", + "\n", + " directory = Path(directory)\n", + "\n", + " preprocess(base_directory=directory)\n", + "\n", + " train(\n", + " model_directory=directory / \"model\",\n", + " train_path=directory / \"train\",\n", + " validation_path=directory / \"validation\",\n", + " pipeline_path=directory / \"model\",\n", + " experiment=None,\n", + " epochs=1,\n", + " )\n", + "\n", + " # After training a model, we need to prepare a package just like\n", + " # SageMaker would. This package is what the evaluation script is\n", " # expecting as an input.\n", " with tarfile.open(directory / \"model.tar.gz\", \"w:gz\") as tar:\n", " tar.add(directory / \"model\" / \"001\", arcname=\"001\")\n", @@ -6691,9 +6704,48 @@ " assert response[\"prediction\"] is None" ] }, + { + "cell_type": "markdown", + "id": "57430168", + "metadata": {}, + "source": [ + "### Step 2 - Creating the Model\n", + "\n", + "We can now create a new [TensorFlowModel](https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/sagemaker.tensorflow.html#tensorflow-serving-model) including the `inference.py` file.\n", + "\n", + "SageMaker triggers a repack operation whenever we specify the `source_dir` attribute in a model. We want that attribute to point to the local folder containing the `inference.py` file. SageMaker will automatically modify the original `model.tar.gz` package to include a `/code` folder containing the file.\n", + "\n", + "Since we need access to Scikit-Learn in our script, we can include a `requirements.txt` file in the same location where the `inference.py` script is, and SageMaker will install everything in it.\n", + "\n", + "To repack the model assets, SageMaker will automatically include a new step in the pipeline right before registering the model.\n", + "\n", + "Here is what the new `model.tar.gz` package will look like:\n", + "\n", + "```\n", + "model/\n", + " |--[model_version_number]\n", + " |--assets/\n", + " |--variables/\n", + " |--saved_model.pb\n", + " |--features.joblib\n", + " |--target.joblib\n", + "code/\n", + " |--inference.py\n", + " |--requirements.txt\n", + "```\n" + ] + }, + { + "cell_type": "markdown", + "id": "7d3cfdd3", + "metadata": {}, + "source": [ + "Let's create a `requirements.txt` file with all the libraries we want SageMaker to install in the inference container.\n" + ] + }, { "cell_type": "code", - "execution_count": 180, + "execution_count": 117, "id": "603cb8f5", "metadata": { "tags": [ @@ -6705,12 +6757,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting code/inference/requirements.txt\n" + "Overwriting code/pipeline/requirements.txt\n" ] } ], "source": [ - "%%writefile {CODE_FOLDER}/inference/requirements.txt\n", + "%%writefile {CODE_FOLDER}/pipeline/requirements.txt\n", "#| filename: requirements.txt\n", "#| code-line-numbers: true\n", "\n", @@ -6721,41 +6773,24 @@ }, { "cell_type": "markdown", - "id": "57430168", + "id": "8f9c7a0d", "metadata": {}, "source": [ - "We can now create a new [TensorFlowModel](https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/sagemaker.tensorflow.html#tensorflow-serving-model). We must also ensure SageMaker repackages the model assets to include the `inference.py` file.\n", - "\n", - "SageMaker triggers a repack whenever we specify the `source_dir` attribute. We want that attribute to point to the local folder containing the `inference.py` file. SageMaker will automatically modify the original `model.tar.gz` package to include a `/code` folder containing the file. Since we need access to Scikit-Learn in our script, we can include a `requirements.txt` file in the same `/code` folder, and SageMaker will install everything in it. To repack the model assets, SageMaker will automatically include a new step in the pipeline right before registering the model.\n", - "\n", - "Here is what the new `model.tar.gz` package will look like:\n", - "\n", - "```\n", - "model/\n", - " |--[model_version_number]\n", - " |--assets/\n", - " |--variables/\n", - " |--saved_model.pb\n", - " |--features.joblib\n", - " |--target.joblib\n", - "code/\n", - " |--inference.py\n", - " |--requirements.txt\n", - "```\n" + "We can now create the model using the `inference.py` script.\n" ] }, { "cell_type": "code", - "execution_count": 181, + "execution_count": 118, "id": "b5015c75", "metadata": {}, "outputs": [], "source": [ "custom_tensorflow_model = TensorFlowModel(\n", " name=\"penguins\",\n", - " model_data=model_assets,\n", + " model_data=train_model_step.properties.ModelArtifacts.S3ModelArtifacts,\n", " entry_point=\"inference.py\",\n", - " source_dir=(CODE_FOLDER / \"inference\").as_posix(),\n", + " source_dir=(CODE_FOLDER / \"pipeline\").as_posix(),\n", " framework_version=config[\"framework_version\"],\n", " sagemaker_session=pipeline_session,\n", " role=role,\n", @@ -6767,14 +6802,22 @@ "id": "a98b5c0a", "metadata": {}, "source": [ - "### Step X - Registering the Model\n", + "### Step 3 - Registering the Model\n", "\n", "We'll modify the registration step to register the custom model in the Model Registry.\n" ] }, + { + "cell_type": "markdown", + "id": "f29084d1", + "metadata": {}, + "source": [ + "First, let's define a new group where we'll register the model using the custom `inference.py` script.\n" + ] + }, { "cell_type": "code", - "execution_count": 182, + "execution_count": 119, "id": "7ee3cdb6", "metadata": {}, "outputs": [], @@ -6782,9 +6825,17 @@ "CUSTOM_MODEL_PACKAGE_GROUP = \"custom-penguins\"" ] }, + { + "cell_type": "markdown", + "id": "a8fb092d", + "metadata": {}, + "source": [ + "We can now create the Registration Step using the new model.\n" + ] + }, { "cell_type": "code", - "execution_count": 183, + "execution_count": 120, "id": "21fb3e2c", "metadata": { "tags": [ @@ -6797,7 +6848,7 @@ "output_type": "stream", "text": [ "INFO:sagemaker.tensorflow.model:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", + "/Users/svpino/dev/ml.school/.venv/lib/python3.10/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", " warnings.warn(\n" ] } @@ -6811,9 +6862,19 @@ ")" ] }, + { + "cell_type": "markdown", + "id": "6b9293b0", + "metadata": {}, + "source": [ + "### Step 4 - Modifying the Deploy Step\n", + "\n", + "Let's now modify the [LambdaStep](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.lambda_step.LambdaStep) to use the updated Registration Step.\n" + ] + }, { "cell_type": "code", - "execution_count": 184, + "execution_count": 122, "id": "9e8162b7", "metadata": {}, "outputs": [], @@ -6821,9 +6882,19 @@ "deploy_step = create_deployment_step(register_model_step)" ] }, + { + "cell_type": "markdown", + "id": "cd1812e7", + "metadata": {}, + "source": [ + "### Step 5 - Modifying the Condition Step\n", + "\n", + "Since we modified the Registration Step, we also need to modify the Condition Step to use the new registration:\n" + ] + }, { "cell_type": "code", - "execution_count": 185, + "execution_count": 123, "id": "849b379f", "metadata": {}, "outputs": [], @@ -6831,7 +6902,7 @@ "condition_step = ConditionStep(\n", " name=\"check-model-accuracy\",\n", " conditions=[condition],\n", - " if_steps=[register_model_step, deploy_step] if not LOCAL_MODE else [],\n", + " if_steps=[register_model_step, deploy_step],\n", " else_steps=[fail_step],\n", ")" ] @@ -6841,14 +6912,14 @@ "id": "671a5efb", "metadata": {}, "source": [ - "### Step X - Creating the Pipeline\n", + "### Step 6 - Creating the Pipeline\n", "\n", "We can now define the SageMaker Pipeline and submit its definition to the SageMaker Pipelines service to create the pipeline if it doesn't exist or update it if it does.\n" ] }, { "cell_type": "code", - "execution_count": 186, + "execution_count": 124, "id": "f64921ee", "metadata": { "tags": [ @@ -6861,11 +6932,13 @@ "output_type": "stream", "text": [ "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session15-pipeline/code/1036e1cb7bc2e206717edc7cc5ef2278/sourcedir.tar.gz\n", + "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session15-pipeline/code/c90fe2477ad62c58fbc0c004cc5ab07f/sourcedir.tar.gz\n", "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/session15-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n", + "/Users/svpino/dev/ml.school/.venv/lib/python3.10/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", + " warnings.warn(\n", "WARNING:sagemaker.workflow._utils:Popping out 'CertifyForMarketplace' from the pipeline definition since it will be overridden in pipeline execution time.\n", "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session15-pipeline/code/1036e1cb7bc2e206717edc7cc5ef2278/sourcedir.tar.gz\n", + "INFO:sagemaker.processing:Uploaded None to s3://mlschool/session15-pipeline/code/c90fe2477ad62c58fbc0c004cc5ab07f/sourcedir.tar.gz\n", "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/session15-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n" ] }, @@ -6873,16 +6946,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session15-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'd8e5d499-edad-46c1-84bb-1480c8e073b2',\n", + " 'ResponseMetadata': {'RequestId': '016ce20b-84bf-41be-b0c1-3c2f3c2b769a',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'd8e5d499-edad-46c1-84bb-1480c8e073b2',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '016ce20b-84bf-41be-b0c1-3c2f3c2b769a',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '86',\n", - " 'date': 'Sat, 16 Mar 2024 23:12:47 GMT'},\n", + " 'date': 'Thu, 28 Mar 2024 16:14:05 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 186, + "execution_count": 124, "metadata": {}, "output_type": "execute_result" } @@ -6893,12 +6966,12 @@ " parameters=[dataset_location, accuracy_threshold],\n", " steps=[\n", " preprocessing_step,\n", - " tune_model_step if USE_TUNING_STEP else train_model_step,\n", + " train_model_step,\n", " evaluate_model_step,\n", " condition_step,\n", " ],\n", " pipeline_definition_config=pipeline_definition_config,\n", - " sagemaker_session=config[\"session\"],\n", + " sagemaker_session=pipeline_session,\n", ")\n", "\n", "session15_pipeline.upsert(role_arn=role)" @@ -6909,14 +6982,14 @@ "id": "0a6f02a4", "metadata": {}, "source": [ - "### Step X - Testing the Endpoint\n", + "### Step 7 - Testing the Endpoint\n", "\n", "Let's test the endpoint to make sure it works.\n" ] }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 128, "id": "1d63ce59", "metadata": {}, "outputs": [ @@ -6924,7 +6997,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'prediction': 'Adelie', 'confidence': 0.505610049}\n" + "{'prediction': 'Adelie', 'confidence': 0.629927337}\n" ] } ], @@ -6980,7 +7053,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": null, "id": "f4747fc7", "metadata": {}, "outputs": [], @@ -7010,23 +7083,14 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": null, "id": "3fc728fa", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:Defaulting to the only supported framework/algorithm version: .\n", - "INFO:sagemaker.image_uris:Ignoring unnecessary instance type: None.\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.workflow.quality_check_step import (\n", " QualityCheckStep,\n", @@ -7070,7 +7134,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": null, "id": "2d5d8133", "metadata": {}, "outputs": [], @@ -7111,23 +7175,14 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": null, "id": "fc5c4325", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/svpino/dev/ml.school/.venv/lib/python3.9/site-packages/sagemaker/workflow/pipeline_context.py:332: UserWarning: Running within a PipelineSession, there will be No Wait, No Logs, and No Job being started.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "register_model_step = create_registration_step(\n", " pipeline_model,\n", @@ -7151,7 +7206,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": null, "id": "be9d6de7", "metadata": {}, "outputs": [], @@ -7176,45 +7231,14 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "id": "fb9b8d1e", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/chapter14-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", - "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/chapter14-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n", - "WARNING:sagemaker.workflow._utils:Popping out 'CertifyForMarketplace' from the pipeline definition since it will be overridden in pipeline execution time.\n", - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/chapter14-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", - "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/chapter14-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n" - ] - }, - { - "data": { - "text/plain": [ - "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/chapter14-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'e552437b-1cc9-4cb8-a830-c963fd08d21b',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'e552437b-1cc9-4cb8-a830-c963fd08d21b',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '86',\n", - " 'date': 'Tue, 12 Mar 2024 20:31:51 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 107, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "session16_pipeline = Pipeline(\n", " name=\"session16-pipeline\",\n", @@ -7253,46 +7277,10 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": null, "id": "c2b95d03", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"name\": \"island\",\n", - " \"inferred_type\": \"String\",\n", - " \"string_statistics\": {\n", - " \"common\": {\n", - " \"num_present\": 232,\n", - " \"num_missing\": 0\n", - " },\n", - " \"distinct_count\": 3.0,\n", - " \"distribution\": {\n", - " \"categorical\": {\n", - " \"buckets\": [\n", - " {\n", - " \"value\": \"Dream\",\n", - " \"count\": 84\n", - " },\n", - " {\n", - " \"value\": \"Torgersen\",\n", - " \"count\": 33\n", - " },\n", - " {\n", - " \"value\": \"Biscoe\",\n", - " \"count\": 115\n", - " }\n", - " ]\n", - " }\n", - " }\n", - " }\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " response = json.loads(\n", @@ -7313,90 +7301,10 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": null, "id": "63908598", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"version\": 0.0,\n", - " \"features\": [\n", - " {\n", - " \"name\": \"island\",\n", - " \"inferred_type\": \"String\",\n", - " \"completeness\": 1.0,\n", - " \"string_constraints\": {\n", - " \"domains\": [\n", - " \"Dream\",\n", - " \"Torgersen\",\n", - " \"Biscoe\"\n", - " ]\n", - " }\n", - " },\n", - " {\n", - " \"name\": \"culmen_length_mm\",\n", - " \"inferred_type\": \"Fractional\",\n", - " \"completeness\": 1.0,\n", - " \"num_constraints\": {\n", - " \"is_non_negative\": true\n", - " }\n", - " },\n", - " {\n", - " \"name\": \"culmen_depth_mm\",\n", - " \"inferred_type\": \"Fractional\",\n", - " \"completeness\": 1.0,\n", - " \"num_constraints\": {\n", - " \"is_non_negative\": true\n", - " }\n", - " },\n", - " {\n", - " \"name\": \"flipper_length_mm\",\n", - " \"inferred_type\": \"Fractional\",\n", - " \"completeness\": 1.0,\n", - " \"num_constraints\": {\n", - " \"is_non_negative\": true\n", - " }\n", - " },\n", - " {\n", - " \"name\": \"body_mass_g\",\n", - " \"inferred_type\": \"Fractional\",\n", - " \"completeness\": 1.0,\n", - " \"num_constraints\": {\n", - " \"is_non_negative\": true\n", - " }\n", - " },\n", - " {\n", - " \"name\": \"sex\",\n", - " \"inferred_type\": \"String\",\n", - " \"completeness\": 1.0,\n", - " \"string_constraints\": {\n", - " \"domains\": [\n", - " \"FEMALE\",\n", - " \"MALE\"\n", - " ]\n", - " }\n", - " }\n", - " ],\n", - " \"monitoring_config\": {\n", - " \"evaluate_constraints\": \"Enabled\",\n", - " \"emit_metrics\": \"Enabled\",\n", - " \"datatype_check_threshold\": 1.0,\n", - " \"domain_content_threshold\": 1.0,\n", - " \"distribution_constraints\": {\n", - " \"perform_comparison\": \"Enabled\",\n", - " \"comparison_threshold\": 0.1,\n", - " \"comparison_method\": \"Robust\",\n", - " \"categorical_comparison_threshold\": 0.1,\n", - " \"categorical_drift_method\": \"LInfinity\"\n", - " }\n", - " }\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " response = json.loads(\n", @@ -7433,7 +7341,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": null, "id": "69e115c3", "metadata": {}, "outputs": [], @@ -7453,7 +7361,7 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": null, "id": "f93f2751", "metadata": { "tags": [ @@ -7484,7 +7392,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": null, "id": "2a530d12", "metadata": {}, "outputs": [], @@ -7518,7 +7426,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": null, "id": "653c6ec8", "metadata": { "tags": [ @@ -7576,23 +7484,14 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": null, "id": "b50a9ed5", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:Defaulting to the only supported framework/algorithm version: .\n", - "INFO:sagemaker.image_uris:Ignoring unnecessary instance type: None.\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.workflow.quality_check_step import ModelQualityCheckConfig\n", "\n", @@ -7638,7 +7537,7 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "id": "3aecc022", "metadata": {}, "outputs": [], @@ -7678,7 +7577,7 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": null, "id": "20154a1a", "metadata": { "tags": [ @@ -7709,7 +7608,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": null, "id": "cd84e567", "metadata": {}, "outputs": [], @@ -7743,45 +7642,14 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": null, "id": "c244e206", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/chapter15-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", - "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/chapter15-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n", - "WARNING:sagemaker.workflow._utils:Popping out 'CertifyForMarketplace' from the pipeline definition since it will be overridden in pipeline execution time.\n", - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", - "INFO:sagemaker.processing:Uploaded None to s3://mlschool/chapter15-pipeline/code/31b1b82156c042a496005fd6f4fe8426/sourcedir.tar.gz\n", - "INFO:sagemaker.processing:runproc.sh uploaded to s3://mlschool/chapter15-pipeline/code/f3b7867d7495763812a03744135acb08/runproc.sh\n" - ] - }, - { - "data": { - "text/plain": [ - "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/chapter15-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'd2b1ed8f-be39-492d-9e12-2a7556288880',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'd2b1ed8f-be39-492d-9e12-2a7556288880',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '86',\n", - " 'date': 'Tue, 12 Mar 2024 20:31:56 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 118, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "session17_pipeline = Pipeline(\n", " name=\"session17-pipeline\",\n", @@ -7812,46 +7680,10 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": null, "id": "dc31aa28", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"version\": 0.0,\n", - " \"multiclass_classification_constraints\": {\n", - " \"accuracy\": {\n", - " \"threshold\": 0.86,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " },\n", - " \"weighted_recall\": {\n", - " \"threshold\": 0.8599999999999999,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " },\n", - " \"weighted_precision\": {\n", - " \"threshold\": 0.8872222222222221,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " },\n", - " \"weighted_f0_5\": {\n", - " \"threshold\": 0.8424908039936941,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " },\n", - " \"weighted_f1\": {\n", - " \"threshold\": 0.8298461538461538,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " },\n", - " \"weighted_f2\": {\n", - " \"threshold\": 0.8430569155446755,\n", - " \"comparison_operator\": \"LessThanThreshold\"\n", - " }\n", - " }\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " response = json.loads(\n", @@ -7888,7 +7720,7 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": null, "id": "57cc8903", "metadata": {}, "outputs": [], @@ -7947,7 +7779,7 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": null, "id": "4966c9c2", "metadata": { "tags": [ @@ -7974,7 +7806,7 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": null, "id": "cea757af", "metadata": { "tags": [ @@ -8028,40 +7860,10 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": null, "id": "caee992c", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File: s3://mlschool/penguins/monitoring/data-capture/penguins-endpoint/AllTraffic/2024/03/12/20/36-48-578-57ec2dac-a3e2-40c5-89f3-b324d87c5578.jsonl\n", - "{\n", - " \"captureData\": {\n", - " \"endpointInput\": {\n", - " \"observedContentType\": \"text/csv\",\n", - " \"mode\": \"INPUT\",\n", - " \"data\": \"Torgersen,39.1,18.7,181.0,3750.0,MALE\",\n", - " \"encoding\": \"CSV\"\n", - " },\n", - " \"endpointOutput\": {\n", - " \"observedContentType\": \"text/csv; charset=utf-8\",\n", - " \"mode\": \"OUTPUT\",\n", - " \"data\": \"Adelie,0.977324724\\n\",\n", - " \"encoding\": \"CSV\"\n", - " }\n", - " },\n", - " \"eventMetadata\": {\n", - " \"eventId\": \"f0edf9d2-d40d-4f1e-94a6-c0329f2e70cc\",\n", - " \"inferenceId\": \"0\",\n", - " \"inferenceTime\": \"2024-03-12T20:36:48Z\"\n", - " },\n", - " \"eventVersion\": \"0\"\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "files = S3Downloader.list(DATA_CAPTURE_DESTINATION)\n", "if len(files):\n", @@ -8086,7 +7888,7 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": null, "id": "7b48cd49", "metadata": {}, "outputs": [], @@ -8106,22 +7908,14 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": null, "id": "0114a817", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Overwriting code/monitoring/data_quality_preprocessor.py\n" - ] - } - ], + "outputs": [], "source": [ "%%writefile {CODE_FOLDER}/monitoring/{DATA_QUALITY_PREPROCESSOR}\n", "#| filename: data_quality_preprocessor.py\n", @@ -8147,22 +7941,14 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": null, "id": "21240214", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials\n" - ] - } - ], + "outputs": [], "source": [ "bucket = boto3.Session().resource(\"s3\").Bucket(config[\"session\"].default_bucket())\n", "prefix = \"penguins/monitoring\"\n", @@ -8186,19 +7972,10 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": null, "id": "b9df3d16", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:Defaulting to the only supported framework/algorithm version: .\n", - "INFO:sagemaker.image_uris:Ignoring unnecessary instance type: None.\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.model_monitor import DefaultModelMonitor\n", "\n", @@ -8235,7 +8012,7 @@ }, { "cell_type": "code", - "execution_count": 493, + "execution_count": null, "id": "c2b3fe69", "metadata": { "tags": [ @@ -8279,19 +8056,10 @@ }, { "cell_type": "code", - "execution_count": 177, + "execution_count": null, "id": "5cedff08", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Parameter validation failed:\n", - "Invalid type for parameter MonitoringScheduleName, value: None, type: , valid types: \n" - ] - } - ], + "outputs": [], "source": [ "def check_execution(monitoring_schedule):\n", " \"\"\"\n", @@ -8352,7 +8120,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": null, "id": "5ddca53e", "metadata": {}, "outputs": [], @@ -8386,31 +8154,14 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": null, "id": "c2089ba4", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker:Creating model with name: pipeline-penguins-2024-03-13-14-25-54-028\n", - "INFO:sagemaker:Creating endpoint-config with name penguins-endpoint\n", - "INFO:sagemaker:Creating endpoint with name penguins-endpoint\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "------!" - ] - } - ], + "outputs": [], "source": [ "%%script false --no-raise-error\n", "#| eval: false\n", @@ -8430,7 +8181,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": null, "id": "c4545041", "metadata": { "tags": [ @@ -8454,40 +8205,10 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": null, "id": "49bc662a", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File: s3://mlschool/penguins/monitoring/data-capture/penguins-endpoint/AllTraffic/2024/03/13/14/43-41-054-9ba5f93c-f9c8-4beb-8ced-85e706e1a011.jsonl\n", - "{\n", - " \"captureData\": {\n", - " \"endpointInput\": {\n", - " \"observedContentType\": \"text/csv\",\n", - " \"mode\": \"INPUT\",\n", - " \"data\": \"Torgersen,39.1,18.7,181.0,3750.0,MALE\",\n", - " \"encoding\": \"CSV\"\n", - " },\n", - " \"endpointOutput\": {\n", - " \"observedContentType\": \"text/csv; charset=utf-8\",\n", - " \"mode\": \"OUTPUT\",\n", - " \"data\": \"Adelie,0.977324724\\n\",\n", - " \"encoding\": \"CSV\"\n", - " }\n", - " },\n", - " \"eventMetadata\": {\n", - " \"eventId\": \"11a01e87-10c8-449c-8a8c-06ae9518229f\",\n", - " \"inferenceId\": \"0\",\n", - " \"inferenceTime\": \"2024-03-13T14:43:41Z\"\n", - " },\n", - " \"eventVersion\": \"0\"\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "files = S3Downloader.list(DATA_CAPTURE_DESTINATION)\n", "if len(files):\n", @@ -8508,25 +8229,14 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": null, "id": "a4a32d8c", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "data": { - "text/plain": [ - "'s3://mlschool/penguins/monitoring/groundtruth/2024/03/13/14/4552.jsonl'" - ] - }, - "execution_count": 164, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import random\n", "from datetime import datetime\n", @@ -8575,23 +8285,14 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": null, "id": "54762759", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.image_uris:Defaulting to the only supported framework/algorithm version: .\n", - "INFO:sagemaker.image_uris:Ignoring unnecessary instance type: None.\n" - ] - } - ], + "outputs": [], "source": [ "from sagemaker.model_monitor import ModelQualityMonitor\n", "\n", @@ -8628,23 +8329,14 @@ }, { "cell_type": "code", - "execution_count": 169, + "execution_count": null, "id": "9665c61a", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.model_monitor.model_monitoring:Creating Monitoring Schedule with name: penguins-model-monitoring-schedule\n", - "INFO:sagemaker:Starting Monitoring Schedule with name: penguins-model-monitoring-schedule\n" - ] - } - ], + "outputs": [], "source": [ "%%script false --no-raise-error\n", "#| eval: false\n", @@ -8693,143 +8385,10 @@ }, { "cell_type": "code", - "execution_count": 180, + "execution_count": null, "id": "34ba56d9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Processing Job Status: Completed\n", - "Exit Message: \"CompletedWithViolations: Job completed successfully with 5 violations.\"\n", - "Last Modified Time: 2024-03-13 11:24:05.882000-04:00\n", - "\n", - "Execution:\n", - "{\n", - " \"ProcessingInputs\": [\n", - " {\n", - " \"InputName\": \"constraints\",\n", - " \"AppManaged\": false,\n", - " \"S3Input\": {\n", - " \"S3Uri\": \"s3://mlschool/penguins/monitoring/model-quality/constraints.json\",\n", - " \"LocalPath\": \"/opt/ml/processing/baseline/constraints\",\n", - " \"S3DataType\": \"S3Prefix\",\n", - " \"S3InputMode\": \"File\",\n", - " \"S3DataDistributionType\": \"FullyReplicated\"\n", - " }\n", - " },\n", - " {\n", - " \"InputName\": \"endpoint_input_1\",\n", - " \"AppManaged\": false,\n", - " \"S3Input\": {\n", - " \"S3Uri\": \"s3://mlschool/penguins/monitoring/model-quality/merge/penguins-endpoint/AllTraffic/2024/03/13/14\",\n", - " \"LocalPath\": \"/opt/ml/processing/input_data/penguins-endpoint/AllTraffic/2024/03/13/14\",\n", - " \"S3DataType\": \"S3Prefix\",\n", - " \"S3InputMode\": \"File\",\n", - " \"S3DataDistributionType\": \"FullyReplicated\",\n", - " \"S3CompressionType\": \"None\"\n", - " }\n", - " }\n", - " ],\n", - " \"ProcessingOutputConfig\": {\n", - " \"Outputs\": [\n", - " {\n", - " \"OutputName\": \"result\",\n", - " \"S3Output\": {\n", - " \"S3Uri\": \"s3://mlschool/penguins/monitoring/model-quality/penguins-endpoint/penguins-model-monitoring-schedule/2024/03/13/15\",\n", - " \"LocalPath\": \"/opt/ml/processing/output\",\n", - " \"S3UploadMode\": \"Continuous\"\n", - " },\n", - " \"AppManaged\": false\n", - " }\n", - " ]\n", - " },\n", - " \"ProcessingJobName\": \"model-quality-monitoring-202403131500-d5ddd720f1dd044adf80cb8a\",\n", - " \"ProcessingResources\": {\n", - " \"ClusterConfig\": {\n", - " \"InstanceCount\": 1,\n", - " \"InstanceType\": \"ml.m5.xlarge\",\n", - " \"VolumeSizeInGB\": 20\n", - " }\n", - " },\n", - " \"StoppingCondition\": {\n", - " \"MaxRuntimeInSeconds\": 1800\n", - " },\n", - " \"AppSpecification\": {\n", - " \"ImageUri\": \"156813124566.dkr.ecr.us-east-1.amazonaws.com/sagemaker-model-monitor-analyzer\"\n", - " },\n", - " \"Environment\": {\n", - " \"analysis_type\": \"MODEL_QUALITY\",\n", - " \"baseline_constraints\": \"/opt/ml/processing/baseline/constraints/constraints.json\",\n", - " \"dataset_format\": \"{\\\"sagemakerMergeJson\\\":{\\\"captureIndexNames\\\":[\\\"endpointOutput\\\"],\\\"originalDatasetFormat\\\":null}}\",\n", - " \"dataset_source\": \"/opt/ml/processing/input_data\",\n", - " \"end_time\": \"2024-03-13T15:00:00Z\",\n", - " \"inference_attribute\": \"0\",\n", - " \"metric_time\": \"2024-03-13T14:00:00Z\",\n", - " \"monitoring_input_type\": \"ENDPOINT_INPUT\",\n", - " \"output_path\": \"/opt/ml/processing/output\",\n", - " \"problem_type\": \"MulticlassClassification\",\n", - " \"publish_cloudwatch_metrics\": \"Enabled\",\n", - " \"sagemaker_endpoint_name\": \"penguins-endpoint\",\n", - " \"sagemaker_monitoring_schedule_name\": \"penguins-model-monitoring-schedule\",\n", - " \"start_time\": \"2024-03-13T14:00:00Z\"\n", - " },\n", - " \"RoleArn\": \"arn:aws:iam::325223348818:role/service-role/AmazonSageMaker-ExecutionRole-20230312T160501\",\n", - " \"ProcessingJobArn\": \"arn:aws:sagemaker:us-east-1:325223348818:processing-job/model-quality-monitoring-202403131500-d5ddd720f1dd044adf80cb8a\",\n", - " \"ProcessingJobStatus\": \"Completed\",\n", - " \"ExitMessage\": \"CompletedWithViolations: Job completed successfully with 5 violations.\",\n", - " \"ProcessingEndTime\": \"2024-03-13 11:24:05.490000-04:00\",\n", - " \"ProcessingStartTime\": \"2024-03-13 11:22:34.328000-04:00\",\n", - " \"LastModifiedTime\": \"2024-03-13 11:24:05.882000-04:00\",\n", - " \"CreationTime\": \"2024-03-13 11:17:33.904000-04:00\",\n", - " \"MonitoringScheduleArn\": \"arn:aws:sagemaker:us-east-1:325223348818:monitoring-schedule/penguins-model-monitoring-schedule\",\n", - " \"ResponseMetadata\": {\n", - " \"RequestId\": \"250e1a71-7046-44b6-9051-09fb0b06453c\",\n", - " \"HTTPStatusCode\": 200,\n", - " \"HTTPHeaders\": {\n", - " \"x-amzn-requestid\": \"250e1a71-7046-44b6-9051-09fb0b06453c\",\n", - " \"content-type\": \"application/x-amz-json-1.1\",\n", - " \"content-length\": \"2659\",\n", - " \"date\": \"Wed, 13 Mar 2024 15:48:25 GMT\"\n", - " },\n", - " \"RetryAttempts\": 0\n", - " }\n", - "}\n", - "\n", - "Violations:\n", - "{\n", - " \"violations\": [\n", - " {\n", - " \"constraint_check_type\": \"LessThanThreshold\",\n", - " \"description\": \"Metric weightedF2 with 0.25660491952626785 was LessThanThreshold '0.8430569155446755'\",\n", - " \"metric_name\": \"weightedF2\"\n", - " },\n", - " {\n", - " \"constraint_check_type\": \"LessThanThreshold\",\n", - " \"description\": \"Metric accuracy with 0.35135135135135137 was LessThanThreshold '0.86'\",\n", - " \"metric_name\": \"accuracy\"\n", - " },\n", - " {\n", - " \"constraint_check_type\": \"LessThanThreshold\",\n", - " \"description\": \"Metric weightedRecall with 0.35135135135135137 was LessThanThreshold '0.8599999999999999'\",\n", - " \"metric_name\": \"weightedRecall\"\n", - " },\n", - " {\n", - " \"constraint_check_type\": \"LessThanThreshold\",\n", - " \"description\": \"Metric weightedPrecision with 0.12344777209642074 was LessThanThreshold '0.8872222222222221'\",\n", - " \"metric_name\": \"weightedPrecision\"\n", - " },\n", - " {\n", - " \"constraint_check_type\": \"LessThanThreshold\",\n", - " \"description\": \"Metric weightedF1 with 0.1827027027027027 was LessThanThreshold '0.8298461538461538'\",\n", - " \"metric_name\": \"weightedF1\"\n", - " }\n", - " ]\n", - "}\n" - ] - } - ], + "outputs": [], "source": [ "check_execution(model_monitor)" ] @@ -8846,7 +8405,7 @@ }, { "cell_type": "code", - "execution_count": 188, + "execution_count": null, "id": "02437a4a", "metadata": {}, "outputs": [], @@ -8868,19 +8427,10 @@ }, { "cell_type": "code", - "execution_count": 189, + "execution_count": null, "id": "1df9cae4", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "arn:aws:sagemaker:us-east-1:325223348818:model-package/basic-penguins/2\n", - "arn:aws:sagemaker:us-east-1:325223348818:model-package/custom-penguins/9\n" - ] - } - ], + "outputs": [], "source": [ "package1 = get_model_package(BASIC_MODEL_PACKAGE_GROUP)\n", "package2 = get_model_package(CUSTOM_MODEL_PACKAGE_GROUP)\n", @@ -8891,7 +8441,7 @@ }, { "cell_type": "code", - "execution_count": 190, + "execution_count": null, "id": "6c8aea09", "metadata": {}, "outputs": [], @@ -8905,32 +8455,14 @@ }, { "cell_type": "code", - "execution_count": 191, + "execution_count": null, "id": "dd20b354", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'ModelArn': 'arn:aws:sagemaker:us-east-1:325223348818:model/shadow-penguins-endpoint-model1-0316192704',\n", - " 'ResponseMetadata': {'RequestId': 'eccbae45-8625-473b-ab1e-8554dee78eb5',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'eccbae45-8625-473b-ab1e-8554dee78eb5',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '104',\n", - " 'date': 'Sat, 16 Mar 2024 23:27:06 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 191, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "model1_name = f\"{SHADOW_DEPLOYMENT_ENDPOINT}-model1-{timestamp}\"\n", "\n", @@ -8943,28 +8475,10 @@ }, { "cell_type": "code", - "execution_count": 192, + "execution_count": null, "id": "d2024f35", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'ModelArn': 'arn:aws:sagemaker:us-east-1:325223348818:model/shadow-penguins-endpoint-model2-0316192704',\n", - " 'ResponseMetadata': {'RequestId': '89b72bf2-21a3-4dc0-a6a0-4ccb4b548669',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '89b72bf2-21a3-4dc0-a6a0-4ccb4b548669',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '104',\n", - " 'date': 'Sat, 16 Mar 2024 23:27:08 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 192, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "model2_name = f\"{SHADOW_DEPLOYMENT_ENDPOINT}-model2-{timestamp}\"\n", "\n", @@ -8977,7 +8491,7 @@ }, { "cell_type": "code", - "execution_count": 193, + "execution_count": null, "id": "85769b3e", "metadata": {}, "outputs": [], @@ -8987,28 +8501,10 @@ }, { "cell_type": "code", - "execution_count": 194, + "execution_count": null, "id": "969df4f8", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'EndpointConfigArn': 'arn:aws:sagemaker:us-east-1:325223348818:endpoint-config/shadow-penguins-endpoint-config-0316192704',\n", - " 'ResponseMetadata': {'RequestId': '13421d00-9a35-4b88-a4e1-8a0a74cc5fc4',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '13421d00-9a35-4b88-a4e1-8a0a74cc5fc4',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '123',\n", - " 'date': 'Sat, 16 Mar 2024 23:27:13 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 194, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "endpoint_config_name = f\"{SHADOW_DEPLOYMENT_ENDPOINT}-config-{timestamp}\"\n", "\n", @@ -9038,28 +8534,10 @@ }, { "cell_type": "code", - "execution_count": 195, + "execution_count": null, "id": "33e8d886", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'EndpointArn': 'arn:aws:sagemaker:us-east-1:325223348818:endpoint/shadow-penguins-endpoint',\n", - " 'ResponseMetadata': {'RequestId': '1390b0fd-de43-4218-bab9-7bf99ab2b697',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '1390b0fd-de43-4218-bab9-7bf99ab2b697',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'content-length': '92',\n", - " 'date': 'Sat, 16 Mar 2024 23:27:18 GMT'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 195, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "sagemaker_client.create_endpoint(\n", " EndpointName=SHADOW_DEPLOYMENT_ENDPOINT,\n", @@ -9069,18 +8547,10 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": null, "id": "069afdae", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint shadow-penguins-endpoint of account 325223348818 not found.\n" - ] - } - ], + "outputs": [], "source": [ "payload = \"\"\"\n", "0.6569590202313976,-1.0813829646495108,1.2097102831892812,0.9226343641317372,1.0,0.0,0.0\n", @@ -9137,7 +8607,7 @@ }, { "cell_type": "code", - "execution_count": 404, + "execution_count": 125, "id": "59d1e634", "metadata": { "tags": [ @@ -9148,10 +8618,10 @@ { "data": { "text/plain": [ - "_PipelineExecution(arn='arn:aws:sagemaker:us-east-1:325223348818:pipeline/session9-pipeline/execution/5y50p6okclor', sagemaker_session=)" + "_PipelineExecution(arn='arn:aws:sagemaker:us-east-1:325223348818:pipeline/session15-pipeline/execution/89f4c9uyn8hf', sagemaker_session=)" ] }, - "execution_count": 404, + "execution_count": 125, "metadata": {}, "output_type": "execute_result" } @@ -9160,7 +8630,7 @@ "# %%script false --no-raise-error\n", "# | eval: false\n", "\n", - "session13_pipeline.start()" + "session15_pipeline.start()" ] }, { @@ -9183,30 +8653,14 @@ }, { "cell_type": "code", - "execution_count": 181, + "execution_count": null, "id": "0df2cbb1", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker:Deleting Monitoring Schedule with name: None\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Parameter validation failed:\n", - "Invalid type for parameter MonitoringScheduleName, value: None, type: , valid types: \n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " data_monitor.delete_monitoring_schedule()\n", @@ -9224,29 +8678,14 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": null, "id": "dee9a67f", "metadata": { "tags": [ "hide-output" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker:Deleting Monitoring Schedule with name: penguins-model-monitoring-schedule\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:sagemaker.model_monitor.model_monitoring:Deleting Model Quality Job Definition with name: model-quality-job-definition-2024-03-13-14-47-53-040\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " model_monitor.delete_monitoring_schedule()\n", @@ -9264,7 +8703,7 @@ }, { "cell_type": "code", - "execution_count": 306, + "execution_count": null, "id": "6b32c3a4-312e-473c-a217-33606f77d1e9", "metadata": { "tags": [ diff --git a/program/images/inference-pipeline.png b/program/images/inference-pipeline.png index f7cfd6e..57c1622 100644 Binary files a/program/images/inference-pipeline.png and b/program/images/inference-pipeline.png differ diff --git a/program/images/prediction-service.png b/program/images/prediction-service.png index 5b83480..8622cf2 100644 Binary files a/program/images/prediction-service.png and b/program/images/prediction-service.png differ