Using sagemaker in jupyter notebook
Hi everyone,I am trying to train a huggingface model on jupyternotebook on my local machine.can i get some advice on: how do i pass my IAM role access key ?i have installed sagemaker on my jupyternotebook, however, how do i connect to my AWS account? i found a line of code:Blockquotegets role for executing training jobiam_client = boto3.client(‘iam’)role = iam_client.get_role(RoleName=‘{IAM_ROLE_WITH_SAGEMAKER_PERMISSIONS}’)[‘Role’][‘Arn’]hyperparameters = {‘model_name_or_path’:‘finiteautomata/beto-sentiment-analysis’,‘output_dir’:‘/opt/ml/model’# add your remaining hyperparameters# more info herehttps://github.com/huggingface/transformers/tree/v4.6.1/examples/pytorch/text-classification}Blockquotei have set up a new user in my AWS account and have my access keys. just don’t understand how do it pass it on to my local machine?everytime i only get errors like:BlockquoteValueError: Must setup local AWS configuration with a region supported by SageMaker.NoCredentialsError: Unable to locate credentialsBlockquoteplease advise!thank you in advance.meng
2021-09-14T12:40:47Z
Hey@tumon,You need to create an IAM Role for sagemaker with permission to access all required resources. You can find instructions on how to do this here:SageMaker Roles - Amazon SageMakerTo create a new roleOpen the IAM console athttps://console.aws.amazon.com/iam/.SelectRolesand then selectCreate role.SelectSageMaker.SelectNext: Permissions.The IAM managed policy,AmazonSageMakerFullAccessis automatically attached to this role. To see the permissions included in this policy, select the sideways arrow next to the policy name. SelectNext: Tags.(Optional) Add tags and selectNext: Review.Give the role a name in the text field underRole nameand selectCreate role.On theRolessection of the IAM console, select the role you just created. If needed, use the text box to search for the role using the role name you entered in step 7.On the role summary page, make note of the ARN.
2021-09-14T17:32:44Z
Hi@philschmid,Thank you so much for the quick reply!I have had an AWS IAM role and have my unique ARN. My following problem is in my jupyternotebook, no matter how i apply my ARN to “{IAM_ROLE_WITH_SAGEMAKER_PERMISSIONS}”  into the below code.iam_client = boto3.client(‘iam’)
role = iam_client.get_role(RoleName=’{IAM_ROLE_WITH_SAGEMAKER_PERMISSIONS}’)[‘Role’][‘Arn’]i always get an error :BlockquoteNoCredentialsError: Unable to locate credentialscould you please kindly advise what might i be missing here?thank you!meng
2021-09-15T07:12:03Z
Hey,Yes let me explain this, it is a bit complicated to get started. So theIAM ROLE, which you have created will be used inside the SageMaker Training Job/Inference. Meaning this ROLE is used to, e.g. download your data from s3 or is needed to start the underlying machine.The errorNoCredentialsError: Unable to locate credentialsis shown when you don’t have credentials configured on your machine. You need to runaws configureso set up IAM Credentials (User) on your machine. You need these credentials to start your training job.
2021-09-15T09:23:59Z
Hi@philschmidThank you so much for my silly question!I configured aws on my machine and now it worked!!meng
2023-08-10T19:41:10Z
So I had the same problem, but I didn’t want to use the secret access key to connect to AWS account, I was usingSSO login. My goal was to deploy huggingface model from my local machine usingHuggingFaceModelinterface. The solution:sg_role = "{SAGEMAKER-ROLE}"
s3_location = "{ARTIFACT-S3-URI}"
sg_session = sagemaker.Session(boto_session=boto3.session.Session(profile_name="{PROFILE-NAME"}))

hg_model = HuggingFaceModel(
    model_data=s3_location,
    role=sg_role,
    transformers_version=...,
    pytorch_version=...,
    py_version=...,
    sagemaker_session=sg_session
)

predictor = hg_model.deploy(
    initial_instance_count=1,
    instance_type="ml.g4dn.xlarge",
    )