From 35caefc2897405dd7b08d3ace74bb458515ffc81 Mon Sep 17 00:00:00 2001 From: nileshpatil6 Date: Wed, 3 Jun 2026 22:43:58 +0530 Subject: [PATCH] fix(remote): remove -U flag from requirements.txt pip install The @remote decorator injects sagemaker>=3.2.0,<4.0.0 into a requirements file and installed it with pip install -r ... -U. The -U flag forces pip to upgrade sagemaker to the latest version within the range even if a compatible version is already installed. This created a version mismatch between the client (which serialized the function at version 3.5.0) and the container (which deserialized at 3.11.0), causing DeserializationError. Remove the -U flag from _install_requirements_txt and _install_req_txt_in_conda_env in both sagemaker-core and sagemaker-train. The version constraint already ensures compatibility; forced upgrades are not needed and actively harmful when the serialization format changes between minor versions. Fixes #5872 Signed-off-by: nileshpatil6 --- .../runtime_environment/runtime_environment_manager.py | 4 ++-- .../runtime_environment/runtime_environment_manager.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sagemaker-core/src/sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py b/sagemaker-core/src/sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py index 5f00317c23..9bc313e85f 100644 --- a/sagemaker-core/src/sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py +++ b/sagemaker-core/src/sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py @@ -298,7 +298,7 @@ def _install_requirements_txt(self, local_path, python_executable): """Install requirements.txt file""" # Validate path to prevent command injection validated_path = self._validate_path(local_path) - cmd = [python_executable, "-m", "pip", "install", "-r", validated_path, "-U"] + cmd = [python_executable, "-m", "pip", "install", "-r", validated_path] logger.info("Running command: '%s' in the dir: '%s' ", " ".join(cmd), os.getcwd()) _run_shell_cmd(cmd) logger.info("Command %s ran successfully", " ".join(cmd)) @@ -320,7 +320,7 @@ def _install_req_txt_in_conda_env(self, env_name, local_path): self._validate_env_name(env_name) validated_path = self._validate_path(local_path) - cmd = [self._get_conda_exe(), "run", "-n", env_name, "pip", "install", "-r", validated_path, "-U"] + cmd = [self._get_conda_exe(), "run", "-n", env_name, "pip", "install", "-r", validated_path] logger.info("Activating conda env and installing requirements: %s", " ".join(cmd)) _run_shell_cmd(cmd) logger.info("Requirements installed successfully in conda env %s", env_name) diff --git a/sagemaker-train/src/sagemaker/train/remote_function/runtime_environment/runtime_environment_manager.py b/sagemaker-train/src/sagemaker/train/remote_function/runtime_environment/runtime_environment_manager.py index 9cb0c7aee4..7ae7aa57a4 100644 --- a/sagemaker-train/src/sagemaker/train/remote_function/runtime_environment/runtime_environment_manager.py +++ b/sagemaker-train/src/sagemaker/train/remote_function/runtime_environment/runtime_environment_manager.py @@ -298,7 +298,7 @@ def _install_requirements_txt(self, local_path, python_executable): """Install requirements.txt file""" # Validate path to prevent command injection validated_path = self._validate_path(local_path) - cmd = [python_executable, "-m", "pip", "install", "-r", validated_path, "-U"] + cmd = [python_executable, "-m", "pip", "install", "-r", validated_path] logger.info("Running command: '%s' in the dir: '%s' ", " ".join(cmd), os.getcwd()) _run_shell_cmd(cmd) logger.info("Command %s ran successfully", " ".join(cmd)) @@ -320,7 +320,7 @@ def _install_req_txt_in_conda_env(self, env_name, local_path): self._validate_env_name(env_name) validated_path = self._validate_path(local_path) - cmd = [self._get_conda_exe(), "run", "-n", env_name, "pip", "install", "-r", validated_path, "-U"] + cmd = [self._get_conda_exe(), "run", "-n", env_name, "pip", "install", "-r", validated_path] logger.info("Activating conda env and installing requirements: %s", " ".join(cmd)) _run_shell_cmd(cmd) logger.info("Requirements installed successfully in conda env %s", env_name)