Trainer

class neuromancer.trainer.Trainer(problem: ~neuromancer.problem.Problem, train_data: ~torch.utils.data.dataloader.DataLoader, dev_data: ~torch.utils.data.dataloader.DataLoader | None = None, test_data: ~torch.utils.data.dataloader.DataLoader | None = None, optimizer: ~torch.optim.optimizer.Optimizer | None = None, logger: ~neuromancer.loggers.BasicLogger | None = None, callback=<neuromancer.callbacks.Callback object>, lr_scheduler=False, epochs=1000, epoch_verbose=1, patience=5, warmup=0, train_metric='train_loss', dev_metric='dev_loss', test_metric='test_loss', eval_metric='dev_loss', eval_mode='min', clip=100.0, device='cpu')[source]

Class encapsulating boilerplate PyTorch training code. Training procedure is somewhat extensible through methods in Callback objects associated with training and evaluation waypoints.

evaluate(best_model)[source]

This method is deprecated. Use self.test instead.

test(best_model)[source]

Evaluate the model on all data splits.

train()[source]

Optimize model according to train_metric and validate per-epoch according to eval_metric. Trains for self.epochs and terminates early if self.patience threshold is exceeded.

neuromancer.trainer.move_batch_to_device(batch, device='cpu')[source]