azure.ai.ml.sweep package Azure SDK for Python 2.0.0 documentation

class azure.ai.ml.sweep.BanditPolicy(*, delay_evaluation: Optional[int] = 0, evaluation_interval: Optional[int] = 0, slack_amount: Optional[float] = 0, slack_factor: Optional[float] = 0)[source]

Defines an early termination policy based on slack criteria and a frequency and delay interval for evaluation.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation. Defaults to 0.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations. Defaults to 0.

  • slack_amount (float) – Absolute distance allowed from the best performing run. Defaults to 0.

  • slack_factor (float) – Ratio of the allowed distance from the best performing run. Defaults to 0.

Example:

Configuring BanditPolicy early termination of a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations from azure.ai.ml.sweep import Uniform job_for_sweep = job( kernel=Uniform(min_value=0.0005, max_value=0.005), penalty=Uniform(min_value=0.9, max_value=0.99), ) from azure.ai.ml.sweep import BanditPolicy sweep_job = job_for_sweep.sweep( sampling_algorithm="random", primary_metric="best_val_acc", goal="Maximize", max_total_trials=8, max_concurrent_trials=4, early_termination_policy=BanditPolicy(slack_factor=0.15, evaluation_interval=1, delay_evaluation=10), ) 

Defines an early termination policy based on slack criteria and a frequency and delay interval for evaluation.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation. Defaults to 0.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations. Defaults to 0.

  • slack_amount (float) – Absolute distance allowed from the best performing run. Defaults to 0.

  • slack_factor (float) – Ratio of the allowed distance from the best performing run. Defaults to 0.

class azure.ai.ml.sweep.BayesianSamplingAlgorithm[source]

Bayesian Sampling Algorithm.

Example:

Assigning a Bayesian sampling algorithm for a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import BayesianSamplingAlgorithm, Objective, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=BayesianSamplingAlgorithm(), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), objective=Objective(goal="maximize", primary_metric="accuracy"), ) 

Base class for sampling algorithms

class azure.ai.ml.sweep.Choice(values: Optional[List[Union[float, str, dict]]] = None, **kwargs)[source]

Choice distribution configuration.

Parameters

values (List[Union[float, str, dict]]) – List of values to choose from.

Example:

Using Choice distribution to set values for a hyperparameter sweep
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import Choice, LogUniform # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( kernel=LogUniform(min_value=-6, max_value=-1), penalty=Choice([0.9, 0.18, 0.36, 0.72]), ) 
Parameters

values (List[Union[float, str, dict]]) – List of values to choose from.

class azure.ai.ml.sweep.GridSamplingAlgorithm[source]

Grid Sampling Algorithm.

Example:

Assigning a grid sampling algorithm for a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import GridSamplingAlgorithm, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=GridSamplingAlgorithm(), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), ) 

Base class for sampling algorithms

class azure.ai.ml.sweep.LogNormal(mu: Optional[float] = None, sigma: Optional[float] = None, **kwargs)[source]

LogNormal distribution configuration.

Parameters
  • mu (float) – Mean of the log of the distribution.

  • sigma (float) – Standard deviation of the log of the distribution.

Example:

Configuring LogNormal distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import LogNormal, QLogNormal # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( kernel=LogNormal(mu=0.0, sigma=1.0), penalty=QLogNormal(mu=5.0, sigma=2.0), ) 

LogNormal distribution configuration.

Parameters
  • mu (float) – Mean of the log of the distribution.

  • sigma (float) – Standard deviation of the log of the distribution.

class azure.ai.ml.sweep.LogUniform(min_value: Optional[float] = None, max_value: Optional[float] = None, **kwargs)[source]

LogUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the log of the distribution.

  • max_value (float) – Maximum value of the log of the distribution.

Example:

Configuring a LogUniform distribution for a hyperparameter sweep job learning rate
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import Choice, LogUniform # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( kernel=LogUniform(min_value=-6, max_value=-1), penalty=Choice([0.9, 0.18, 0.36, 0.72]), ) 

LogUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the log of the distribution.

  • max_value (float) – Maximum value of the log of the distribution.

class azure.ai.ml.sweep.MedianStoppingPolicy(*, delay_evaluation: Optional[int] = 0, evaluation_interval: Optional[int] = 1)[source]

Defines an early termination policy based on a running average of the primary metric of all runs.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation. Defaults to 0.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations. Defaults to 1.

Example:

Configuring an early termination policy for a hyperparameter sweep job using MedianStoppingPolicy
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations from azure.ai.ml.sweep import MedianStoppingPolicy, Uniform job_for_sweep = job( kernel=Uniform(min_value=0.0005, max_value=0.005), penalty=Uniform(min_value=0.9, max_value=0.99), ) sweep_job = job_for_sweep.sweep( sampling_algorithm="random", primary_metric="best_val_acc", goal="Maximize", max_total_trials=8, max_concurrent_trials=4, early_termination_policy=MedianStoppingPolicy(delay_evaluation=5, evaluation_interval=2), ) 

Defines an early termination policy based on a running average of the primary metric of all runs.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation. Defaults to 0.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations. Defaults to 1.

class azure.ai.ml.sweep.Normal(mu: Optional[float] = None, sigma: Optional[float] = None, **kwargs)[source]

Normal distribution configuration.

Parameters
  • mu (float) – Mean of the distribution.

  • sigma (float) – Standard deviation of the distribution.

Example:

Configuring Normal distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import Normal, Randint # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( penalty=Randint(upper=5), kernel=Normal(mu=2.0, sigma=1.0), ) 

Normal distribution configuration.

Parameters
  • mu (float) – Mean of the distribution.

  • sigma (float) – Standard deviation of the distribution.

class azure.ai.ml.sweep.Objective(goal: str, primary_metric: Optional[str] = None)[source]

Optimization objective.

Parameters
  • goal (str) – Required. Defines supported metric goals for hyperparameter tuning. Acceptable values are: “minimize”, “maximize”.

  • primary_metric (str) – Required. Name of the metric to optimize.

Example:

Assigning an objective to a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import BayesianSamplingAlgorithm, Objective, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=BayesianSamplingAlgorithm(), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), objective=Objective(goal="maximize", primary_metric="accuracy"), ) 

Optimization objective.

Parameters

goal – Required. Defines supported metric goals for hyperparameter tuning. Acceptable values

are: “minimize”, “maximize”. :type goal: str :param primary_metric: Required. The name of the metric to optimize. :type primary_metric: str

class azure.ai.ml.sweep.QLogNormal(mu: Optional[float] = None, sigma: Optional[float] = None, q: Optional[int] = None, **kwargs)[source]

QLogNormal distribution configuration.

Parameters
  • mu (float) – Mean of the log of the distribution.

  • sigma (float) – Standard deviation of the log of the distribution.

Example:

Configuring QLogNormal distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import LogNormal, QLogNormal # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( kernel=LogNormal(mu=0.0, sigma=1.0), penalty=QLogNormal(mu=5.0, sigma=2.0), ) 

QLogNormal distribution configuration.

Parameters
  • mu (float) – Mean of the log of the distribution.

  • sigma (float) – Standard deviation of the log of the distribution.

class azure.ai.ml.sweep.QLogUniform(min_value: Optional[float] = None, max_value: Optional[float] = None, q: Optional[int] = None, **kwargs)[source]

QLogUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the log of the distribution.

  • max_value (float) – Maximum value of the log of the distribution.

Example:

Configuring QLogUniform distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import QLogUniform, QNormal # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( penalty=QNormal(mu=2.0, sigma=1.0, q=1), kernel=QLogUniform(min_value=1.0, max_value=5.0), ) 

QLogUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the log of the distribution.

  • max_value (float) – Maximum value of the log of the distribution.

class azure.ai.ml.sweep.QNormal(mu: Optional[float] = None, sigma: Optional[float] = None, q: Optional[int] = None, **kwargs)[source]

QNormal distribution configuration.

Parameters
  • mu (float) – Mean of the distribution.

  • sigma (float) – Standard deviation of the distribution.

  • q (int) – Quantization factor.

Example:

Configuring QNormal distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import QLogUniform, QNormal # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( penalty=QNormal(mu=2.0, sigma=1.0, q=1), kernel=QLogUniform(min_value=1.0, max_value=5.0), ) 

QNormal distribution configuration.

Parameters
  • mu (float) – Mean of the distribution.

  • sigma (float) – Standard deviation of the distribution.

  • q (int) – Quantization factor.

class azure.ai.ml.sweep.QUniform(min_value: Optional[Union[int, float]] = None, max_value: Optional[Union[int, float]] = None, q: Optional[int] = None, **kwargs)[source]

QUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the distribution.

  • max_value (float) – Maximum value of the distribution.

  • q (int) – Quantization factor.

Example:

Configuring QUniform distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations from azure.ai.ml.sweep import QUniform, TruncationSelectionPolicy, Uniform job_for_sweep = job( kernel=Uniform(min_value=0.0005, max_value=0.005), penalty=QUniform(min_value=0.05, max_value=0.75, q=1), ) sweep_job = job_for_sweep.sweep( sampling_algorithm="random", primary_metric="best_val_acc", goal="Maximize", max_total_trials=8, max_concurrent_trials=4, early_termination_policy=TruncationSelectionPolicy(delay_evaluation=5, evaluation_interval=2), ) 

QUniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the distribution.

  • max_value (float) – Maximum value of the distribution.

  • q (int) – Quantization factor.

class azure.ai.ml.sweep.Randint(upper: Optional[int] = None, **kwargs)[source]

Randint distribution configuration.

Parameters

upper (int) – Upper bound of the distribution.

Example:

Configuring Randint distributions for a hyperparameter sweep on a Command job.
from azure.ai.ml import command job = command( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) from azure.ai.ml.sweep import Normal, Randint # we can reuse an existing Command Job as a function that we can apply inputs to for the sweep configurations job_for_sweep = job( penalty=Randint(upper=5), kernel=Normal(mu=2.0, sigma=1.0), ) 

Randint distribution configuration.

Parameters

upper (int) – Upper bound of the distribution.

class azure.ai.ml.sweep.RandomSamplingAlgorithm(*, rule: Optional[str] = None, seed: Optional[int] = None, logbase: Optional[Union[float, str]] = None)[source]

Random Sampling Algorithm.

Parameters
  • rule (str) – The specific type of random algorithm. Acceptable values are: “random”, “sobol”.

  • seed (int) – The seed for random number generation.

  • logbase (Union[float, str]) – A positive number or the number “e” in string format to be used as the base for log based random sampling.

Example:

Assigning a random sampling algorithm for a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import RandomSamplingAlgorithm, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=RandomSamplingAlgorithm(seed=999, rule="sobol", logbase="e"), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), ) 

Random Sampling Algorithm.

Parameters
  • rule (str) – The specific type of random algorithm. Acceptable values are: “random”, “sobol”.

  • seed (int) – The seed for random number generation.

  • logbase (Union[float, str]) – A positive number or the number “e” in string format to be used as the base for log based random sampling.

class azure.ai.ml.sweep.SamplingAlgorithm[source]

Base class for sampling algorithms.

You should not instantiate this class directly. Instead, use one of its subclasses.

Base class for sampling algorithms

class azure.ai.ml.sweep.SweepJob(*, name: Optional[str] = None, description: Optional[str] = None, tags: Optional[Dict] = None, display_name: Optional[str] = None, experiment_name: Optional[str] = None, identity: Optional[Union[azure.ai.ml.entities._credentials.ManagedIdentityConfiguration, azure.ai.ml.entities._credentials.AmlTokenConfiguration, azure.ai.ml.entities._credentials.UserIdentityConfiguration]] = None, inputs: Optional[Dict[str, Union[int, str, float, bool, azure.ai.ml.entities._inputs_outputs.input.Input]]] = None, outputs: Optional[Dict[str, azure.ai.ml.entities._inputs_outputs.output.Output]] = None, compute: Optional[str] = None, limits: Optional[azure.ai.ml.entities._job.job_limits.SweepJobLimits] = None, sampling_algorithm: Optional[Union[str, azure.ai.ml.entities._job.sweep.sampling_algorithm.SamplingAlgorithm]] = None, search_space: Optional[Dict[str, Union[azure.ai.ml.entities._job.sweep.search_space.Choice, azure.ai.ml.entities._job.sweep.search_space.LogNormal, azure.ai.ml.entities._job.sweep.search_space.LogUniform, azure.ai.ml.entities._job.sweep.search_space.Normal, azure.ai.ml.entities._job.sweep.search_space.QLogNormal, azure.ai.ml.entities._job.sweep.search_space.QLogUniform, azure.ai.ml.entities._job.sweep.search_space.QNormal, azure.ai.ml.entities._job.sweep.search_space.QUniform, azure.ai.ml.entities._job.sweep.search_space.Randint, azure.ai.ml.entities._job.sweep.search_space.Uniform]]] = None, objective: Optional[azure.ai.ml.entities._job.sweep.objective.Objective] = None, trial: Optional[Union[azure.ai.ml.entities._job.command_job.CommandJob, azure.ai.ml.entities._component.command_component.CommandComponent]] = None, early_termination: Optional[Union[azure.ai.ml.entities._job.sweep.early_termination_policy.BanditPolicy, azure.ai.ml.entities._job.sweep.early_termination_policy.MedianStoppingPolicy, azure.ai.ml.entities._job.sweep.early_termination_policy.TruncationSelectionPolicy]] = None, queue_settings: Optional[azure.ai.ml.entities._job.queue_settings.QueueSettings] = None, **kwargs: Any)[source]

Sweep job for hyperparameter tuning.

Parameters
  • name (str) – Name of the job.

  • display_name (str) – Display name of the job.

  • description (str) – Description of the job.

  • tags (dict[str, str]) – Tag dictionary. Tags can be added, removed, and updated.

  • properties (dict[str, str]) – The asset property dictionary.

  • experiment_name (str) – Name of the experiment the job will be created under, if None is provided, job will be created under experiment ‘Default’.

  • identity (Union[ ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]) – Identity that the training job will use while running on compute.

  • inputs (dict) – Inputs to the command.

  • outputs (dict[str, Output]) – Mapping of output data bindings used in the job.

  • sampling_algorithm (str) – The hyperparameter sampling algorithm to use over the search_space. Defaults to “random”.

  • search_space (Dict) – Dictionary of the hyperparameter search space. The key is the name of the hyperparameter and the value is the parameter expression.

  • objective (Objective) – Metric to optimize for.

  • compute (str) – The compute target the job runs on.

  • trial (Union[CommandJob, CommandComponent]) – The job configuration for each trial. Each trial will be provided with a different combination of hyperparameter values that the system samples from the search_space.

  • early_termination (Union[) – The early termination policy to use. A trial job is canceled when the criteria of the specified policy are met. If omitted, no early termination policy will be applied.

~azure.mgmt.machinelearningservices.models.BanditPolicy, ~azure.mgmt.machinelearningservices.models.MedianStoppingPolicy, ~azure.mgmt.machinelearningservices.models.TruncationSelectionPolicy] :param limits: Limits for the sweep job. :type limits: ~azure.ai.ml.entities.SweepJobLimits :param queue_settings: Queue settings for the job. :type queue_settings: ~azure.ai.ml.entities.QueueSettings :param kwargs: A dictionary of additional configuration parameters. :type kwargs: dict

Example:

Creating a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import BayesianSamplingAlgorithm, Objective, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=BayesianSamplingAlgorithm(), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), objective=Objective(goal="maximize", primary_metric="accuracy"), ) 

Sweep job for hyperparameter tuning.

Parameters
  • name (str) – Name of the job.

  • display_name (str) – Display name of the job.

  • description (str) – Description of the job.

  • tags (dict[str, str]) – Tag dictionary. Tags can be added, removed, and updated.

  • properties (dict[str, str]) – The asset property dictionary.

  • experiment_name (str) – Name of the experiment the job will be created under. If None is provided, job will be created under experiment ‘Default’.

  • identity (Union[ ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]) – Identity that the training job will use while running on compute.

  • inputs (dict) – Inputs to the command.

  • outputs (dict[str, Output]) – Mapping of output data bindings used in the job.

  • sampling_algorithm (str) – The hyperparameter sampling algorithm to use over the search_space. Defaults to “random”.

  • search_space (Dict) – Dictionary of the hyperparameter search space. The key is the name of the hyperparameter and the value is the parameter expression.

  • objective (Objective) – Metric to optimize for.

  • compute (str) – The compute target the job runs on.

  • trial (Union[CommandJob, CommandComponent]) – The job configuration for each trial. Each trial will be provided with a different combination of hyperparameter values that the system samples from the search_space.

  • early_termination (Union[) – The early termination policy to use. A trial job is canceled when the criteria of the specified policy are met. If omitted, no early termination policy will be applied.

~azure.mgmt.machinelearningservices.models.BanditPolicy, ~azure.mgmt.machinelearningservices.models.MedianStoppingPolicy, ~azure.mgmt.machinelearningservices.models.TruncationSelectionPolicy] :param limits: Limits for the sweep job. :type limits: ~azure.ai.ml.entities.SweepJobLimits :param queue_settings: Queue settings for the job. :type queue_settings: ~azure.ai.ml.entities.QueueSettings :param kwargs: A dictionary of additional configuration parameters. :type kwargs: dict

dump(dest: Union[str, os.PathLike, IO], **kwargs)None

Dump the job content into a file in yaml format.

Parameters

dest (Union[PathLike, str, IO[AnyStr]]) – The destination to receive this job’s content. Must be either a path to a local file, or an already-open file stream. If dest is a file path, a new file will be created, and an exception is raised if the file exists. If dest is an open file, the file will be written to directly, and an exception will be raised if the file is not writable.

set_limits(*, max_concurrent_trials: Optional[int] = None, max_total_trials: Optional[int] = None, timeout: Optional[int] = None, trial_timeout: Optional[int] = None)None

Set limits for Sweep node. Leave parameters as None if you don’t want to update corresponding values.

Parameters
  • max_concurrent_trials (int) – maximum concurrent trial number.

  • max_total_trials (int) – maximum total trial number.

  • timeout (int) – total timeout in seconds for sweep node

  • trial_timeout (int) – timeout in seconds for each trial

set_objective(*, goal: Optional[str] = None, primary_metric: Optional[str] = None)None

Set the sweep object.. Leave parameters as None if you don’t want to update corresponding values.

Parameters

goal – Defines supported metric goals for hyperparameter tuning. Acceptable values are:

“minimize”, “maximize”. :type goal: str :param primary_metric: Name of the metric to optimize. :type primary_metric: str

property base_path

Base path of the resource.

Returns

Base path of the resource

Return type

str

property creation_context

Creation context.

Returns

Creation metadata of the resource.

Return type

typing.Optional[SystemData]

property early_termination

Early termination policy for sweep job.

Returns

Early termination policy for sweep job.

Return type

EarlyTerminationPolicy

property id

Resource ID.

Returns

Global id of the resource, Azure Resource Manager ID

Return type

typing.Optional[str]

property inputs property limits

Limits for sweep job.

Returns

Limits for sweep job.

Return type

SweepJobLimits

property log_files

Job output files.

Returns

Dictionary of log names to url.

Return type

Optional[Dict[str, str]]

property outputs property sampling_algorithm

Sampling algorithm for sweep job.

Returns

Sampling algorithm for sweep job.

Return type

SamplingAlgorithm

property status

Status of the job.

Common values returned include “Running”, “Completed”, and “Failed”.

Note

  • NotStarted - This is a temporary state client-side Run objects are in before cloud submission.

  • Starting - The Run has started being processed in the cloud. The caller has a run ID at this point.

  • Provisioning - Returned when on-demand compute is being created for a given job submission.

  • Preparing - The run environment is being prepared:
    • docker image build

    • conda environment setup

  • Queued - The job is queued in the compute target. For example, in BatchAI the job is in queued state

    while waiting for all the requested nodes to be ready.

  • Running - The job started to run in the compute target.

  • Finalizing - User code has completed and the run is in post-processing stages.

  • CancelRequested - Cancellation has been requested for the job.

  • Completed - The run completed successfully. This includes both the user code and run

    post-processing stages.

  • Failed - The run failed. Usually the Error property on a run will provide details as to why.

  • Canceled - Follows a cancellation request and indicates that the run is now successfully cancelled.

  • NotResponding - For runs that have Heartbeats enabled, no heartbeat has been recently sent.

Returns

Status of the job.

Return type

str

property studio_url

Azure ML studio endpoint.

Returns

URL to the job detail page.

Return type

Optional[str]

property type

Type of the job, supported are ‘command’ and ‘sweep’.

Returns

Type of the job.

Return type

str

class azure.ai.ml.sweep.SweepJobLimits(*, max_concurrent_trials: Optional[int] = None, max_total_trials: Optional[int] = None, timeout: Optional[int] = None, trial_timeout: Optional[int] = None)[source]

Sweep Job limit class.

Variables are only populated by the server, and will be ignored when sending a request.

Parameters
  • max_concurrent_trials (int) – Sweep Job max concurrent trials.

  • max_total_trials (int) – Sweep Job max total trials.

  • timeout (int) – The max run duration in seconds , after which the job will be cancelled. Only supports duration with precision as low as Seconds.

  • trial_timeout (int) – Sweep Job Trial timeout value in seconds.

Example:

Assigning limits to a SweepJob
from azure.ai.ml.entities import CommandJob from azure.ai.ml.sweep import BayesianSamplingAlgorithm, Objective, SweepJob, SweepJobLimits command_job = CommandJob( inputs=dict(kernel="linear", penalty=1.0), compute=cpu_cluster, environment=f"{job_env.name}:{job_env.version}", code="./scripts", command="python scripts/train.py --kernel $kernel --penalty $penalty", experiment_name="sklearn-iris-flowers", ) sweep = SweepJob( sampling_algorithm=BayesianSamplingAlgorithm(), trial=command_job, search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])}, inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}}, compute="top_level", limits=SweepJobLimits(trial_timeout=600), objective=Objective(goal="maximize", primary_metric="accuracy"), ) 

Sweep Job limit class.

Parameters
  • max_concurrent_trials (int) – Sweep Job max concurrent trials.

  • max_total_trials (int) – Sweep Job max total trials.

  • timeout – The max run duration in seconds , after which the job will be cancelled.

Only supports duration with precision as low as Seconds. :type timeout: int :param trial_timeout: Sweep Job Trial timeout value in seconds. :type trial_timeout: int

property timeout property trial_timeout class azure.ai.ml.sweep.TruncationSelectionPolicy(*, delay_evaluation: Optional[int] = 0, evaluation_interval: Optional[int] = 0, truncation_percentage: Optional[int] = 0)[source]

Defines an early termination policy that cancels a given percentage of runs at each evaluation interval.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation. Defaults to 0.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations. Defaults to 0.

  • truncation_percentage (int) – The percentage of runs to cancel at each evaluation interval. Defaults to 0.

Defines an early termination policy that cancels a given percentage of runs at each evaluation interval.

Parameters
  • delay_evaluation (int) – Number of intervals by which to delay the first evaluation.

  • evaluation_interval (int) – Interval (number of runs) between policy evaluations.

  • truncation_percentage (int) – The percentage of runs to cancel at each evaluation interval.

class azure.ai.ml.sweep.Uniform(min_value: Optional[float] = None, max_value: Optional[float] = None, **kwargs)[source]

Uniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the distribution.

  • max_value (float) – Maximum value of the distribution.

Uniform distribution configuration.

Parameters
  • min_value (float) – Minimum value of the distribution.

  • max_value (float) – Maximum value of the distribution.

ncG1vNJzZmiZqqq%2Fpr%2FDpJuom6Njr627wWeaqKqVY8SqusOorqxmnprBcHDWnploqKmptbC6jpqxrqqVYq6qecylZmpmaGN9cK3ZrqmeZpGee664jayunp2gY7W1ucs%3D