Closed george-chenvibes closed 2 years ago
For anyone struggling with this issue copy this notebook exactly when creating your pipeline. I changed my pipeline and it worked. https://github.com/aws/amazon-sagemaker-examples/blob/main/sagemaker-pipelines/tabular/tuning-step/sagemaker-pipelines-tuning-step.ipynb
Describe the bug When running the
HyperparameterTuner.fit
method, with ParameterString as part of input, the method errors out with following:Exception: Object of type ParameterString is not JSON serializable
. Even replacing the ParameterStrings with, strings produces the same error.To reproduce
bucket = "ml-bucket"
prefix = "sample-prefix/"
image_uri = sagemaker.image_uris.retrieve( framework="xgboost", region=region, version="1.0-1", py_version="py3", instance_type=training_instance_type, )
role = sagemaker.session.get_execution_role(sagemaker_session)
train_instance_count=1
training_instance_type="ml.m4.4xlarge"
estimator_prefix="generic-estimator-prefix"
estimator_output_path=f"s3://{bucket}/{estimator_prefix}"
train_data_path = f's3://{bucket}/{prefix}train'
test_data_path = f's3://{bucket}/{prefix}test'
train_data_path = ParameterString( name="TrainDataPath", default_value=train_data_path, )
test_data_path = ParameterString( name="TestDataPath", default_value=test_data_path, )
xgb = sagemaker.estimator.Estimator( image_uri=image_uri, role=role, instance_count=train_instance_count, instance_type=training_instance_type, output_path=estimator_output_path, base_job_name="generic-base-job-name", hyperparameters=HPs, debugger_hook_config=False, # disable SageMaker Debugger disable_profiler=True # Specifies whether Debugger monitoring and profiling will be disabled )
search_grid = { "alpha": ContinuousParameter(0.01, 10, scaling_type="Logarithmic"), "eta": ContinuousParameter(0.1, 0.5), "gamma": ContinuousParameter(0, 5), "min_child_weight": ContinuousParameter(0, 120), "max_depth": IntegerParameter(1, 7), "subsample": ContinuousParameter(0.5, 1) }
tuner = HyperparameterTuner( xgb, objective_metric_name="validation:auc", objective_type="Maximize", hyperparameter_ranges=search_grid, max_jobs=2, max_parallel_jobs=2, early_stopping_type="Auto", strategy="Bayesian" )
step_args = tuner.fit(inputs={ "train": TrainingInput( s3_data=train_data_path, ), "validation": TrainingInput( s3_data=test_data_path ), }, )
Even trying above without setting train_data_path, and test_data_path as ParameterStrings fails with same error.
Expected behavior Tuner successfully runs tuning job. Screenshots or logs
System information AWS Codebuild