Pipeline中使用环境

Pipeline中使用环境

本文介绍了如何在ML Azure Pipeline中使用环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

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

I have created an ML Workspace environment from a conda environment.yml plus some docker config and environment variables. I can access it from within a Python notebook:

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

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

I can use this successfully to run a Python script as an experiment, i.e.

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)

问题

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

I would now like to run this same script as a Pipeline, so that I can trigger multiple runs with different parameters. I have created the Pipeline as follows:

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()

然后我尝试运行管道时:

When I then try to run the Pipeline:

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

我收到以下错误:响应状态代码未指示成功:400(未指定Conda依赖项。请确保已将所有conda依赖项指定为i)。

当我查看在Azure门户中运行的管道时,似乎尚未拾取环境:没有配置我的conda依赖项,因此代码无法运行。我在做什么错了?

When I view the pipeline run in the Azure Portal it seems that the environment has not been picked up: none of my conda dependencies are configured, hence the code does not run. What am I doing wrong?

推荐答案

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

You're almost there, but you need to use RunConfiguration instead of ScriptRunConfig. More info 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)

这篇关于如何在ML Azure Pipeline中使用环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:09