Training Job Failing ClientError: The value '"binary_classifier"' is not valid for the 'predictor_type' hyperparameter

0

I have searched the re:Post forums as well as the other, well-known site that contains answers and solutions to problems.

I am using a Sagemaker notebook with the Python SDK. Th version of the Sagemaker Python SDK that is current as of this question and that I am running is 2.213.0.

I'm fitting a Sagemaker linear learner. I'm encountering an error in the value of the predictor_type hyperparameter. I am seeking to use the binary_classifier. Regardless if I put in regressor or the other allowed value, I continue to encounter a ClientError with validating the value of the hyperparameter.

The log information output in the notebook for the failed training job:

Running default environment configuration script
[03/20/2024 23:44:34 INFO 140282169501504] Reading default configuration from /opt/amazon/lib/python3.8/site-packages/algorithm/resources/default-input.json: {'mini_batch_size': '1000', 'epochs': '15', 'feature_dim': 'auto', 'use_bias': 'true', 'binary_classifier_model_selection_criteria': 'accuracy', 'f_beta': '1.0', 'target_recall': '0.8', 'target_precision': '0.8', 'num_models': 'auto', 'num_calibration_samples': '10000000', 'init_method': 'uniform', 'init_scale': '0.07', 'init_sigma': '0.01', 'init_bias': '0.0', 'optimizer': 'auto', 'loss': 'auto', 'margin': '1.0', 'quantile': '0.5', 'loss_insensitivity': '0.01', 'huber_delta': '1.0', 'num_classes': '1', 'accuracy_top_k': '3', 'wd': 'auto', 'l1': 'auto', 'momentum': 'auto', 'learning_rate': 'auto', 'beta_1': 'auto', 'beta_2': 'auto', 'bias_lr_mult': 'auto', 'bias_wd_mult': 'auto', 'use_lr_scheduler': 'true', 'lr_scheduler_step': 'auto', 'lr_scheduler_factor': 'auto', 'lr_scheduler_minimum_lr': 'auto', 'positive_example_weight_mult': '1.0', 'balance_multiclass_weights': 'false', 'normalize_data': 'true', 'normalize_label': 'auto', 'unbias_data': 'auto', 'unbias_label': 'auto', 'num_point_for_scaler': '10000', '_kvstore': 'auto', '_num_gpus': 'auto', '_num_kv_servers': 'auto', '_log_level': 'info', '_tuning_objective_metric': '', 'early_stopping_patience': '3', 'early_stopping_tolerance': '0.001', '_enable_profiler': 'false'}
[03/20/2024 23:44:34 INFO 140282169501504] Merging with provided configuration from /opt/ml/input/config/hyperparameters.json: {'predictor_type': 'null', 'sagemaker_container_log_level': '20', 'sagemaker_job_name': '"linear-learner-2024-03-20-23-41-44-252"', 'sagemaker_program': '"inference_linear_learner.py"', 'sagemaker_region': '"us-east-1"', 'sagemaker_submit_directory': '"s3://sagemaker-us-east-1-{{ value_here }}/linear-learner-2024-03-20-23-41-44-252/source/sourcedir.tar.gz"'}
[03/20/2024 23:44:34 ERROR 140282169501504] Customer Error: The value 'null' is not valid for the 'predictor_type' hyperparameter which accepts one of the following: 'binary_classifier', 'regressor', 'multiclass_classifier' (caused by ValidationError)

2024-03-20 23:44:55 Failed - Training job failed

How I'm bringing in the estimator:

from sagemaker.sklearn.estimator import SKLearn  # for estimator

My estimator code

estimator = SKLearn(
    entry_point=script_path,
    image_uri=image_uri,
    framework_version=FRAMEWORK_VERSION,
    instance_type='ml.m5.large',  # smallest
    role=role,
    sagemaker_session=sagemaker_session,
    hyperparameters={"predictor_type":"binary_classifier"}
)

My fit statement is:

estimator.fit(inputs=data_channels, logs=True, wait=True)

The discussion on Github at # see issue https://github.com/aws/sagemaker-python-sdk/issues/613 is somewhat related. I've tried different techniques for string processing to try to force acceptance of the value. Small things like predictor_type='bindary_classifier';''.join(predictor_type) and a couple of other small hacks.

Training job error in Sagemaker in the console

Trial and error for a couple of days now. Researching for over a couple of days hasn't resulted in any other questions or posts about this.

Edit: One of the approaches for setting the hyperparameters that I tried is using the set_hyperparameters function as shown in the documentation here. Even when copying the set_hyperparameters() value passed as in the documentation, it continues to return an error. Value used is:

estimator.set_hyperparameters(feature_dim=4, predictor_type="binary_classifier", mini_batch_size=200)  # I have 4 features rather than 784 shown in the doc

Error when using this example from the documentation:

UnexpectedStatusException: Error for Training job linear-learner-2024-03-21-21-25-17-096: Failed. Reason: ClientError: The value '"4"' is not valid for 'feature_dim'. Reason: '"4"' is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['feature_dim']:
    {'oneOf': [{'$ref': '#/definitions/auto_string'},
               {'maximum': 100000000, 'minimum': 1, 'type': 'integer'}]}

On instance['feature_dim']:
    '"4"' (caused by ValidationError), exit code: 2

Edit: Possibly related URLs to discussions on Github are pasted below. Not sure if these are relevant or not. Pasting for others who might be able to explain.

https://github.com/aws/sagemaker-python-sdk/issues/613 https://github.com/aws/sagemaker-python-sdk/issues/3487

I also did a scan of recently opened issues. I did not identify a recent issue that is relevant to above problem. https://github.com/aws/sagemaker-python-sdk/issues

asked a month ago149 views
1 Answer
0
Accepted Answer

Looks like it was the incorrect module.

This gets past the error described above:

import sagemaker
estimator = sagemaker.estimator.Estimator(  # compare original and this line to see difference
    # entry_point=script_path,
    image_uri=image_uri,
    framework_version=FRAMEWORK_VERSION,
    instance_type='ml.m5.large',  # smallest
    instance_count=1,
    role=role,
    sagemaker_session=sagemaker_session,
    hyperparameters={"feature_dim": 4, "predictor_type": "binary_classifier"}
)

Edit: Worked through couple of other, non-related bugs. Training job successful. Marking this reply as answer.

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions