-
Notifications
You must be signed in to change notification settings - Fork 2
Amazon SageMaker train locally using Python
toncho11 edited this page Oct 11, 2022
·
3 revisions
It is possible to use SageMaker using Python and training on your local computer. In this case "locally" means on your computer and using SageMaker APIs. Another option (not discussed here) is to use your local installation of TensorFlow and only use SageMaker to deploy your model to an end point.
Sources:
- https://gitlab.com/juliensimon/aim410/-/blob/master/local_training.ipynb
- https://www.youtube.com/watch?v=K3ngZKF31mc&ab_channel=JulienSimon
How it works?
- you need to install the sagemaker python package
- you need Docker because most frameworks such as TensorFlow are provided (from SageMaker) as big docker images and automatically downloaded
- you need to set the region and role in your python script
- you can use Amazon's cli to find your SageMaker role using the following command:
aws iam list-roles|grep SageMaker-Execution - you are limited to the number of Docker containers provided by the sagemaker python module
Python code:
sess = sagemaker.Session() # Use the AWS region configured with the AWS CLI
# sess = sagemaker.Session(boto3.session.Session(region_name='eu-west-1'))
# This doesn't work on your local machine because it doesn't have an IAM role :)
# role = sagemaker.get_execution_role()
# This is the SageMaker role you're already using, it will work just fine
role = 'YOUR_ROLE'
You can work on a local data and your local CPU or GPU.
Alternatively you can use a native version (not provided from SageMaker) of your ML framework and just use SageMaker to deploy your model.