sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

`Estimator` environment variables are not passed to entry point script when using `HyperparameterTuner`

Open yuntan opened this issue 4 years ago • 3 comments

Describe the bug Environment variables specified at Estimator class are not passed to the entry point script when running jobs by HyperparameterTune class.

To reproduce Dummy entry point script and notebook running sagemaker SDK

Expected behavior Training jobs run without failure and HyperParameterTuning job finishes without error.

Screenshots or logs Logs is shown in above link.

System information

  • SageMaker Python SDK version: 2.59.1 (local)
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): TensorFlow
  • Framework version: 2.4.1
  • Python version: 3.9.4 (local)
  • CPU or GPU: CPU
  • Custom Docker image (Y/N): N

related: #2311

yuntan avatar Sep 06 '21 04:09 yuntan

This bug already costed me hours. -.- Any ETA of a fix @ahsan-z-khan or at least no slient failing?

lorenzwalthert avatar May 22 '22 20:05 lorenzwalthert

@ahsan-z-khan, I also have this issue. Do we have any updates on this?

alar0330 avatar Jul 10 '22 09:07 alar0330

I think the problem is that the underlaying botocore functionality does not exist, not even sure it exists on the API level.

lorenzwalthert avatar Sep 01 '22 16:09 lorenzwalthert

Hi folks, a workaround solution for that is to use the hyperparameters instead of environment in the Estimator API.

To don't change my estimator implementation, I added the code below in the hyperparameters code.

for k, v in estimator.environment.items():
    estimator._hyperparameters[k] = v

In the entry_point script, I added all unexpected arguments as environment variables

if len(remaining_args) > 0:
    for arg in range(len(remaining_args)):
        if remaining_args[arg].startswith("--"):
            os.environ[remaining_args[arg].strip("--")] = remaining_args[arg+1]

DougTrajano avatar Nov 11 '22 14:11 DougTrajano

I think we can close this as per #3614.

lorenzwalthert avatar Jan 27 '23 22:01 lorenzwalthert

Closing as completed

trungleduc avatar Sep 27 '23 11:09 trungleduc