Skip to content

estimator environment values are not used when calling HyperparameterTuner #2311

@anupash147

Description

@anupash147

Describe the bug
on singleton training; i use the below code

from sagemaker.sklearn.estimator import SKLearn
estimator = SKLearn(
    entry_point='train.py',
    source_dir='../',
    role=role,
    metric_definitions=metric_definitions,
    hyperparameters=hyperparameters,
    instance_count=1,
    instance_type='ml.m5.xlarge',
    framework_version='0.23-1',
    base_job_name='mlflow',
    vpc_config=vpc_config,
    environment={'MLFLOW_TRACKING_URI': 'https://xyz.com/mlflow-np',
                            'OTHER_ENV': 'something'}
)
estimator.fit({'train':train_path, 'test': test_path})

it works well but on using the same code for hyperparameter training it fails. I don't see the reason on failing.

estimator = SKLearn(
    entry_point='train.py',
    source_dir='../',      
    role=role,
    instance_count=1,
    instance_type='ml.m5.xlarge',
    hyperparameters=hyperparameters,
    metric_definitions=metric_definitions,
    framework_version='0.23-1',
    py_version='py3',
    vpc_config=vpc_config,
    environment={'MLFLOW_TRACKING_URI': 'https://xyz.com/mlflow-np',
                            'OTHER_ENV': 'something'}
)

hyperparameter_ranges = {
    'n-estimators': IntegerParameter(50, 200),
    'min-samples-leaf': IntegerParameter(1, 10)
}

objective_metric_name = 'median-AE'
objective_type = 'Minimize'

tuner = HyperparameterTuner(estimator,
                            objective_metric_name,
                            hyperparameter_ranges,
                            metric_definitions,
                            max_jobs=20,
                            max_parallel_jobs=10,
                            objective_type=objective_type,
                            base_tuning_job_name='mlflow')

tuner.fit({'train':train_path, 'test': test_path})

Also i am not able see the environment variables in debug.

Expected behavior
If I hardcode the values in the training it works fine.. this code is taken from https://github.com/aws-samples/amazon-sagemaker-mlflow-fargate/blob/main/lab/2_track_experiments_hpo.ipynb

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: sagemaker==2.39.0
  • Python version: 3.7.6
  • CPU or GPU: 4
  • Custom Docker image (Y/N): N

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions