Aliases for datasets in Valohai allow you to avoid making changes to your code whenever a new version is created. Instead of referencing the version name, you can use an alias. For example, rather than using dataset://<dataset-name>/<dataset-version-name>
in your input, you can use dataset://<dataset-name>/myalias
.
A special alias, dataset://<dataset-name>/latest
, always points to the latest version in your dataset, and you don’t need to create this alias manually.
Create an alias
Web application
You can create an alias in the Valohai UI by opening the “Aliases” tab under the dataset and clicking the “Create new dataset version alias” button. To set the alias to point to a different dataset version, click “Edit.” The UI allows you to track the alias history.
Programmatically
You can also create or update dataset version aliases programmatically using the .metadata.json sidecar file. The following example demonstrates how to create a new dataset version based on a previous version and set the alias “myalias” to point to that new version. If the alias doesn’t exist, it will be created.
import valohai
import json
metadata = {
"valohai.dataset-versions": [{
'uri': "dataset://<dataset-name>/<new-dataset-version-name>",
'from': "dataset://<dataset-name>/<original-dataset-version-name>",
'targeting_aliases': ['myalias']
}]
}
save_path = '/valohai/outputs/model.pkl'
model.save(save_path)
metadata_path = '/valohai/outputs/model.pkl.metadata.json'
with open(metadata_path, 'w') as outfile:
json.dump(metadata, outfile)