Command 類別
命令節點的基類,用於命令元件版本取用。
您不應該直接具現化此類別。 相反地,您應該使用 builder 函式:command () 來建立它。
- 繼承
-
azure.ai.ml.entities._builders.base_node.BaseNodeCommandazure.ai.ml.entities._job.pipeline._io.mixin.NodeWithGroupInputMixinCommand
建構函式
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]
要針對步驟執行的命令元件或作業的識別碼或實例。
- limits
- CommandJobLimits
命令元件或作業的限制。
- identity
- Optional[Union[ dict[str, str], ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]]
在計算上執行時,命令作業將使用的身分識別。
- distribution
- Optional[Union[dict, PyTorchDistribution, MpiDistribution, TensorFlowDistribution, RayDistribution]]
分散式作業的組態。
- environment
- Optional[Union[str, Environment]]
作業將執行的環境。
- 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
參數
要寫入 YAML 內容的本機路徑或檔案資料流程。 如果 dest 是檔案路徑,將會建立新的檔案。 如果 dest 是開啟的檔案,則會直接將檔案寫入。
- kwargs
- dict
要傳遞至 YAML 序列化程式的其他引數。
例外狀況
如果 dest 是檔案路徑且檔案已經存在,則會引發 。
如果 dest 是開啟的檔案,而且檔案無法寫入,則引發。
fromkeys
建立新的字典,其中包含可反覆運算的索引鍵,並將值設定為 value。
fromkeys(value=None, /)
參數
- type
- iterable
- value
get
如果索引鍵位於字典中,則傳回索引鍵的值,否則為預設值。
get(key, default=None, /)
參數
- key
- default
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
參數
範例
在命令上設定佇列設定。
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
參數
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
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」。
- early_termination_policy
- Optional[Union[BanditPolicy, TruncationSelectionPolicy, MedianStoppingPolicy, str]]
掃掠節點的早期終止原則。 可接受的值為 「bandit」、「median_stopping」 或 「truncation_selection」。 預設為 [無]。
- identity
- Optional[Union[ ManagedIdentityConfiguration, AmlTokenConfiguration, UserIdentityConfiguration]]
在計算上執行時,作業將使用的身分識別。
- queue_settings
- Optional[QueueSettings]
作業的佇列設定。
傳回
具有目前命令節點元件做為其試用元件的掃掠節點。
傳回類型
範例
從命令作業建立掃掠節點。
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
code
command
component
creation_context
distribution
分散式命令元件或作業的組態。
傳回
分散式作業的組態。
傳回類型
id
identity
在計算上執行時,作業將使用的身分識別。
傳回
在計算上執行時,作業將使用的身分識別。
傳回類型
inputs
log_files
name
outputs
parameters
queue_settings
resources
services
status
工作的狀態。
傳回的常見值包括「執行中」、「已完成」和「失敗」。 所有可能的值為:
NotStarted - 這是用戶端 Run 物件在雲端提交之前所在的暫時狀態。
啟動 - 執行已在雲端中開始處理。 呼叫端此時具有執行識別碼。
布建 - 正在針對指定的作業提交建立隨選計算。
準備 - 正在準備執行環境,且處於兩個階段之一:
Docker 映射組建
conda 環境設定
已排入佇列 - 作業已排入計算目標上的佇列。 例如,在 BatchAI 中,作業處於佇列狀態
等候所有要求的節點準備就緒時。
執行 - 作業已開始在計算目標上執行。
完成 - 使用者程式碼執行已完成,且執行處於後續處理階段。
CancelRequested - 作業已要求取消。
已完成 - 執行已順利完成。 這包括使用者程式碼執行和執行
後續處理階段。
失敗 - 執行失敗。 執行上的 Error 屬性通常會提供原因的詳細資料。
已取消 - 遵循取消要求,並指出現在已成功取消執行。
NotResponding - 針對已啟用活動訊號的執行,最近不會傳送活動訊號。
傳回
作業的狀態。
傳回類型
studio_url
type
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應