Skip to content

Instantly share code, notes, and snippets.

@aguschin
Created May 18, 2023 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aguschin/9ad9ee8adf02a42d08dda92ee6d4497f to your computer and use it in GitHub Desktop.
Save aguschin/9ad9ee8adf02a42d08dda92ee6d4497f to your computer and use it in GitHub Desktop.
Migrate from GTO-based model registry to DVC-based model registry: move artifacts' annotations from `artifacts.yaml` to `dvc.yaml`
"""
Script that will
1. read your annotations from `artifacts.yaml`
2. update them to be compatible with the new DVC format
3. add them to `dvc.yaml`, creating it if needed
4. remove `artifacts.yaml`
"""
from ruamel.yaml import YAML
yaml = YAML(typ="safe", pure=True)
yaml.default_flow_style = False
# Read the YAML file
with open("artifacts.yaml", "r") as f:
artifacts = yaml.load(f)
# Modify the format
for key, value in artifacts.items():
if "virtual" in value:
value.pop("virtual")
if "description" in value:
value["desc"] = value.pop("description")
if "custom" in value:
value["meta"] = value.pop("custom")
# Copy info from dvc.yaml
with open("dvc.yaml", "r") as f:
dvcyaml = f.readlines()
# Write the modified data back to the same file
with open("dvc.yaml", "w") as f:
yaml.dump({"artifacts": artifacts}, f)
f.write("\n")
f.writelines(dvcyaml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment