6

我使用 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)

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

'enabled' is deprecated. Please use the azureml.core.runconfig.DockerConfiguration object with the 'use_docker' param instead.

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

我不知道如何使用该azureml.core.runconfig.DockerConfiguration对象。有人可以给我一个例子吗?谢谢!

4

2 回答 2

9

该类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)
于 2021-05-06T14:23:42.350 回答
4

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

改变:

run_config = RunConfiguration()
run_config.environment.docker.enabled = True

到:

run_config = RunConfiguration()
docker_config = DockerConfiguration(use_docker=True)
run_config.docker = docker_config

run_config以后可以用作例如 PythonScriptStep 的参数。

请注意,docker 属性从内部移动environmentRunConfiguration直接。

于 2021-08-11T19:03:00.500 回答