Upgrade local runs to SDK v2
Local runs are similar in both V1 and V2. Use the "local" string when setting the compute target in either version.
This article gives a comparison of scenario(s) in SDK v1 and SDK v2.
Submit a local run
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
Mapping of key functionality in SDK v1 and SDK v2
Functionality in SDK v1 | Rough mapping in SDK v2 |
---|---|
experiment.submit | MLCLient.jobs.create_or_update |