sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

AttributeError: 'NoneType' object has no attribute '_create_model_request'

Open neilmcguigan opened this issue 2 years ago • 4 comments

Describe the bug Create a model without specifying sagemaker_session and you get this error

To reproduce

model = Model(
    image_uri = "246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-scikit-learn:0.23-1-cpu-py3",
    model_data = my_model_data_url,
    role = role_arn,
    source_dir = s3_url_to_targz,
    entry_point= "encoder.py"
)

model_step = CreateModelStep(
    name="createmodel",
    model = model,
    inputs = CreateModelInput(instance_type = "ml.m5.large")
)

pipeline = Pipeline(name="pipeline1", steps=[model_step])
pipeline.upsert(role_arn=role_arn)
pipeline.start()

if you add sagemaker_session = Session() to Model() it magically works

Expected behavior work without specifying sagemaker_session

Screenshots or logs

    request_dict = self.model.sagemaker_session._create_model_request(
AttributeError: 'NoneType' object has no attribute '_create_model_request'

System information A description of your system. Please provide:

  • SageMaker Python SDK version: latest
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): any
  • Framework version: any
  • Python version: 3.8
  • CPU or GPU: any
  • Custom Docker image (Y/N): N

Additional context Add any other context about the problem here.

neilmcguigan avatar Mar 12 '22 03:03 neilmcguigan

any update here?

mouhannadali avatar Aug 17 '22 11:08 mouhannadali

Running into the same issue. Any update?

timxieICN avatar Mar 23 '23 02:03 timxieICN

any updates ? got the same issue

bernadinel avatar Mar 24 '23 11:03 bernadinel

There is a method to set a default session: https://github.com/aws/sagemaker-python-sdk/blob/410ab2c005a59941a4e56a7081d4dc3009244454/src/sagemaker/model.py#L559 But it doesn't seem to be called early enough. Since it is accessed from another place: https://github.com/aws/sagemaker-python-sdk/blob/410ab2c005a59941a4e56a7081d4dc3009244454/src/sagemaker/workflow/steps.py#L609 Maybe a solution would be for the sagemaker_session to be a @property of the model, so that it can be initialized lazily by calling _init_sagemaker_session_if_does_not_exist()?

davidbrochart avatar Sep 21 '23 16:09 davidbrochart