Condividi tramite


Aggiornare la gestione dei modelli all'SDK v2

Questo articolo offre un confronto tra gli scenari in SDK v1 e SDK v2.

Creare un modello

  • 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)
    

Usare il modello in un esperimento/processo

  • 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)
    

Per altre informazioni sui modelli, vedere Usare modelli in Azure Machine Learning.

Mapping delle funzionalità chiave in SDK v1 e SDK v2

Funzionalità in SDK v1 Mapping approssimativo 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)

Passaggi successivi

Per altre informazioni, vedere la documentazione qui: