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
feita há um ano559 visualizações
1 Resposta
1
Resposta aceita

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
respondido há um ano
  • Wow, I sure do. That was a silly mistake. Thank you for the fast response, Duraga_S!

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas