MachineLearningNotebooks icon indicating copy to clipboard operation
MachineLearningNotebooks copied to clipboard

How pass runconfig's dataReferences to Estimator class

Open dataders opened this issue 7 years ago • 5 comments

the how-to-access-data tutorial section on access datastores for training gives two examples:

  1. where the ds is referenced in a script parameter, and
  2. where the ds is referenced in the input

example 1

from azureml.train.estimator import Estimator

script_params = {
    '--data_dir': ds.as_mount()
}

est = Estimator(source_directory='your code directory',
                script_params=script_params,
                compute_target=compute_target,
                entry_script='train.py')

example 2

est = Estimator(source_directory='your code directory',
                compute_target=compute_target,
                entry_script='train.py',
                inputs=[
                    ds1.as_download(),
                    ds2.path('./foo').as_download(),
                    ds3.as_upload(path_on_compute='./bar.pkl')
                    ]
           )

What is the best way to have a --data_dir param and use a datareference from an already made runconfig?

dataReferences:
  workspaceblobstore:
# Name of the datastore.
    dataStoreName: workspaceblobstore
# relative path on the datastore.
    pathOnDataStore: attrition/output
# operation on the datastore, mount, download, upload
    mode: download
# whether to overwrite the data if existing
    overwrite: false
# the path on the compute target.
    pathOnCompute: /temp

Question

This is the best i've gotten so far, but it seems so redundant. I'm stating to question the point of an already created runconfig if Estimator class just creates a new runconfig anyway? My real objective is how to reduce all the copy-pasta'd boilerplate code

est_config_aml_3 = Estimator(
    source_directory = "./compute",
    entry_script= "train.py",
    script_params = {
            "--data-folder": "workspaceblobstore/temp/output",
            "--objective": "binary"
        },
    compute_target = cpuCluster,
    environment_definition = cfg_run_aml.environment,
    inputs = [(Datastore(ws, "workspaceblobstore")
             .path('attrition/output')
             .as_download(path_on_compute='temp/output')
        )]
)

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

dataders avatar Feb 12 '19 22:02 dataders

Is this what you are looking for?

dr = cfg_run_aml.data_references['workspaceblobstore']
ds = Datastore(ws, dr.datastore_name)

est_config_aml_3 = Estimator(
    source_directory = "./compute",
    entry_script= "train.py",
    script_params = {
            "--data-folder": str(ds.path(dr.path_on_data_store).as_download(dr.path_on_compute)),
            "--objective": "binary"
        },
    compute_target = cpuCluster,
    environment_definition = cfg_run_aml.environment
)

hning86 avatar Feb 13 '19 15:02 hning86

@hning86, totally agree your example would also work. After carefully reading the docs, I learned why both our examples work.

Any ds or ds.path object resolves to an environment variable name of the format "$AZUREML_DATAREFERENCE_XXXX" whose value represents the mount/download path on the remote compute.

I think there is a need for documentation on how to use the inputs and outputs within Pipelines. What is best practice if porting an Estimator into a pipeline as an EstimatorStep? Does one always need to pass the DataReference as a script argument and as an input?

cc: @heatherbshapiro @clmccart

p.s. as someone who has been forced into using ML studio for something, azuremlps has been a lifesaver.

dataders avatar Mar 15 '19 00:03 dataders

cc @sanpil

yanrez avatar Mar 26 '19 21:03 yanrez

@sanpil can you confirm if the docs have been updated and/or if this issue should be closed?

swinner95 avatar May 22 '19 04:05 swinner95

Sorry, I missed this completely. Our sample notebook also shows passing DataReference, but there should be no limitation on this. Let me know if you found otherwise as documented here.

sanpil avatar May 22 '19 04:05 sanpil