RunConfiguration 類別

代表以 Azure Machine Learning 中不同計算目標為目標的實驗執行組態。

RunConfiguration 物件會封裝在實驗中提交定型回合所需的資訊。 一般而言,您不會直接建立 RunConfiguration 物件,而是從傳回它的方法取得一個,例如 submit 類別的 Experiment 方法。

RunConfiguration 是基底環境組態,也用於其他類型的組態步驟,視您觸發的執行類型而定。 例如,設定 時 PythonScriptStep ,您可以存取步驟的 RunConfiguration 物件,並設定 Conda 相依性,或存取執行的環境屬性。

如需執行組態的範例,請參閱 選取並使用計算目標來定型模型

使用預設設定初始化 RunConfiguration。

繼承
azureml._base_sdk_common.abstract_run_config_element._AbstractRunConfigElement
RunConfiguration

建構函式

RunConfiguration(script=None, arguments=None, framework=None, communicator=None, conda_dependencies=None, _history_enabled=None, _path=None, _name=None, command=None)

參數

script
str
預設值: None

Python 腳本檔案的相對路徑。 檔案路徑相對於傳遞至 submit 的來原始目錄。

arguments
list[str]
預設值: None

Python 腳本檔案的命令列引數。

framework
str
預設值: None

執行中使用的目標架構。 支援的架構包括 Python、PySpark、TensorFlow 和 PyTorch。

communicator
str
預設值: None

執行中使用的 communicator。 支援的通訊器為 None、ParameterServer、OpenMpi 和 IntelMpi。 請記住,OpenMpi 需要已安裝 OpenMpi 的自訂映射。 針對 AmlCompute 叢集使用 ParameterServer 或 OpenMpi。 使用 IntelMpi 進行分散式訓練作業。

conda_dependencies
CondaDependencies
預設值: None

當保留為 False 的預設值時,系統會建立 Python 環境,其中包含 中指定的 conda_dependencies 套件。 設定 true 時,可以使用 python_interpreter 設定來指定現有的 Python 環境。

auto_prepare_environment
bool
必要

已淘汰。 不再使用此設定。

command
list[str] 或 str
預設值: None

要針對執行提交的命令。 您也可以使用命令屬性,而不是腳本/引數。 命令和腳本/引數屬性不能一起使用來提交執行。 若要使用命令屬性提交腳本檔案 - ['python', 'train.py', '–arg1', arg1_val] 若要執行實際命令 - ['ls']

_history_enabled
預設值: None
_path
預設值: None
_name
預設值: None

備註

我們通常會建置機器學習系統來解決特定問題。 例如,我們可能會有興趣尋找排名可能做為對應查詢之搜尋結果的網頁排名最佳模型。 我們搜尋最佳的機器學習模型可能需要我們嘗試不同的演算法,或考慮不同的參數設定等等。

在 Azure Machine Learning SDK 中,我們使用實驗的概念來擷取不同定型執行與嘗試解決的問題相關的概念。 Experiment接著會作為這些定型回合的邏輯容器,讓您更輕鬆地追蹤訓練回合的進度、直接比較兩個訓練回合等等。

RunConfiguration 會封裝在實驗中提交定型回合所需的執行環境設定。 它會擷取設計來解決相同機器學習問題的定型回合共用結構,以及組態參數 (的差異,例如學習速率、遺失函式等) ,以區別不同的定型回合彼此不同。

在典型的定型案例中,RunConfiguration 是藉由建立一個 ScriptRunConfig 物件,將 RunConfiguration 物件封裝在一起,以及用來定型的執行腳本來使用。

RunConfiguration 的設定包括:

  • 將實驗來原始目錄統合,包括提交的腳本。

  • 設定所提交腳本的命令列引數。

  • 設定 Python 解譯器的路徑。

  • 取得 的 Conda 組態,以管理應用程式相依性。 作業提交程式可以使用組態來布建暫存 Conda 環境,並在其中啟動應用程式。 暫存環境會在後續執行中快取和重複使用。

  • 選擇性使用 Docker 和自訂基底映射。

  • 選擇性選擇將實驗提交至多種 Azure 計算類型。

  • 選擇性選擇設定如何具體化輸入和上傳輸出。

  • 常見執行時間的進階執行時間設定,例如 spark 和 tensorflow。

下列範例示範如何在本機電腦上提交定型腳本。


   from azureml.core import ScriptRunConfig, RunConfiguration, Experiment

   # create or load an experiment
   experiment = Experiment(workspace, "MyExperiment")
   # run a trial from the train.py code in your current directory
   config = ScriptRunConfig(source_directory='.', script='train.py',
       run_config=RunConfiguration())
   run = experiment.submit(config)

下列範例示範如何使用 命令屬性,而不是腳本和引數,在叢集上提交定型腳本。


   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)

下列範例示範如何在叢集上執行命令。


   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)

變數

environment
Environment

環境定義。 此欄位會設定 Python 環境。 它可以設定為使用現有的 Python 環境,或設定來設定實驗的暫存環境。 定義也會負責設定必要的應用程式相依性。

max_run_duration_seconds
int

執行所允許的時間上限。 如果執行時間超過此值,系統會嘗試自動取消執行。

node_count
int

要用於作業的節點數目。

priority
int

排程原則之作業的優先順序。

history
HistoryConfiguration

用來停用和啟用實驗歷程記錄功能的組態區段。

spark
SparkConfiguration

當平臺設定為 PySpark 時,會使用 Spark 組態區段來設定提交作業的預設 SparkConf。

hdi
HdiConfiguration

只有在目標設定為 Azure HDI 計算時,HDI 組態區段才會生效。 HDI 組態可用來設定 YARN 部署模式。 預設部署模式為叢集。

docker
DockerConfiguration

Docker 組態區段可用來設定 Docker 環境的變數。

tensorflow
TensorflowConfiguration

用來設定分散式 TensorFlow 參數的組態區段。 只有當 設定為 TensorFlow,並將 設為 communicator ParameterServer 時 framework ,此參數才會生效。 AmlCompute 是此組態唯一支援的計算。

mpi
MpiConfiguration

用來設定分散式 MPI 作業參數的組態區段。 只有當 設定為 Python,並將 communicator 設為 OpenMpi 或 IntelMpi 時 framework ,此參數才會生效。 AmlCompute 是這個組態唯一支援的計算類型。

pytorch
PyTorchConfiguration

用來設定分散式 PyTorch 作業參數的組態區段。 只有當 設定為 PyTorch,並將 設為 communicator Nccl 或 Gloo 時 framework ,此參數才會生效。 AmlCompute 是這個組態唯一支援的計算類型。

paralleltask
ParallelTaskConfiguration

用來設定分散式 paralleltask 作業參數的組態區段。 只有當 設定為 Python,並將 communicator 設為 ParallelTask 時 framework ,此參數才會生效。 AmlCompute 是這個組態唯一支援的計算類型。

data_references
dict[str, DataReferenceConfiguration]

根據每個組態在執行期間,所有資料來源都可供執行。 針對字典的每個專案,索引鍵是提供給資料來源的名稱,而此值為 DataReferenceConfiguration。

data
dict[str, Data]

在執行期間可供執行的所有資料使用。

datacaches
<xref:buildin.list>[DatacacheConfiguration]

所有資料,讓 datacache 可供執行期間執行。

output_data
OutputData

所有應該針對此執行上傳和追蹤的輸出。

source_directory_data_store
str

專案共用的備份資料存放區。

amlcompute
AmlComputeConfiguration

實驗期間要建立之計算目標的詳細資料。 只有在計算目標為 AmlCompute 時,設定才會生效。

kubernetescompute
KubernetesComputeConfiguration

實驗期間所要使用的計算目標詳細資料。 只有在計算目標為 KubernetesCompute 時,設定才會生效。

services
dict[str, ApplicationEndpointConfiguration]

與計算資源互動的端點。 允許的端點包括 Jupyter、JupyterLab、VS Code、Tensorboard、SSH 和自訂埠。

方法

delete

刪除執行組態檔。

UserErrorException如果找不到組態檔,則引發 。

load

從磁片上檔案載入先前儲存的執行設定檔。

如果 path 指向檔案,則會從該檔案載入 RunConfiguration。

如果 path 指向應該是專案目錄的目錄,則會從 < path/.azureml/ < name 或 < path >> /aml_config/ < name >> 載入 RunConfiguration。

save

將 RunConfiguration 儲存至磁片上的檔案。

UserErrorException當:

  • RunConfiguration 無法以指定的名稱儲存。

  • name 指定參數。

  • path 參數無效。

如果 path 格式 < 為 dir_path > / < file_name > ,其中 < dir_path > 是有效的目錄,則 RunConfiguration 會儲存在 < dir_path > / < file_name > 。

如果 path 指向應該是專案目錄的目錄,則 RunConfiguration 會儲存在 < path/.azureml/ < name 或 < path >> /aml_config/ < name >> 。

此方法在手動編輯組態或與 CLI 共用組態時很有用。

delete

刪除執行組態檔。

UserErrorException如果找不到組態檔,則引發 。

static delete(path, name)

參數

path
str
必要

使用者選取執行組態的根目錄。 這通常是 Git 存放庫或 Python 專案根目錄。 設定會從名為 .azureml 的子目錄中刪除。

name
str
必要

組態檔名稱。

例外狀況

UserErrorException

load

從磁片上檔案載入先前儲存的執行設定檔。

如果 path 指向檔案,則會從該檔案載入 RunConfiguration。

如果 path 指向應該是專案目錄的目錄,則會從 < path/.azureml/ < name 或 < path >> /aml_config/ < name >> 載入 RunConfiguration。

static load(path, name=None)

參數

path
str
必要

使用者選取執行組態的根目錄。 這通常是 Git 存放庫或 Python 專案根目錄。 為了回溯相容性,設定也會從 .azureml 或aml_config子目錄載入。 如果檔案不在那些目錄中,則會從指定的路徑載入檔案。

name
str
預設值: None

組態檔名稱。

傳回

執行組態物件。

傳回類型

例外狀況

UserErrorException

save

將 RunConfiguration 儲存至磁片上的檔案。

UserErrorException當:

  • RunConfiguration 無法以指定的名稱儲存。

  • name 指定參數。

  • path 參數無效。

如果 path 格式 < 為 dir_path > / < file_name > ,其中 < dir_path > 是有效的目錄,則 RunConfiguration 會儲存在 < dir_path > / < file_name > 。

如果 path 指向應該是專案目錄的目錄,則 RunConfiguration 會儲存在 < path/.azureml/ < name 或 < path >> /aml_config/ < name >> 。

此方法在手動編輯組態或與 CLI 共用組態時很有用。

save(path=None, name=None, separate_environment_yaml=False)

參數

separate_environment_yaml
bool
預設值: False

指出是否要儲存 Conda 環境組態。 如果為 True,Conda 環境組態會儲存至名為 'environment.yml' 的 YAML 檔案。

path
str
預設值: None

使用者選取執行組態的根目錄。 這通常是 Git 存放庫或 Python 專案根目錄。 設定會儲存至名為 .azureml 的子目錄。

name
str
預設值: None

[必要]組態檔名稱。

傳回類型

例外狀況

UserErrorException

屬性

auto_prepare_environment

auto_prepare_environment取得 參數。 這是已被取代且未使用的設定。

environment_variables

執行時間環境變數。

傳回

執行時間變數

傳回類型

target

取得排程執行作業的計算目標。

預設目標為參照本機電腦的「本機」。 您可以使用 函式 compute_targets 找到可用的雲端計算目標。

傳回

目標名稱

傳回類型

str