如何在 azureml.core.Environment 或 azureml.core.ScriptRunConfig 类中使用 azureml.core.runco​​nfig.DockerConfiguration 类

Ste*_*fan 3 python azure-machine-learning-service azureml azureml-python-sdk

我使用 Microsoft Azure 机器学习 (Azure-ml) 来运行我的 (python) 实验。

为了指定我使用的 VM 和 python 环境:

from azureml.core import Environment
from azureml.core import ScriptRunConfig

# Other imports and code...

# Specify VM and Python environment:
vm_env = Environment.from_conda_specification(name='my-test-env', file_path=PATH_TO_YAML_FILE)
vm_env.docker.enabled = True
vm_env.docker.base_image = 'mcr.microsoft.com/azureml/openmpi3.1.2-cuda10.2-cudnn7-ubuntu18.04'

# Finally, use the environment in the ScriptRunConfig:
src = ScriptRunConfig(source_directory=DEPLOY_CONTAINER_FOLDER_PATH,
                      script=SCRIPT_FILE_TO_EXECUTE,
                      arguments=EXECUTE_ARGUMENTS,
                      compute_target=compute_target,
                      environment=vm_env)
Run Code Online (Sandbox Code Playgroud)

我收到该行的以下警告vm_env.docker.enabled = True

'enabled' is deprecated. Please use the azureml.core.runconfig.DockerConfiguration object with the 'use_docker' param instead.
Run Code Online (Sandbox Code Playgroud)

关于DockerSection Class和的文档对于DockerConfiguration Class应用DockerConfiguration Class.

我无法弄清楚如何使用该azureml.core.runconfig.DockerConfiguration对象。有人可以为我提供一个例子吗?谢谢!

小智 9

为使用 RunConfiguration 的任何人添加另一个示例:

改变:

run_config = RunConfiguration()
run_config.environment.docker.enabled = True
Run Code Online (Sandbox Code Playgroud)

到:

run_config = RunConfiguration()
docker_config = DockerConfiguration(use_docker=True)
run_config.docker = docker_config
Run Code Online (Sandbox Code Playgroud)

run_config稍后可以用作 PythonScriptStep 等的参数。

请注意,docker 属性从内部移至environment直接RunConfiguration


小智 6

ScriptRunConfig班现在接受一个docker_runtime_config参数,它是你传递DockerConfiguration的对象。

所以,代码看起来像这样:

from azureml.core import Environment
from azureml.core import ScriptRunConfig
from azureml.core.runconfig import DockerConfiguration

# Other imports and code...

# Specify VM and Python environment:
vm_env = Environment.from_conda_specification(name='my-test-env', file_path=PATH_TO_YAML_FILE)
vm_env.docker.base_image = 'mcr.microsoft.com/azureml/openmpi3.1.2-cuda10.2-cudnn7-ubuntu18.04'

docker_config = DockerConfiguration(use_docker=True)

# Finally, use the environment in the ScriptRunConfig:
src = ScriptRunConfig(source_directory=DEPLOY_CONTAINER_FOLDER_PATH,
                      script=SCRIPT_FILE_TO_EXECUTE,
                      arguments=EXECUTE_ARGUMENTS,
                      compute_target=compute_target,
                      environment=vm_env,
                      docker_runtime_config=docker_config)
Run Code Online (Sandbox Code Playgroud)