Stefan
Stefan

Reputation: 1225

How to use azureml.core.runconfig.DockerConfiguration class in azureml.core.Environment or azureml.core.ScriptRunConfig class

I use Microsoft Azure Machine Learning (Azure-ml) to run my (python) experiments.

For specifying the VM and python environment I use:

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)

I get the following warning for the line vm_env.docker.enabled = True:

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

The documentation about the DockerSection Class and DockerConfiguration Class is not very clear about applying the DockerConfiguration Class.

I can't figure out how to use the azureml.core.runconfig.DockerConfiguration object. Can someone provide me with an example? Thank you!

Upvotes: 10

Views: 4505

Answers (2)

Moshe Zvi
Moshe Zvi

Reputation: 446

Adding another example for anyone using RunConfiguration:

Change:

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

To:

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

run_config can later be used as a parameter for e.g. PythonScriptStep.

Note that the docker attribute moved from the internal environment to the RunConfiguration directly.

Upvotes: 9

Erik Z
Erik Z

Reputation: 412

The ScriptRunConfig class now accepts a docker_runtime_config argument, which is where you pass the DockerConfiguration object.

So, the code would look something like this:

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)

Upvotes: 14

Related Questions