Command 類別

命令節點的基類,用於命令元件版本取用。

您不應該直接具現化此類別。 相反地,您應該使用 builder 函式:command () 來建立它。

繼承
azure.ai.ml.entities._builders.base_node.BaseNode
Command
azure.ai.ml.entities._job.pipeline._io.mixin.NodeWithGroupInputMixin
Command

建構函式

Command(*, component: str | CommandComponent, compute: str | None = None, inputs: Dict[str, Input | str | bool | int | float | Enum] | None = None, outputs: Dict[str, str | Output] | None = None, limits: CommandJobLimits | None = None, identity: ManagedIdentityConfiguration | AmlTokenConfiguration | UserIdentityConfiguration | None = None, distribution: Dict | MpiDistribution | TensorFlowDistribution | PyTorchDistribution | RayDistribution | None = None, environment: Environment | str | None = None, environment_variables: Dict | None = None, resources: JobResourceConfiguration | None = None, services: Dict[str, JobService | JupyterLabJobService | SshJobService | TensorBoardJobService | VsCodeJobService] | None = None, queue_settings: QueueSettings | None = None, **kwargs)

參數

component
Union[str, CommandComponent]

要針對步驟執行的命令元件或作業的識別碼或實例。

compute
Optional[str]

作業將執行的計算目標。

inputs
Optional[dict[str, Union[ Input, str, bool, int, float, <xref:Enum>]]]

輸入名稱與作業中使用的輸入資料來源對應。

outputs
Optional[dict[str, Union[str, Output]]]

輸出名稱與作業中使用的輸出資料來源對應。

limits
CommandJobLimits

命令元件或作業的限制。

identity
Optional[Union[ dict[str, str], ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]]

在計算上執行時,命令作業將使用的身分識別。

environment
Optional[Union[str, Environment]]

作業將執行的環境。

environment_variables
Optional[dict[str, str]]

環境變數名稱和值的字典。 這些環境變數是在執行使用者腳本的程式上設定。

resources
Optional[JobResourceConfiguration]

命令的計算資源組態。

services
Optional[dict[str, Union[JobService, JupyterLabJobService, SshJobService, TensorBoardJobService, VsCodeJobService]]]

節點的互動式服務。 這是實驗性參數,隨時可能會變更。 請參閱 https://aka.ms/azuremlexperimental 以取得詳細資訊。

queue_settings
Optional[QueueSettings]

作業的佇列設定。

方法

clear
copy
dump

以 YAML 格式將作業內容傾印到檔案中。

fromkeys

建立新的字典,其中包含可反覆運算的索引鍵,並將值設定為 value。

get

如果索引鍵位於字典中,則傳回索引鍵的值,否則為預設值。

items
keys
pop

如果找不到索引鍵,則傳回指定的預設值;否則,請引發 KeyError。

popitem

將 (索引鍵、值) 組移除並傳回為 2 元組。

以 LIFO (先出) 順序傳回配對。 如果聽寫是空的,則會引發 KeyError。

set_limits

設定 Command 的限制。

set_queue_settings

設定作業的 QueueSettings。

set_resources

設定 Command 的資源。

setdefault

如果索引鍵不在字典中,則插入值為預設值的索引鍵。

如果索引鍵位於字典中,則傳回索引鍵的值,否則為預設值。

sweep

將命令轉換成具有額外掃掠執行設定的掃掠節點。 目前命令節點中的命令元件將用來作為其試用元件。 命令節點可以多次掃掠,而產生的掃掠節點將會共用相同的試用元件。

update

如果 E 存在且具有 .keys () 方法,則執行: e: D[k] = E[k] 如果 E 存在且缺少 .keys () 方法,則會執行: for k, v in E: D[k] = v 在任一案例中,後面接著: f: D[k] = F[k]

values

clear

clear() -> None.  Remove all items from D.

copy

copy() -> a shallow copy of D

dump

以 YAML 格式將作業內容傾印到檔案中。

dump(dest: str | PathLike | IO, **kwargs) -> None

參數

dest
Union[<xref:PathLike>, str, IO[AnyStr]]
必要

要寫入 YAML 內容的本機路徑或檔案資料流程。 如果 dest 是檔案路徑,將會建立新的檔案。 如果 dest 是開啟的檔案,則會直接將檔案寫入。

kwargs
dict

要傳遞至 YAML 序列化程式的其他引數。

例外狀況

如果 dest 是檔案路徑且檔案已經存在,則會引發 。

如果 dest 是開啟的檔案,而且檔案無法寫入,則引發。

fromkeys

建立新的字典,其中包含可反覆運算的索引鍵,並將值設定為 value。

fromkeys(value=None, /)

參數

type
必要
iterable
必要
value
預設值: None

get

如果索引鍵位於字典中,則傳回索引鍵的值,否則為預設值。

get(key, default=None, /)

參數

key
必要
default
預設值: None

items

items() -> a set-like object providing a view on D's items

keys

keys() -> a set-like object providing a view on D's keys

pop

如果找不到索引鍵,則傳回指定的預設值;否則,請引發 KeyError。

pop(k, [d]) -> v, remove specified key and return the corresponding value.

popitem

將 (索引鍵、值) 組移除並傳回為 2 元組。

以 LIFO (先出) 順序傳回配對。 如果聽寫是空的,則會引發 KeyError。

popitem()

set_limits

設定 Command 的限制。

set_limits(*, timeout: int, **kwargs) -> None

參數

timeout
int

作業的逾時,以秒為單位。

範例

在命令上設定 10 秒的逾時限制。


   from azure.ai.ml import Input, Output, command

   command_node = command(
       environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33",
       command='echo "hello world"',
       distribution={"type": "Pytorch", "process_count_per_instance": 2},
       inputs={
           "training_data": Input(type="uri_folder"),
           "max_epochs": 20,
           "learning_rate": 1.8,
           "learning_rate_schedule": "time-based",
       },
       outputs={"model_output": Output(type="uri_folder")},
   )

   command_node.set_limits(timeout=10)

set_queue_settings

設定作業的 QueueSettings。

set_queue_settings(*, job_tier: str | None = None, priority: str | None = None) -> None

參數

job_tier
Optional[str]

作業層。 接受的值是 「Spot」、「Basic」、「Standard」 或 「Premium」。

priority
Optional[str]

計算上作業的優先順序。 預設為 「Medium」。

範例

在命令上設定佇列設定。


   from azure.ai.ml import Input, Output, command

   command_node = command(
       environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33",
       command='echo "hello world"',
       distribution={"type": "Pytorch", "process_count_per_instance": 2},
       inputs={
           "training_data": Input(type="uri_folder"),
           "max_epochs": 20,
           "learning_rate": 1.8,
           "learning_rate_schedule": "time-based",
       },
       outputs={"model_output": Output(type="uri_folder")},
   )

   command_node.set_queue_settings(job_tier="standard", priority="medium")

set_resources

設定 Command 的資源。

set_resources(*, instance_type: str | List[str] | None = None, instance_count: int | None = None, locations: List[str] | None = None, properties: Dict | None = None, docker_args: str | None = None, shm_size: str | None = None, **kwargs) -> None

參數

instance_type
Optional[Union[str, list[str]]]

要執行作業的計算實例類型。 如果未指定,作業將會在預設計算目標上執行。

instance_count
Optional[int]

要執行作業的實例數目。 如果未指定,作業將會在單一實例上執行。

locations
Optional[list[str]]

作業將執行的位置清單。 如果未指定,作業將會在預設計算目標上執行。

properties
Optional[dict]

作業的屬性。

docker_args
Optional[str]

作業的 Docker 引數。

shm_size
Optional[str]

Docker 容器的共用記憶體區塊大小。 這應該是 (number) (單位) 的格式,其中數位必須大於 0,而單位可以是 b (位元組) 、k (kb) 、m (MB) 或 g (GB) 。

範例

在命令上設定資源。


   from azure.ai.ml import Input, Output, command

   command_node = command(
       environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33",
       command='echo "hello world"',
       distribution={"type": "Pytorch", "process_count_per_instance": 2},
       inputs={
           "training_data": Input(type="uri_folder"),
           "max_epochs": 20,
           "learning_rate": 1.8,
           "learning_rate_schedule": "time-based",
       },
       outputs={"model_output": Output(type="uri_folder")},
   )

   command_node.set_resources(
       instance_count=1,
       instance_type="STANDARD_D2_v2",
       properties={"key": "new_val"},
       shm_size="3g",
   )

setdefault

如果索引鍵不在字典中,則插入值為預設值的索引鍵。

如果索引鍵位於字典中,則傳回索引鍵的值,否則為預設值。

setdefault(key, default=None, /)

參數

key
必要
default
預設值: None

sweep

將命令轉換成具有額外掃掠執行設定的掃掠節點。 目前命令節點中的命令元件將用來作為其試用元件。 命令節點可以多次掃掠,而產生的掃掠節點將會共用相同的試用元件。

sweep(*, primary_metric: str, goal: str, sampling_algorithm: str = 'random', compute: str | None = None, max_concurrent_trials: int | None = None, max_total_trials: int | None = None, timeout: int | None = None, trial_timeout: int | None = None, early_termination_policy: EarlyTerminationPolicy | str | None = None, search_space: Dict[str, Choice | LogNormal | LogUniform | Normal | QLogNormal | QLogUniform | QNormal | QUniform | Randint | Uniform] | None = None, identity: ManagedIdentityConfiguration | AmlTokenConfiguration | UserIdentityConfiguration | None = None, queue_settings: QueueSettings | None = None, job_tier: str | None = None, priority: str | None = None) -> Sweep

參數

primary_metric
str

掃掠目標的主要計量,例如 AUC (曲線下的區域) 。 執行試用元件時,必須記錄計量。

goal
str

掃掠目標的目標。 接受的值是「最小化」或「最大化」。

sampling_algorithm
str

搜尋空間內要使用的取樣演算法。 可接受的值為 「random」、「grid」 或 「bayesian」。 預設為 「random」。

compute
Optional[str]

要執行節點的目標計算。 如果未指定,則會使用目前節點的計算。

max_total_trials
Optional[int]

要執行的試用版總數上限。 如果指定,此值將會覆寫 CommandJob.limits 中的值。

max_concurrent_trials
Optional[int]

掃掠作業的並行試用版數目上限。

timeout
Optional[int]

執行時間上限,以秒為單位,之後作業將會取消。

trial_timeout
Optional[int]

[掃掠作業試用逾時] 值,以秒為單位。

early_termination_policy
Optional[Union[BanditPolicy, TruncationSelectionPolicy, MedianStoppingPolicy, str]]

掃掠節點的早期終止原則。 可接受的值為 「bandit」、「median_stopping」 或 「truncation_selection」。 預設為 [無]。

identity
Optional[Union[ ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]]

在計算上執行時,作業將使用的身分識別。

queue_settings
Optional[QueueSettings]

作業的佇列設定。

job_tier
Optional[str]

實驗 作業層。 接受的值為 「Spot」、「Basic」、「Standard」 或 「Premium」。

priority
Optional[str]

實驗 計算優先順序。 接受的值為 「low」、「medium」 和 「high」。

傳回

具有目前命令節點元件做為其試用元件的掃掠節點。

傳回類型

範例

從命令作業建立掃掠節點。


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

update

如果 E 存在且具有 .keys () 方法,則執行: e: D[k] = E[k] 如果 E 存在且缺少 .keys () 方法,則會執行: for k, v in E: D[k] = v 在任一案例中,後面接著: f: D[k] = F[k]

update([E], **F) -> None.  Update D from dict/iterable E and F.

values

values() -> an object providing a view on D's values

屬性

base_path

資源的基底路徑。

傳回

資源的基底路徑。

傳回類型

str

code

要執行作業的原始程式碼。

傳回類型

command

設定要執行的命令。

傳回類型

component

要針對步驟執行的命令元件或作業的識別碼或實例。

傳回

要針對步驟執行的命令元件或作業的識別碼或實例。

傳回類型

creation_context

資源的建立內容。

傳回

資源的建立中繼資料。

傳回類型

distribution

分散式命令元件或作業的組態。

傳回

分散式作業的組態。

傳回類型

id

資源識別碼。

傳回

資源的全域識別碼,Azure Resource Manager (ARM) 識別碼。

傳回類型

identity

在計算上執行時,作業將使用的身分識別。

傳回

在計算上執行時,作業將使用的身分識別。

傳回類型

inputs

取得 物件的輸入。

傳回

字典,包含 物件的輸入。

傳回類型

log_files

作業輸出檔案。

傳回

記錄名稱和 URL 的字典。

傳回類型

name

取得節點的名稱。

傳回

節點的名稱。

傳回類型

str

outputs

取得 物件的輸出。

傳回

字典,包含 物件的輸出。

傳回類型

parameters

在作業期間要記錄的 MLFlow 參數。

傳回

作業期間要記錄的 MLFlow 參數。

傳回類型

queue_settings

命令元件或作業的佇列設定。

傳回

命令元件或作業的佇列設定。

傳回類型

resources

命令元件或作業的計算資源組態。

傳回類型

services

節點的互動式服務。

這是實驗性參數,隨時可能會變更。 請參閱 https://aka.ms/azuremlexperimental 以取得詳細資訊。

傳回類型

status

工作的狀態。

傳回的常見值包括「執行中」、「已完成」和「失敗」。 所有可能的值為:

  • NotStarted - 這是用戶端 Run 物件在雲端提交之前所在的暫時狀態。

  • 啟動 - 執行已在雲端中開始處理。 呼叫端此時具有執行識別碼。

  • 布建 - 正在針對指定的作業提交建立隨選計算。

  • 準備 - 正在準備執行環境,且處於兩個階段之一:

    • Docker 映射組建

    • conda 環境設定

  • 已排入佇列 - 作業已排入計算目標上的佇列。 例如,在 BatchAI 中,作業處於佇列狀態

    等候所有要求的節點準備就緒時。

  • 執行 - 作業已開始在計算目標上執行。

  • 完成 - 使用者程式碼執行已完成,且執行處於後續處理階段。

  • CancelRequested - 作業已要求取消。

  • 已完成 - 執行已順利完成。 這包括使用者程式碼執行和執行

    後續處理階段。

  • 失敗 - 執行失敗。 執行上的 Error 屬性通常會提供原因的詳細資料。

  • 已取消 - 遵循取消要求,並指出現在已成功取消執行。

  • NotResponding - 針對已啟用活動訊號的執行,最近不會傳送活動訊號。

傳回

作業的狀態。

傳回類型

studio_url

Azure ML Studio 端點。

傳回

作業詳細資料頁面的 URL。

傳回類型

type

作業的類型。

傳回

作業的類型。

傳回類型