Uredi

Upgrade AutoML to SDK v2

In SDK v2, jobs consolidate "experiments" and "runs".

In SDK v1, you primarily configure and run AutoML by using the AutoMLConfig class. In SDK v2, this class is now an AutoML job. Although some configuration options differ, most naming and functionality is preserved in V2.

This article compares scenarios in SDK v1 and SDK v2.

Submit AutoML run

  • SDK v2: The following example shows an AutoML classification task. For the complete code, see the examples repo.

    # Imports
    from azure.ai.ml import automl, Input, MLClient
    from azure.ai.ml.constants import AssetTypes
    
    # Create MLTables for training dataset
    # Note that AutoML Job can also take in tabular data
    my_training_data_input = Input(
        type=AssetTypes.MLTABLE, path="./data/training-mltable-folder"
    )
    
    # Create the AutoML classification job with the related factory-function.
    classification_job = automl.classification(
        compute="<compute_name>",
        experiment_name="<exp_name>",
        training_data=my_training_data_input,
        target_column_name="<name_of_target_column>",
        primary_metric="accuracy",
        n_cross_validations=5,
        enable_model_explainability=True,
        tags={"my_custom_tag": "My custom value"},
    )
    
    # Limits are all optional
    classification_job.set_limits(
        timeout_minutes=600,
        trial_timeout_minutes=20,
        max_trials=5,
        max_concurrent_trials = 4,
        max_cores_per_trial= 1,
        enable_early_termination=True,
    )
    
    # Training properties are optional
    classification_job.set_training(
        blocked_training_algorithms=["LogisticRegression"],
        enable_onnx_compatible_models=True,
    )
    
    # Submit the AutoML job
    returned_job = ml_client.jobs.create_or_update(classification_job)  
    returned_job
    

Mapping of key functionality in SDK v1 and SDK v2

Functionality in SDK v1 Rough mapping in SDK v2
AutoMLConfig automl.classification() / automl.regression() / automl.forecasting()
experiment.submit(automl_config) ml_client.jobs.create_or_update(job)
remote_run.get_portal_url() returned_job.services["Studio"].endpoint
AutoMLConfig(enable_early_stopping=True) job.set_limits(enable_early_termination=True)
AutoMLConfig(blocked_models=[...]) job.set_training(blocked_training_algorithms=[...])
AutoMLConfig(n_cross_validations=N) automl.classification(n_cross_validations=N)

Next steps

For more information, see: