| import wandb | |
| import os | |
| from util import Config, RandomCode | |
| class Wandb: | |
| def __init__(self, config: Config): | |
| self.__dict__ = dict(config.__dict__) | |
| if self.entity == '' or self.project == '' or self.api_key == '': | |
| raise ValueError('Missing required values for either Entity, Project or API Key') | |
| if self.name == '': | |
| self.name = 'run-' + RandomCode() | |
| os.environ['WANDB_API_KEY'] = self.api_key | |
| wandb.init(project=self.project, entity=self.entity, name=self.name, reinit=True) | |
| def __call__(self, args): | |
| wandb.log(args) | |
| def __exit__(self): | |
| wandb.finish() |