From 637bc2e2b6ec1bf3ff93b69e687e8ab71c6340ab Mon Sep 17 00:00:00 2001 From: Gokul A <166456257+nargokul@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:31:54 -0800 Subject: [PATCH 1/3] Fix Flake8 Violations --- .../model_server/multi_model_server/inference.py | 14 ++++++++++++-- .../serve/model_server/torchserve/inference.py | 14 ++++++++++++-- .../model_server/torchserve/xgboost_inference.py | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/sagemaker/serve/model_server/multi_model_server/inference.py b/src/sagemaker/serve/model_server/multi_model_server/inference.py index 3cece40c5e..1d2440f5f9 100644 --- a/src/sagemaker/serve/model_server/multi_model_server/inference.py +++ b/src/sagemaker/serve/model_server/multi_model_server/inference.py @@ -45,11 +45,21 @@ def input_fn(input_data, content_type): try: if hasattr(schema_builder, "custom_input_translator"): deserialized_data = schema_builder.custom_input_translator.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type, ) else: deserialized_data = schema_builder.input_deserializer.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type[0] + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type[0], ) # Check if preprocess method is defined and call it diff --git a/src/sagemaker/serve/model_server/torchserve/inference.py b/src/sagemaker/serve/model_server/torchserve/inference.py index 294c032ccc..489cc1bc1e 100644 --- a/src/sagemaker/serve/model_server/torchserve/inference.py +++ b/src/sagemaker/serve/model_server/torchserve/inference.py @@ -67,11 +67,21 @@ def input_fn(input_data, content_type): try: if hasattr(schema_builder, "custom_input_translator"): deserialized_data = schema_builder.custom_input_translator.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type, ) else: deserialized_data = schema_builder.input_deserializer.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type[0] + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type[0], ) # Check if preprocess method is defined and call it diff --git a/src/sagemaker/serve/model_server/torchserve/xgboost_inference.py b/src/sagemaker/serve/model_server/torchserve/xgboost_inference.py index 6dab9bc6c6..517c774bbc 100644 --- a/src/sagemaker/serve/model_server/torchserve/xgboost_inference.py +++ b/src/sagemaker/serve/model_server/torchserve/xgboost_inference.py @@ -70,11 +70,21 @@ def input_fn(input_data, content_type): try: if hasattr(schema_builder, "custom_input_translator"): return schema_builder.custom_input_translator.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type, ) else: return schema_builder.input_deserializer.deserialize( - io.BytesIO(input_data) if type(input_data)== bytes else io.BytesIO(input_data.encode('utf-8')), content_type[0] + ( + io.BytesIO(input_data) + if type(input_data) == bytes + else io.BytesIO(input_data.encode("utf-8")) + ), + content_type[0], ) except Exception as e: raise Exception("Encountered error in deserialize_request.") from e From 8f2611511daee81569967c414f9a3bd4a1d53b84 Mon Sep 17 00:00:00 2001 From: Gokul A Date: Tue, 11 Mar 2025 11:38:12 -0700 Subject: [PATCH 2/3] UPDATE PYTORCH VERSION TO ADDRESS SECURITY RISK **Description** Currently used Pytorch version has a possible vulnerability . Internal - https://tiny.amazon.com/p5i4jla1 **Testing Done** Unit and Integration tests in the CodeBuild --- tests/data/modules/script_mode/requirements.txt | 2 +- tests/data/serve_resources/mlflow/pytorch/conda.yaml | 4 ++-- tests/data/serve_resources/mlflow/pytorch/requirements.txt | 4 ++-- tests/unit/sagemaker/jumpstart/constants.py | 2 +- tox.ini | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/data/modules/script_mode/requirements.txt b/tests/data/modules/script_mode/requirements.txt index da7441eee2..8bc00365b2 100644 --- a/tests/data/modules/script_mode/requirements.txt +++ b/tests/data/modules/script_mode/requirements.txt @@ -1,3 +1,3 @@ numpy -f https://download.pytorch.org/whl/torch_stable.html -torch==2.0.1+cpu +torch>=2.6.0+cpu diff --git a/tests/data/serve_resources/mlflow/pytorch/conda.yaml b/tests/data/serve_resources/mlflow/pytorch/conda.yaml index be61456197..beecdbab08 100644 --- a/tests/data/serve_resources/mlflow/pytorch/conda.yaml +++ b/tests/data/serve_resources/mlflow/pytorch/conda.yaml @@ -17,8 +17,8 @@ dependencies: - pandas==2.2.1 - pyyaml==6.0.1 - requests==2.31.0 - - torch==2.0.1 - - torchvision==0.15.2 + - torch>=2.6.0 + - torchvision>=0.17.0 - tqdm==4.66.2 - scikit-learn==1.3.2 name: mlflow-env diff --git a/tests/data/serve_resources/mlflow/pytorch/requirements.txt b/tests/data/serve_resources/mlflow/pytorch/requirements.txt index 0446ed5053..450bcbfada 100644 --- a/tests/data/serve_resources/mlflow/pytorch/requirements.txt +++ b/tests/data/serve_resources/mlflow/pytorch/requirements.txt @@ -11,6 +11,6 @@ packaging==21.3 pandas==2.2.1 pyyaml==6.0.1 requests==2.32.2 -torch==2.2.0 -torchvision==0.17.0 +torch>=2.6.0 +torchvision>=0.17.0 tqdm==4.66.3 diff --git a/tests/unit/sagemaker/jumpstart/constants.py b/tests/unit/sagemaker/jumpstart/constants.py index 59f38bd189..c3ccdc2626 100644 --- a/tests/unit/sagemaker/jumpstart/constants.py +++ b/tests/unit/sagemaker/jumpstart/constants.py @@ -17391,7 +17391,7 @@ "texttable==1.6.7", "tokenize-rt==5.1.0", "tokenizers==0.13.3", - "torch==2.2.0", + "torch>=2.6.0", "transformers==4.33.3", "triton==2.2.0", "typing-extensions==4.8.0", diff --git a/tox.ini b/tox.ini index b16c0d2f0b..9000787e83 100644 --- a/tox.ini +++ b/tox.ini @@ -83,8 +83,8 @@ passenv = commands = python -c "import os; os.system('install-custom-pkgs --install-boto-wheels')" pip install 'apache-airflow==2.9.3' --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.9.3/constraints-3.8.txt" - pip install 'torch==2.0.1+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' - pip install 'torchvision==0.15.2+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' + pip install 'torch>=2.6.0+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' + pip install 'torchvision>=0.17.0+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' pip install 'dill>=0.3.8' pytest {posargs} From 4a1701636e0f9ef7fbb526310a7d4dbe56e31552 Mon Sep 17 00:00:00 2001 From: Gokul A Date: Tue, 11 Mar 2025 12:19:19 -0700 Subject: [PATCH 3/3] REvert CPU Versions --- tests/data/modules/script_mode/requirements.txt | 2 +- tox.ini | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/data/modules/script_mode/requirements.txt b/tests/data/modules/script_mode/requirements.txt index 8bc00365b2..da7441eee2 100644 --- a/tests/data/modules/script_mode/requirements.txt +++ b/tests/data/modules/script_mode/requirements.txt @@ -1,3 +1,3 @@ numpy -f https://download.pytorch.org/whl/torch_stable.html -torch>=2.6.0+cpu +torch==2.0.1+cpu diff --git a/tox.ini b/tox.ini index 9000787e83..b16c0d2f0b 100644 --- a/tox.ini +++ b/tox.ini @@ -83,8 +83,8 @@ passenv = commands = python -c "import os; os.system('install-custom-pkgs --install-boto-wheels')" pip install 'apache-airflow==2.9.3' --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.9.3/constraints-3.8.txt" - pip install 'torch>=2.6.0+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' - pip install 'torchvision>=0.17.0+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' + pip install 'torch==2.0.1+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' + pip install 'torchvision==0.15.2+cpu' -f 'https://download.pytorch.org/whl/torch_stable.html' pip install 'dill>=0.3.8' pytest {posargs}