def test_state_get_event_attrib_value(): state = State() state.iteration = 10 state.epoch = 9 e = Events.ITERATION_STARTED assert state.get_event_attrib_value(e) == state.iteration e = Events.ITERATION_COMPLETED assert state.get_event_attrib_value(e) == state.iteration e = Events.EPOCH_STARTED assert state.get_event_attrib_value(e) == state.epoch e = Events.EPOCH_COMPLETED assert state.get_event_attrib_value(e) == state.epoch e = Events.STARTED assert state.get_event_attrib_value(e) == state.epoch e = Events.COMPLETED assert state.get_event_attrib_value(e) == state.epoch e = Events.ITERATION_STARTED(every=10) assert state.get_event_attrib_value(e) == state.iteration e = Events.ITERATION_COMPLETED(every=10) assert state.get_event_attrib_value(e) == state.iteration e = Events.EPOCH_STARTED(once=5) assert state.get_event_attrib_value(e) == state.epoch e = Events.EPOCH_COMPLETED(once=5) assert state.get_event_attrib_value(e) == state.epoch
def evaluate_best_model(trainer, loader, evaluator, model_manager, save_path, save_prefix, timestamp, seed, device): load_best_model(trainer, model_manager, save_path, save_prefix, timestamp, seed, device) # Re-set random seed to have reproducable evaluation torch.random.manual_seed(seed) np.random.seed(seed) state = State(dataloader=loader, max_epochs=1) state.epoch = 1 setattr(trainer, "state", state) log_results(trainer, TEST, loader, evaluator, None)