Repository navigation
Closed
Labels
Description
System Information
- Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans): Sagemaker / sagemaker.model.Model
- Framework Version: stable
- Python Version: 3.6
- CPU or GPU: CPU
- Python SDK Version:
- Are you using a custom image: Yes
Describe the problem
When creating a model, sagemaker.model.Model, if a sagemaker_session is not specified, an AttributeError: 'NoneType' object has no attribute 'create_model' is raised when invoking one of the model's functions. In the docs, also pasted below, it specifies that if the parameter is not specified, one is created. This did not work and I can confirm because when I passed in a valid sagemaker_session, the code worked fine.
sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.
Note: created a PR for this issue here
Minimal repro / logs
AttributeError Traceback (most recent call last)
<ipython-input-4-b38a2118e690> in <module>()
3 target_data_s3_location='s3://pd-ds-workbench-sagemaker-stg/projects/responder_recommendations/data/output',
4 instance_type='ml.m4.xlarge',
----> 5 instance_count=1
6 )
~/SageMaker/ds-python-utils/dsutils/ml/model.py in get_predictions_s3(self, input_data_s3_location, target_data_s3_location, instance_type, instance_count, wait)
136 instance_type=instance_type,
137 output_path=target_data_s3_location,
--> 138 tags=self.aws_tags()
139 )
140
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/model.py in transformer(self, instance_count, instance_type, strategy, assemble_with, output_path, output_kms_key, accept, env, max_concurrent_transforms, max_payload, tags, volume_kms_key)
520 attached to the ML compute instance (default: None).
521 """
--> 522 self._create_sagemaker_model(instance_type, tags=tags)
523 if self.enable_network_isolation():
524 env = None
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/model.py in _create_sagemaker_model(self, instance_type, accelerator_type, tags)
186 self.name = self.name or utils.name_from_image(container_def["Image"])
187 enable_network_isolation = self.enable_network_isolation()
--> 188 self.sagemaker_session.create_model(
189 self.name,
190 self.role,
AttributeError: 'NoneType' object has no attribute 'create_model'
- Exact command to reproduce: Call one of the
sagemaker.model.Modelclass methods without specifying asagemaker_sessionwhen instantiating the object (I calledsagemaker.model.Model.transformer()).
Activity
[-]SageMaker Session not getting created by default[/-][+]SageMaker Session not created by default upon Model Class Instantiation[/+]Addressing Issue aws#1184 - create Session by default
nadiaya commentedon Dec 19, 2019
Thank you for your contribution!
Addressing Issue aws#1184 - create Session by default
laurenyu commentedon Feb 14, 2020
fix was released in v1.50.11