首页 > 解决方案 > 如何将参数传递给 Azure 机器学习服务中的训练脚本?

问题描述

我正在尝试使用工作区中的对象在Azure VM 上本地提交 Azure 机器学习服务中的实验,如ScriptRunConfigws

from azureml.core import ScriptRunConfig    
from azureml.core.runconfig import RunConfiguration
from azureml.core import Experiment

experiment = Experiment(ws, name='test')
run_local = RunConfiguration()

script_params = {
    '--data-folder': './data',
    '--training-data': 'train.csv'
}

src = ScriptRunConfig(source_directory = './source_dir', 
                      script = 'train.py', 
                      run_config = run_local, 
                      arguments = script_params)

run = experiment.submit(src)

但是,这失败了

ExperimentExecutionException: { "error_details": { "correlation": { "operation": "bb12f5b8bd78084b9b34f088a1d77224", "request": "iGfp+sjC34Q=" }, "error": { "code": "UserError", "message": “无法反序列化运行定义”

更糟糕的是,如果我将数据文件夹设置为使用数据存储(我可能需要这样做)

script_params = {
    '--data-folder': ds.path('mydatastoredir').as_mount(),
    '--training-data': 'train.csv'
}

错误是

UserErrorException:runco​​nfigs 中不支持具有非本机 python 类型值的字典。
{'--data-folder': $AZUREML_DATAREFERENCE_d93269a580ec4ecf97be428cd2fe79, '--training-data': 'train.csv'}

我不太明白我应该如何将我的script_params参数传递给我的train.py(不幸的是,文档中ScriptRunConfig没有包含很多细节)。

有人知道如何src在这两种情况下正确创建吗?

标签: pythonazureazure-machine-learning-service

解决方案


最后我放弃ScriptRunConfig并使用Estimator如下方式通过script_params(在提供了计算目标之后):

estimator = Estimator(source_directory='./mysourcedir',
                      script_params=script_params,
                      compute_target='cluster',
                      entry_script='train.py',
                      conda_packages = ["pandas"],
                      pip_packages = ["git+https://github.com/..."], 
                      use_docker=True,
                      custom_docker_image='<mydockeraccount>/<mydockerimage>')

这也允许我通过在https://hub.docker.com/上放置一个从 Dockerfile 创建的 Docker 映像来安装我的pip_packages依赖项,例如:custom_docker_image

FROM continuumio/miniconda
RUN apt-get update
RUN apt-get install git gcc g++ -y

(有效!)


推荐阅读