Search code examples
amazon-sagemakerlightgbm

Sagemaker:Failed to parse HyperParameter during LightGBM training


I am trying to train a LightGBM model in sagemaker. I think I am missing how to set the hyperparameters. The model fails in the training process with this error

2024-04-01 01:36:47,011 sagemaker-training-toolkit INFO     Failed to parse hyperparameter objective value binary to Json.

This is how I have defined the training steps

train_model_id, train_model_version, train_scope = "lightgbm-classification-model", "*", "training"
image_uri = sagemaker.image_uris.retrieve(
    framework=None,
    model_id=train_model_id,
    model_version=train_model_version,
    image_scope=train_scope,
    region=AWS_REGION,
    py_version="py3",
    instance_type=instance_type,
)
lgbm_train = Estimator(
    image_uri=image_uri,
    instance_type=instance_type,
    instance_count=1,
    output_path=model_path,
    role=ROLE_ARN,
    sagemaker_session=sagemaker_session,
)

lgbm_train.set_hyperparameters(
    objective="binary",
    early_stopping_round=150,
    num_threads=20,
    learning_rate=0.01,
    is_unbalance=True,
    max_depth=15,
    num_leaves=15,
    num_iterations=500,
)

train_args = lgbm_train.fit(
    inputs={
        "train": TrainingInput(
            s3_data=step_spark_pre_proc.properties.ProcessingOutputConfig.Outputs[
                "train"
            ].S3Output.S3Uri,
            content_type="text/csv",
        ),
        "validation": TrainingInput(
            s3_data=step_spark_pre_proc.properties.ProcessingOutputConfig.Outputs[
                "test"
            ].S3Output.S3Uri,
            content_type="text/csv",
        ),
    }
)

Solution

  • The objective parameter is not supported as a hyper parameter for the LightGBM algorithm on SageMaker.

    The SageMaker LightGBM algorithm automatically selects an evaluation metric and objective function according to the classification type, determined by the number of labels in your data. For regression, it uses root mean squared error for evaluation and L2 loss as the objective. For binary classification, both the evaluation metric and objective function are binary cross entropy.

    The full list of available hyper parameters for LightGBM on SageMaker is listed here.