Edit

Share via


Upgrade model management to SDK v2

Important

This article references Azure Machine Learning SDK v1. SDK v1 is deprecated as of March 31, 2025. Support for it ends on June 30, 2026. Your existing workflows that use SDK v1 continue to operate after the end-of-support date, but they could be exposed to security risks or breaking changes. Transition to SDK v2 before June 30, 2026. For more information, see What is Azure Machine Learning CLI and Python SDK v2?

This article provides a comparison of scenarios in SDK v1 and SDK v2.

Create model

  • SDK v1

    from azureml.core.model import Model
    
    # Register model
    model = Model.register(ws, model_name="local-file-example", model_path="mlflow-model/model.pkl")
    
  • SDK v2

    from azure.ai.ml.entities import Model
    from azure.ai.ml.constants import AssetTypes
    
    file_model = Model(
        path="mlflow-model/model.pkl",
        type=AssetTypes.CUSTOM_MODEL,
        name="local-file-example",
        description="Model created from local file.",
        stage="Development"  # Optional lifecycle stage: Development, Production, or Archived
    )
    ml_client.models.create_or_update(file_model)
    

Use model in an experiment or job

  • SDK v1

    model = run.register_model(model_name='run-model-example',
                               model_path='outputs/model/')
    print(model.name, model.id, model.version, sep='\t')
    
  • SDK v2

    from azure.ai.ml.entities import Model
    from azure.ai.ml.constants import AssetTypes
    
    run_model = Model(
        path="azureml://jobs/$RUN_ID/outputs/artifacts/paths/model/",
        name="run-model-example",
        description="Model created from run.",
        type=AssetTypes.CUSTOM_MODEL
    )
    
    ml_client.models.create_or_update(run_model)
    

For more information about models, see Work with models in Azure Machine Learning.

Mapping of key functionality in SDK v1 and SDK v2

Functionality in SDK v1 Rough mapping in SDK v2
Model.register ml_client.models.create_or_update
run.register_model ml_client.models.create_or_update
Model.deploy ml_client.begin_create_or_update(blue_deployment)

Next steps

For more information, see the following documentation: