Skip to content

Remote Training Job created with decorator not installing pip dependencies #4484

Closed

Description

@asarasua

Describe the bug
After upgrading to version 2.212.0, pip dependencies passed as a requirements.txt file in @remote decorator are not installed. Same code works fine in versions up to 2.209.x, fails with versions from 2.210.x.

To reproduce
Just tried with the toy example from the documentation:

import boto3
import sagemaker
from sagemaker.remote_function import remote

sm_session = sagemaker.Session(boto_session=boto3.session.Session(region_name="us-east-1"))
settings = dict(
    sagemaker_session=sm_session,
    role=<The IAM role name>,
    instance_type="ml.m5.xlarge",
    dependencies='./requirements.txt'
)

@remote(**settings)
def divide(x, y):
    return x / y


if __name__ == "__main__":
    print(divide(2, 3.0))

And got this in the Training Job, showing no pip install logging before (sagemaker is listed in requirements.txt):

  File "/opt/ml/input/data/sagemaker_remote_function_bootstrap/bootstrap_runtime_environment.py", line 24, in <module>
    from runtime_environment_manager import (
  File "/opt/ml/input/data/sagemaker_remote_function_bootstrap/runtime_environment_manager.py", line 27, in <module>
    import sagemaker
ModuleNotFoundError: No module named 'sagemaker'

Using sagemaker sdk versions previous to 2.210.x, the job prints pip install logging and then runs the operation without problems.

We observed equivalent problems in our code for remote functions that were working fine before upgrading.

Expected behavior
The training job should start by installing the dependencies defined in requirements.txt

System information

  • SageMaker Python SDK version: tried with 2.210.0, 2.211.0, 2.212.0
  • Python version: 3.8.18
  • CPU or GPU: CPU

Activity

  1. added
    component: pipelines
    on Mar 7, 2024
  2. added
    remote-function
    on Mar 7, 2024
  3. nmadan commented on Mar 8, 2024

    @nmadan
    Contributor

    Hi @asarasua, thanks for opening an issue for this. We are actively working on a fix.

  4. arun-akur8 commented on May 22, 2024

    @arun-akur8

    Hello!

    It seems I still get the same error when using remote decorator in VSCode in Code Editor Space in AWS Sagemaker Studio. Would it be the same issue?

    Error is :

    /miniconda3/bin/python: Error while finding module specification for 'sagemaker.remote_function.invoke_function' (ModuleNotFoundError: No module named 'sagemaker')

    Minimal code example:

    from sagemaker.remote_function import remote
    import sagemaker
    import boto3
    boto_session = boto3.Session()
    sm_session = sagemaker.Session(boto_session,default_bucket="default_bucket")
    image_uri = sagemaker.image_uris.retrieve(sagemaker.image_uris.SKLEARN_FRAMEWORK,version="1.2-1",region=region)
    settings = dict(
             sagemaker_session=sm_session,
             role=sagemaker.get_execution_role(),
             instance_type="ml.m5.large", image_uri=image_uri)
    

    sagemaker version: 2.200.0, 2.221.0
    Python version: 3.8
    Boto version: 1.34.109

  5. qqaatw commented on Jun 2, 2025

    @qqaatw

    Same:

    Traceback (most recent call last):
      File "/opt/ml/input/data/sagemaker_remote_function_bootstrap/bootstrap_runtime_environment.py", line 574, in main
        RuntimeEnvironmentManager()._validate_sagemaker_pysdk_version(
      File "/opt/ml/input/data/sagemaker_remote_function_bootstrap/runtime_environment_manager.py", line 361, in _validate_sagemaker_pysdk_version
        job_sagemaker_pysdk_version = self._current_sagemaker_pysdk_version()
      File "/opt/ml/input/data/sagemaker_remote_function_bootstrap/runtime_environment_manager.py", line 331, in _current_sagemaker_pysdk_version
        import sagemaker
    ModuleNotFoundError: No module named 'sagemaker'
    

    Seems like it is an issue with the image used. I can confirm this one works:

    763104351884.dkr.ecr.{aws_region}.amazonaws.com/pytorch-training:2.0.0-gpu-py310-cu118-ubuntu20.04-sagemaker
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: pipelinesremote-functiontype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions