Using and Versioning Data Assets
This lesson explains how jobs reference data assets, how access modes differ, how versions keep training reproducible, and why versions are archived rather than deleted.
Learning outcomes
After completing this lesson, you will be able to:
- Reference a data asset by version or label.
- Distinguish mount from download access modes.
- Explain how to version refreshed data.
- Describe archiving and lineage.
Referencing assets in jobs
A job input refers to a data asset by name and version, as azureml:churn-data:3, or by name with a label, as azureml:churn-data@latest. Pinning a version makes the job reproducible; @latest suits a scheduled retraining pipeline that should always use the newest data. In both cases, the job records the resolved version, so lineage is kept even when a label was used.
from azure.ai.ml import Input, command
from azure.ai.ml.constants import AssetTypes, InputOutputModes
job = command(
code="./src",
command="python train.py --data ${{inputs.data}}",
inputs={"data": Input(type=AssetTypes.URI_FILE, path="azureml:churn-data:3",
mode=InputOutputModes.RO_MOUNT)},
environment="azureml:train-env:2",
compute="cpu-cluster",
)Access modes
The mode decides how the data reaches the script. The choice affects start-up time, disk use and performance, and the right mode depends on the data size and how the script reads it.
| Mode | Behaviour | Suits |
|---|---|---|
ro_mount | Mounts storage read-only; files are streamed when read | Large data, or scripts that read only part of it (default for inputs) |
download | Copies the data to the node's disk before the script starts | Small or medium data read many times, such as in several epochs |
direct | Passes the storage URI; the script reads it itself | Spark and libraries that read cloud storage natively |
rw_mount | Mounts an output location for reading and writing | Outputs written incrementally |
upload | Writes outputs locally and uploads them at the end | Outputs written once (default for outputs) |
A script receives the mount point or local path as an argument and reads it like a local file, so the same code works with either mount or download.
Versioning practices
Asset versions are immutable: the metadata of a version cannot be changed to point at different data. Good practice treats each version as a snapshot. Refreshed data is written to a new path, such as a dated folder, and registered as a new version, often by the pipeline that produced it, so the version history matches the data history.
- Register new versions from pipelines with the output path of the job that created them, which links the data asset to that job.
- Use tags such as
snapshot,sourceandquality=validatedto describe each version. - Pin versions in production training definitions, and update the pin through a pull request when a new version is approved.
- Do not overwrite files at a path that an existing version references, because jobs that use the old version would read new data.
Archiving and lineage
Old versions accumulate. az ml data archive hides a version, or all versions of an asset, from lists and the studio without deleting it, so jobs and models that used it keep their lineage. az ml data restore reverses the archive. Deleting the underlying files would break those references and should follow a retention policy rather than routine clean-up.
Lineage works in both directions. From a data asset version, the studio shows the jobs that used it; from a model, it shows the job that produced it and that job's inputs. This makes it possible to answer questions such as which production models were trained on a dataset that was later found to contain errors.
Reproducible training on refreshed data
A pipeline retrains a model weekly on the latest customer data. Auditors require that, for any production model, the team can identify the exact data used. Data engineers currently overwrite the same file in place each week, and the data asset has a single version that points at it.
Change the data engineering job to write each weekly extract to a new dated path and register it as a new version of the data asset. The retraining pipeline uses @latest, and each run records the resolved version, so every registered model's lineage leads to an immutable snapshot.
Keeping the overwritten file and adding a tag with the date would leave old jobs pointing at data that no longer exists. Pinning the pipeline to version 1 would not use new data. Copying the data into the model folder would make models large and would not record lineage.
Data is refreshed every month. How should a team version it so that last month's training run stays reproducible?
Show answer
Write the refreshed data to a new path and register it as a new version. A version points to a location, so overwriting files at the same path silently changes an existing version.
Exam Tips
Remember for the exam
- Reference assets as azureml:name:version or azureml:name@latest.
- ro_mount streams data; download copies it before the script starts.
- Versions are snapshots: write refreshed data to a new path and register a new version.
- Archive versions instead of deleting them, so lineage is kept.