How to create hyperparameter tuning job with custom docker container on Amazon Sagemaker?

Viewed 358

I created a custom docker container to run Catboost on Amazon Sagemaker, followed this demo (https://github.com/aws-samples/sagemaker-byo-catboost-container-demo/blob/master/Catboost_container_for_SageMaker.ipynb). I now want to do hyperparameter tuning with this custom container, but this is not a built-in or pre-built Sagemaker container, so I am not sure if I could or how to create hyperparameter tuning job on Sagemaker with a custom container. I didn't find any official documentation or official examples about using custom docker container to do HYT.

So my question is: how to create hyperparameter tuning with a custom container on Amazon Sagemaker?

1 Answers

When creating an estimator for your custom container, you will want to specify hyperparameters that you will be passing in. For example in the Catboost training script you have different args that can represent different hyperparameters enter image description here

You can add more arguments such as epochs, learning rate and other hyperparameters that you will be tuning. You will then want to add these hyperparamters and fit them in the Estimator you are creating with your container, similar to as shown below.

enter image description here

After the container has been pushed to ECR you will want to define a JSON with your hyperparameter tuning job as described in the following image. enter image description here

You can then define your training and tuning jobs and call them through the SM Tuning Job API

smclient.create_hyper_parameter_tuning_job(
    HyperParameterTuningJobName=tuning_job_name,
    HyperParameterTuningJobConfig=tuning_job_config,
    TrainingJobDefinition=training_job_definition,
)

For an end to end example of tuning and training with a custom Keras/TensorFlow container check out the following document for reference.

https://sagemaker-examples.readthedocs.io/en/latest/hyperparameter_tuning/keras_bring_your_own/hpo_bring_your_own_keras_container.html

I work for AWS & my opinions are my own

Related