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
질문됨 일 년 전560회 조회
1개 답변
1
수락된 답변

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
답변함 일 년 전
  • Wow, I sure do. That was a silly mistake. Thank you for the fast response, Duraga_S!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠