sagemaker-python-sdk
sagemaker-python-sdk copied to clipboard
AttributeError: 'NoneType' object has no attribute '_create_model_request'
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.
any update here?
Running into the same issue. Any update?
any updates ? got the same issue
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()
?