Last active
February 10, 2021 08:48
-
-
Save yusuke0519/c148f2d7b382170f43738eb3303b14a4 to your computer and use it in GitHub Desktop.
In many cases, including hyperparameter search, we want to check whether the same config has been already finished or not, This is a short examples for checking it when we uses wandb as a backend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Argparser to wandb query. | |
References | |
---------- | |
Short tutorial: https://docs.wandb.ai/ref/export-api | |
Wandb API: https://docs.wandb.ai/ref/export-api/api | |
- Api.runs | |
- RUN class | |
Mongodb query: https://docs.mongodb.com/manual/reference/operator/query/ | |
""" | |
import argparse | |
import wandb | |
# Argparser | |
parser = argparse.ArgumentParser(description='NAM Example') | |
parser.add_argument('--batch-size', type=int, default=128, metavar='N', | |
help='input batch size for training (default: 128)') | |
parser.add_argument('--epochs', type=int, default=10, metavar='N', | |
help='number of epochs to train (default: 10)') | |
parser.add_argument('--no-cuda', action='store_true', default=False, | |
help='disables CUDA training') | |
parser.add_argument('--seed', type=int, default=1, metavar='S', | |
help='random seed (default: 1)') | |
parser.add_argument('--log-interval', type=int, default=10, metavar='N', | |
help='how many batches to wait before logging training status') | |
args = parser.parse_args() | |
# Wandb | |
project_path = "{user_name}/{project_name}" | |
api = wandb.Api() | |
query = [{"config." + str(key): val} for key, val in vars(args).items()] | |
query.append({"state": {'$in': ["finished", "running"]}}) # You can also add state condition. The strings may be depend on the version of wandb. | |
runs = api.runs(project_path, {'$and': query}) | |
exist_same_exp = len(runs) > 0 # You can check if the same experiments has been started/finished or not |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment