当尝试运行ScriptRunConfig时,请使用:
src = ScriptRunConfig(source_directory=project_folder,
script='train.py',
arguments=['--input-data-dir', ds.as_mount(),
'--reg', '0.99'],
run_config=run_config)
run = experiment.submit(config=src)当我提交这份工作时,它不起作用,并与此断断续续:
... lots of things... and then
TypeError: Object of type 'DataReference' is not JSON serializable不过,如果我用估计器运行它,它就能工作。其中一个不同之处在于,对于ScriptRunConfig,我们使用一个列表作为参数,而另一个是字典。
谢谢你的指点!
发布于 2019-09-20 02:14:46
能够在DataReference中使用ScriptRunConfig比只使用ds.as_mount()要复杂一些。您将需要将其转换为arguments中的字符串,然后使用从ds创建的DataReferenceConfiguration更新RunConfiguration的data_references部分。
如果您只是从输入位置读取,而不对其进行任何写入,请查看Dataset。它允许你做你正在做的事情而不做任何额外的事情。这里是一个例子笔记本,它在行动中显示这一点。
下面是笔记本的一个简短版本。
from azureml.core import Dataset
# more imports and code
ds = Datastore(workspace, 'mydatastore')
dataset = Dataset.File.from_files(path=(ds, 'path/to/input-data/within-datastore'))
src = ScriptRunConfig(source_directory=project_folder,
script='train.py',
arguments=['--input-data-dir', dataset.as_named_input('input').as_mount(),
'--reg', '0.99'],
run_config=run_config)
run = experiment.submit(config=src)发布于 2021-01-14 16:44:55
您可以在正式文档中看到此链接how-to-migrate-from-estimators-to-scriptrunconfig。
在ScriptRunConfig中使用DataReference的核心代码是
# if you want to pass a DataReference object, such as the below:
datastore = ws.get_default_datastore()
data_ref = datastore.path('./foo').as_mount()
src = ScriptRunConfig(source_directory='.',
script='train.py',
arguments=['--data-folder', str(data_ref)], # cast the DataReference object to str
compute_target=compute_target,
environment=pytorch_env)
src.run_config.data_references = {data_ref.data_reference_name: data_ref.to_config()} # set a dict of the DataReference(s) you want to the `data_references` attribute of the ScriptRunConfig's underlying RunConfiguration object.https://stackoverflow.com/questions/58019308
复制相似问题