Skip to content

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

Closed

Description

@neilmcguigan

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.

Activity

  1. mouhannadali commented on Aug 17, 2022

    @mouhannadali

    any update here?

  2. timxieICN commented on Mar 23, 2023

    @timxieICN

    Running into the same issue. Any update?

  3. bernadinel commented on Mar 24, 2023

    @bernadinel

    any updates ? got the same issue

  4. davidbrochart commented on Sep 21, 2023

    @davidbrochart
    Collaborator

    There is a method to set a default session:

    def _init_sagemaker_session_if_does_not_exist(self, instance_type=None):

    But it doesn't seem to be called early enough.
    Since it is accessed from another place:
    request_dict = self.model.sagemaker_session._create_model_request(

    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()?

  5. added
    component: model
    component: hosting
    on Apr 11, 2024
  6. added theissue type on Feb 4, 2025
  7. pintaoz-aws commented on Mar 5, 2025

    @pintaoz-aws
    Contributor

    Fixed by #5062

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

    Pending informationcomponent: hostingcomponent: modeltype: bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions