Skip to content

SageMaker Session not created by default upon Model Class Instantiation #1184

Closed

Description

@matthewfollegot

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.Model class methods without specifying a sagemaker_session when instantiating the object (I called sagemaker.model.Model.transformer()).

Activity

  1. changed the title [-]SageMaker Session not getting created by default[/-] [+]SageMaker Session not created by default upon Model Class Instantiation[/+] on Dec 18, 2019
  2. added a commit that references this issue on Dec 18, 2019
  3. nadiaya commented on Dec 19, 2019

    @nadiaya
    Contributor

    Thank you for your contribution!

  4. added a commit that references this issue on Feb 12, 2020
  5. added
    status: pending release
    on Feb 12, 2020
  6. laurenyu commented on Feb 14, 2020

    @laurenyu
    Contributor

    fix was released in v1.50.11

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

    status: pending releasetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions