How to pass environment variables in sagemaker tuner job

0

Sagemaker training jobs support setting environment variables on-the-fly in the training job:

 "Environment": { 
      "string" : "string" 
   },

https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html

I did not find an equivalent for the tuner jobs:

https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHyperParameterTuningJob.html

According to my testing, the SagemakerTuner in the python SDK simply ignores the environment variables set in the passed estimator.

Is there any way to pass environment variables to the training jobs started by a tuner job programmatically, or is that currently unsupported?

Chris
已提問 1 年前檢視次數 1556 次
1 個回答
1
已接受的答案

Thanks for raising this. Yes, as you point out the Environment collection is not supported in the underlying CreateHyperparameterTuningJob API and therefore the SageMaker Python SDK can't make use of it when running a tuner.

As discussed on the SM Py SDK GitHub issue here, you might consider using hyperparameters instead to pass parameters through to the job?

If you specifically need environment variables for some other process/library, you could also explore setting the variables from your Python script (perhaps to map from hyperparam to env var?).

Or another option could be to customize your container image to bake in the variable via the ENV command? For example to customize an existing AWS Deep Learning Container (framework container), you could:

  • Use sagemaker.image_uris.retrieve(...) to find the base image URI for your given framework, version, region, etc. You'll need to authenticate Docker to this registry as well as your own Amazon ECR account.
  • Create a Dockerfile that takes this base image URI as an arg and builds FROM it, something like this example
  • Add the required ENV commands to bake in the (static) environment variables you need
  • docker build your custom container (passing in the base image URI as a --build-arg), upload it to Amazon ECR, and use in your SageMaker training job.
AWS
專家
Alex_T
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南