ScriptRunConfig Class
Represents configuration information for submitting a training run in Azure Machine Learning.
A ScriptRunConfig packages together the configuration information needed to submit a run in Azure ML, including the script, compute target, environment, and any distributed job-specific configs.
Once a script run is configured and submitted with the submit, a ScriptRun is returned.
Class ScriptRunConfig constructor.
- Inheritance
-
azureml._logging.chained_identity.ChainedIdentityScriptRunConfig
Constructor
ScriptRunConfig(source_directory, script=None, arguments=None, run_config=None, _telemetry_values=None, compute_target=None, environment=None, distributed_job_config=None, resume_from=None, max_run_duration_seconds=2592000, command=None, docker_runtime_config=None)
Parameters
Name | Description |
---|---|
source_directory
Required
|
A local directory containing code files needed for a run. |
script
Required
|
The file path relative to the source_directory of the script to be run. |
arguments
Required
|
Optional command line arguments to pass to the training script. Arguments are passed in pairs, for example, ['–arg1', arg1_val, '–arg2', arg2_val]. |
run_config
Required
|
Optional run configuration to use. |
_telemetry_values
Required
|
Internal use only. |
compute_target
Required
|
The compute target where training will happen. This can either be a ComputeTarget object, the name of an existing ComputeTarget, or the string "local". If no compute target is specified, your local machine will be used. |
environment
Required
|
The environment to use for the run. If no environment is specified, azureml.core.runconfig.DEFAULT_CPU_IMAGE will be used as the Docker image for the run. |
distributed_job_config
Required
|
For jobs that require additional distributed job-specific configurations. |
resume_from
Required
|
The DataPath containing the checkpoint or model files from which to resume the experiment. |
max_run_duration_seconds
Required
|
The maximum time allowed for the run. The system will attempt to automatically cancel the run if it took longer than this value. :type max_run_duration_seconds: int |
command
Required
|
The command to be submitted for the run. The command property can also be used instead of script/arguments. Both command and script/argument properties cannot be used together to submit a run. To submit a script file using the command property - ['python', 'train.py', '–arg1', arg1_val] To run an actual command - ['ls'] |
docker_runtime_config
Required
|
For jobs that require Docker runtime-specific configurations. |
source_directory
Required
|
A local directory containing code files needed for a run. |
script
Required
|
The file path relative to the source_directory of the script to be run. |
arguments
Required
|
Optional command line arguments to pass to the training script. Arguments are passed in pairs, for example, ['–arg1', arg1_val, '–arg2', arg2_val]. |
run_config
Required
|
Optional run configuration to use. |
_telemetry_values
Required
|
Internal use only. |
compute_target
Required
|
The compute target where training will happen. This can either be a ComputeTarget object, the name of an existing ComputeTarget, or the string "local". If no compute target is specified, your local machine will be used. |
environment
Required
|
The environment to use for the run. If no environment is specified, azureml.core.runconfig.DEFAULT_CPU_IMAGE will be used as the Docker image for the run. |
distributed_job_config
Required
|
For jobs that require additional distributed job-specific configurations. |
resume_from
Required
|
The DataPath containing the checkpoint or model files from which to resume the experiment. |
max_run_duration_seconds
Required
|
The maximum time allowed for the run. The system will attempt to automatically cancel the run if it took longer than this value. |
command
Required
|
The command to be submitted for the run. The command property can also be used instead of script/arguments. Both command and script/argument properties cannot be used together to submit a run. To submit a script file using the command property - ['python', 'train.py', '–arg1', arg1_val] To run an actual command - ['ls'] |
docker_runtime_config
Required
|
For jobs that require Docker runtime-specific configurations. |
Remarks
The Azure Machine Learning SDK provides you with a series of interconnected classes, that are designed to help you train and compare machine learning models that are related by the shared problem that they are solving.
An Experiment acts as a logical container for these training runs. A ScriptRunConfig object is used to configure the information necessary for submitting a training run as part of an Experiment. When a run is submitted using a ScriptRunConfig object, the submit method returns an object of type ScriptRun. Then returned ScriptRun object gives you programmatic access to information about the training run. ScriptRun is a child class of Run.
The key concept to remember is that there are different configuration objects that are used to submit an experiment, based on what kind of run you want to trigger. The type of the configuration object then informs what child class of Run you get back from the submit method. When you pass a ScriptRunConfig object in a call to Experiment's submit method, you get back a ScriptRun object. Examples of other run objects returned include AutoMLRun (returned for an AutoML run) and PipelineRun (returned for a Pipeline run).
The following sample shows how to submit a training script on your local machine.
from azureml.core import ScriptRunConfig, Experiment
# create or load an experiment
experiment = Experiment(workspace, 'MyExperiment')
# create or retrieve a compute target
cluster = workspace.compute_targets['MyCluster']
# create or retrieve an environment
env = Environment.get(ws, name='MyEnvironment')
# configure and submit your training run
config = ScriptRunConfig(source_directory='.',
script='train.py',
arguments=['--arg1', arg1_val, '--arg2', arg2_val],
compute_target=cluster,
environment=env)
script_run = experiment.submit(config)
The following example shows how to submit a training script on your cluster using the command property instead of script and arguments.
from azureml.core import ScriptRunConfig, Experiment
# create or load an experiment
experiment = Experiment(workspace, 'MyExperiment')
# create or retrieve a compute target
cluster = workspace.compute_targets['MyCluster']
# create or retrieve an environment
env = Environment.get(ws, name='MyEnvironment')
# configure and submit your training run
config = ScriptRunConfig(source_directory='.',
command=['python', 'train.py', '--arg1', arg1_val],
compute_target=cluster,
environment=env)
script_run = experiment.submit(config)
The following sample shows how to run a command on your cluster.
from azureml.core import ScriptRunConfig, Experiment
# create or load an experiment
experiment = Experiment(workspace, 'MyExperiment')
# create or retrieve a compute target
cluster = workspace.compute_targets['MyCluster']
# create or retrieve an environment
env = Environment.get(ws, name='MyEnvironment')
# configure and submit your training run
config = ScriptRunConfig(source_directory='.',
command=['ls', '-l'],
compute_target=cluster,
environment=env)
script_run = experiment.submit(config)
For more examples showing how to work with ScriptRunConfig, see:
the article Select and use a compute target to train your model
these training notebooks
Attributes
MAX_DURATION_SECONDS_DEFAULT
MAX_DURATION_SECONDS_DEFAULT = 2592000