SageMaker Notebook Instance: cannot import name 'get_execution_role' from 'sagemaker'

0

I am trying to run a pytorch estimator on a local instance. I have a basic script from a SageMaker Studio Notebook which loads the session, region, and role. Because Studio notebooks do not support local instance types, I migrated to Notebook instances. Immediately when I run the first code block, I receive an error.
Environment:

  • SageMaker Notebook Instance.
  • Kernel: conda_pytorch_p39
import sagemaker
from sagemaker import get_execution_role
from sagemaker.pytorch import PyTorch

# Get the necessary information
sagemaker_session = sagemaker.Session()
role = get_execution_role()

Cannot import name 'get_execution_role' from 'sagemaker' (/home/ec2-user/SageMaker/AI/sagemaker.py)

I also tried the following:

import sagemaker

sagemaker_session = sagemaker.Session()
bucket = sagemaker_session.default_bucket()
role = sagemaker.get_execution_role()

module 'sagemaker' has no attribute 'Session'

I have tried multiple variations of this to no avail. Please help.

Samuel
gefragt vor einem Jahr560 Aufrufe
1 Antwort
1
Akzeptierte Antwort

You seem to have a sagemaker.py in your working directory that the cell is importing. get_execution_role, session etc. are part of the sagemaker python SDK (https://sagemaker.readthedocs.io/en/stable/overview.html).

Not sure why you have the sagemaker.py file, if it's a helper function, try renaming it and trying the cell again. SageMaker notebooks should have sagemaker already installed, you can also install/upgrade it using pip.

AWS
Durga_S
beantwortet vor einem Jahr
  • Wow, I sure do. That was a silly mistake. Thank you for the fast response, Duraga_S!

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen