def save_eval_file(opt, stats, eval_type="losses", split="dev", ext="pickle"): if cfg.test_save: name = "{}/{}.{}".format( utils.make_name(opt, prefix="garbage/{}/".format(eval_type), is_dir=True, eval_=True), split, ext) else: name = "{}/{}.{}".format( utils.make_name(opt, prefix="results/{}/".format(eval_type), is_dir=True, eval_=True), split, ext) print("Saving {} {} to {}".format(split, eval_type, name)) if ext == "pickle": with open(name, "wb") as f: pickle.dump(stats, f) elif ext == "txt": with open(name, "w") as f: f.write(stats) elif ext == "json": with open(name, "w") as f: json.dump(stats, f) else: raise
def set_logger(self): if cfg.toy: self.logger = SummaryWriter( utils.make_name(self.opt, prefix="garbage/logs/", eval_=True, do_epoch=False)) else: self.logger = SummaryWriter( utils.make_name(self.opt, prefix="logs/", eval_=True, do_epoch=False)) print("Logging Tensorboard Files at: {}".format(self.logger.log_dir))
def save_step(model, vocab, optimizer, opt, length, lrs): if cfg.test_save: name = "{}.pickle".format( utils.make_name(opt, prefix="garbage/models/", is_dir=False, eval_=True)) else: name = "{}.pickle".format( utils.make_name(opt, prefix="models/", is_dir=False, eval_=True)) save_checkpoint( { "epoch": length, "state_dict": model.state_dict(), "optimizer": optimizer.state_dict(), "opt": opt, "vocab": vocab, "epoch_learning_rates": lrs }, name)