Mettre à niveau la gestion des modèles vers le SDK v2

Cet article fournit une comparaison des scénarios dans le SDK v1 et le SDK v2.

Créer un modèle

  • Kit de développement logiciel (SDK) v1

    import urllib.request
    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."
    )
    ml_client.models.create_or_update(file_model)
    

Utiliser un modèle dans une expérience ou un travail

  • Kit de développement logiciel (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)
    

Pour plus d’informations sur les modèles, consultez Utiliser des modèles dans Azure Machine Learning.

Mappage des fonctionnalités clés dans le SDK v1 et le SDK v2

Fonctionnalités dans le SDK v1 Mappage approximatif dans le 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)

Étapes suivantes

Pour plus d’informations, consultez cette documentation :