我正在尝试从 Blob Storage 读取文件,加载到 pandas 并将其写入 BlobStorage
我有一个带有 PythonScriptStep 的 Azure 机器学习管道,它采用 2 个 PipelineParameters 并且是如下的 DataPath。
from azureml.core import Datastore from azureml.data.datapath import DataPath, DataPathComputeBinding, DataReference from azureml.pipeline.core import PipelineParameter datastore = Datastore(ws, "SampleStore") in_raw_path_default = 'somefolder/raw/alerts/2020/08/03/default_in.csv' in_cleaned_path_default= 'somefolder/cleaned/alerts/2020/08/03/default_out.csv' in_raw_datapath = DataPath(datastore=datastore, path_on_datastore=in_raw_path_default) in_raw_path_pipelineparam = PipelineParameter(name="inrawpath", default_value=in_raw_datapath) raw_datapath_input = (in_raw_path_pipelineparam, DataPathComputeBinding(mode='mount')) in_cleaned_datapath = DataPath(datastore=datastore, path_on_datastore=in_cleaned_path_default) in_cleaned_path_pipelineparam = PipelineParameter(name="incleanedpath", default_value=in_cleaned_datapath) cleaned_datapath_input = (in_cleaned_path_pipelineparam, DataPathComputeBinding(mode='mount')) from azureml.pipeline.steps import PythonScriptStep source_directory = script_folder + '/pipeline_Steps' dataprep_step = PythonScriptStep( script_name="SimpleTest.py", arguments=["--input_data", raw_datapath_input, "--cleaned_data", cleaned_datapath_input], inputs=[raw_datapath_input, cleaned_datapath_input], compute_target=default_compute, source_directory=source_directory, runconfig=run_config, allow_reuse=True ) from azureml.pipeline.core import Pipeline pipeline_test = Pipeline(workspace=ws, steps=[dataprep_step]) test_raw_path = DataPath(datastore=datastore, path_on_datastore='samplefolder/raw/alerts/2017/05/31/test.csv') test_cleaned_path = DataPath(datastore=datastore, path_on_datastore='samplefolder/cleaned/alerts/2020/09/03') pipeline_run_msalerts = Experiment(ws, 'SampleExperiment').submit(pipeline_test, pipeline_parameters={"inrawpath" : test_raw_path, "incleanedpath" : test_cleaned_path})```
这是使用的脚本(SimpleTest.py):
import os
import sys
import argparse
import pathlib
import azureml.core
import pandas as pd
parser = argparse.ArgumentParser("datapreponly")
parser.add_argument("--input_data", type=str)
parser.add_argument("--cleaned_data", type=str)
args = parser.parse_args()
print("Argument 1: %s" % args.input_data)
print("Argument 2: %s" % args.cleaned_data)
testDf = pd.read_csv(args.input_data, error_bad_lines=False)
print('Total Data Shape' + str(testDf.shape))
if not (args.cleaned_data is None):
output_path = args.cleaned_data
os.makedirs(output_path, exist_ok=True)
outdatapath = output_path + '/alert.csv'
testDf.to_csv(outdatapath, index=False)
从 AzureDataFactory 触发此 AzureMLipeline:
通过在 AzureMLWorkspace/PipelineSDK 中执行 ML 管道,上述代码可以正常工作。我正在尝试从 AzureDataFactory(AzureMachineLearningExecutePipeline) 活动触发 AzureMLpipeline,如下所示
通过传递 2 个字符串输入路径rawdatapath = "samplefolder/raw/alerts/2017/05/31/test.csv"
cleandatapath = "samplefolder/raw/cleaned/2020/09/03/"尝试调试运行如下
Current directory: /mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/workspaceblobstore/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade
Preparing to call script [ SimpleTest.py ]
with arguments:
['--input_data', '/mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/raw/alerts/2020/08/03/default_in.csv',
'--cleaned_data', '/mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/cleaned/alerts/2020/08/03/default_out.csv']
After variable expansion, calling script [ SimpleTest.py ] with arguments:
['--input_data', '/mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/raw/alerts/2020/08/03/default_in.csv',
'--cleaned_data', '/mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/cleaned/alerts/2020/08/03/default_out.csv']
Script type = None
Argument 1: /mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/raw/alerts/2020/08/03/default_in.csv
Argument 2: /mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/cleaned/alerts/2020/08/03/default_out.csv
.......................
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/batch/tasks/shared/LS_root/jobs/myazuremlworkspace/azureml/d8ee11ea-5838-46e5-a8ce-da2fbff5aade/mounts/SampleStore/somefolder/raw/alerts/2020/08/03/default_in.csv'
它表明采用默认路径而不是管道参数(没有这样的文件或目录错误不太重要,因为要点是采用默认路径而不是管道参数)。我怀疑它是因为将管道参数作为字符串而不是数据路径传递。
最后的问题:如何将数据路径从 Azure 数据工厂传递给 AzureMLipelineActivity?
谢谢。