Compartilhar via


Atualize o gerenciamento de modelos para o SDK v2

Este artigo fornece uma comparação de cenários no SDK v1 e no SDK v2.

Criar modelo

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

Usar modelo em um experimento/trabalho

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

Para obter mais informações sobre modelos, confira Trabalhar com modelos no aprendizado de máquina do Azure.

Mapeamento da funcionalidade de chave no SDK v1 e no SDK v2

Funcionalidade no SDK v1 Mapeamento aproximado no 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)

Próximas etapas

Para obter mais informações, confira esta documentação: