Using the python API to delete models with no tag (minimal)

Hey all,

Here’s a minimal example of how to delete models that have no tag.

This is useful when you blow your data limit by saving too many intermediate checkpoints during training.

If you improve this script, post your improvements to this thread for the benefit of all.



import wandb

deletes all models that do not have a tag attached

by default this means wandb will delete all but the "latest" or "best" models

set dry_run == False to delete...

dry_run = True
api = wandb.Api(overrides={"project": "oardm_binary_mnist", "entity": "duanenielsen"})
project = api.project('oardm_binary_mnist')

for artifact_type in project.artifacts_types():
    for artifact_collection in artifact_type.collections():
        for version in api.artifact_versions(artifact_type.type,
            if artifact_type.type == 'model':
                if len(version.aliases) > 0:
                    # print out the name of the one we are keeping
                    print(f'KEEPING {}')
                    print(f'DELETING {}')
                    if not dry_run:
1 Like

Thanks a lot for this contribution, Duane!
I love this post! I’m sure our forum readers would love more contributions like these in the future if you have any.

Had a couple spare hours, so I made this into a python command line module and documented.

Check it out on github, feel free to clone/extend…

1 Like