將本機執行升級至 SDK v2
本機執行在 V1 和 V2 中都很類似。 在任一版本中設定計算目標時,請使用 「local」 字串。
本文提供 SDK v1 和 SDK v2 中案例的比較。
提交本機執行
SDK v1
from azureml.core import Workspace, Experiment, Environment, ScriptRunConfig # connect to the workspace ws = Workspace.from_config() # define and configure the experiment experiment = Experiment(workspace=ws, name='day1-experiment-train') config = ScriptRunConfig(source_directory='./src', script='train.py', compute_target='local') # set up pytorch environment env = Environment.from_conda_specification( name='pytorch-env', file_path='pytorch-env.yml') config.run_config.environment = env run = experiment.submit(config) aml_url = run.get_portal_url() print(aml_url)
SDK v2
#import required libraries from azure.ai.ml import MLClient, command from azure.ai.ml.entities import Environment from azure.identity import DefaultAzureCredential #connect to the workspace ml_client = MLClient.from_config(DefaultAzureCredential()) # set up pytorch environment env = Environment( image='mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04', conda_file='pytorch-env.yml', name='pytorch-env' ) # define the command command_job = command( code='./src', command='train.py', environment=env, compute='local', ) returned_job = ml_client.jobs.create_or_update(command_job) returned_job
SDK v1 和 SDK v2 中的主要功能對應
SDK v1 中的功能 | SDK v2 中的粗略對應 |
---|---|
experiment.submit | MLCLient.jobs.create_or_update |