如何在 ML Azure Pipeline 中使用环境

How do I use an environment in an ML Azure Pipeline

背景

我已经从 conda environment.yml 加上一些 docker 配置和环境变量创建了一个 ML Workspace 环境。我可以从 Python 笔记本中访问它:

env = Environment.get(workspace=ws, name='my-environment', version='1')

我可以成功地使用它来 运行 一个 Python 脚本作为实验,即

runconfig = ScriptRunConfig(source_directory='script/', script='my-script.py', arguments=script_params)
runconfig.run_config.target = compute_target
runconfig.run_config.environment = env
run = exp.submit(runconfig)

问题

我现在想要 运行 这个相同的脚本作为管道,这样我就可以用不同的参数触发多个 运行。我创建了如下管道:

pipeline_step = PythonScriptStep(
    source_directory='script', script_name='my-script.py',
    arguments=['-a', param1, '-b', param2],
    compute_target=compute_target,
    runconfig=runconfig
)
steps = [pipeline_step]
pipeline = Pipeline(workspace=ws, steps=steps)
pipeline.validate()

当我尝试 运行 管道时:

pipeline_run = Experiment(ws, 'my_pipeline_run').submit(
    pipeline, pipeline_parameters={...}
)

我收到以下错误:Response status code does not indicate success: 400 (Conda dependencies were not specified. Please make sure that all conda dependencies were specified i).

当我在 Azure 门户中查看管道 运行 时,似乎还没有选择环境:none 我的 conda 依赖项已配置,因此代码没有 运行.我做错了什么?

您快完成了,但是您需要使用 RunConfiguration 而不是 ScriptRunConfig。更多信息 here

from azureml.core.runconfig import RunConfiguration

env = Environment.get(workspace=ws, name='my-environment', version='1')
# create a new runconfig object
runconfig = RunConfiguration()
runconfig.environment = env

pipeline_step = PythonScriptStep(
    source_directory='script', script_name='my-script.py',
    arguments=['-a', param1, '-b', param2],
    compute_target=compute_target,
    runconfig=runconfig
)

pipeline = Pipeline(workspace=ws, steps=[pipeline_step])

pipeline_run = Experiment(ws, 'my_pipeline_run').submit(pipeline)