TS2EvalTrainer#
- class ts2.TS2EvalTrainer(cfg, rank, world_size)[source]#
Bases:
ts2.ts2_test_mixin.TS2TestMixin,core.trainer.BaseTrainerStandardized evaluation Trainer for Task Suite 2 (neural prediction).
This class defines the base Trainer for benchmark neural prediction tasks. This interface abstracts away the common boilerplate code for evaluating models on the benchmark, and allows for easy customization of the training loop. Both tasks reconstruct held-out spike counts stripped from the input before
input_fn, and only those entries are scored. Several methods related to standardized evaluation are declared final and should not be overridden. Please refer toLFADSEvalTrainerfor a template for customizing the training logic.Available to customize (override these methods in a custom Trainer, if needed):
setup: Set up the trainer. This includes setting up the tasks, data loaders, model, optimizer, and scheduler.
setup_model: Instantiate and initialize the model.
link_model: Link the datasets to the model.
setup_finetuning: Set up the finetuning strategy.
setup_optimizers: Configure the optimizer (and scheduler, if applicable).
loss: Define the loss function.
train_epoch: Define the training loop. This is flexible and allows for custom training logic, such as adding gradient accumulation, curriculum learning, etc.
training_step: Compute the loss for one batch. This is where a model that corrupts its own input applies its masker.
predict: Given a batch of data, including inputs as defined by the model’s input_fn and any masking information, generate the model’s predictions.
See Task Suite 2: Neural Activity Prediction for more details on the interface.
- setup(ckpt)[source]#
Set up all trainer components.
Called automatically by the base constructor. Initializes tasks, data loaders, model, DDP wrapping, optimizer, and finetuning strategy in order.
- setup_model(ckpt)[source]#
Instantiate and register the model.
Instantiates the model from the Hydra config and registers it for checkpointing. Override this to load pretrained weights or modify the model architecture.
- link_model(model, ckpt)[source]#
Link datasets to the model.
Attaches the configured transforms and the model input_fn to the train/val/test dataset transform pipelines, then calls
model.link_datasetsto register the datasets with the model.
- setup_finetuning()[source]#
Set up the finetuning strategy from config.
Instantiates and initializes the finetuning strategy if
finetuning.strategyis specified in the config. Setsself.ft_strategytoNoneotherwise.
- loss(pred, target, mask=None)[source]#
Compute the reconstruction loss.
- Parameters:
pred – Model predictions.
target – Ground truth targets.
mask – Optional boolean mask. If provided, loss is averaged only over masked positions.
- Returns:
Scalar loss value.
- Return type:
- train_epoch()[source]#
Run one training epoch.
Iterates over the train loader, computes predictions and loss, and updates model parameters via optimizer and scheduler. Logs loss per step if
log_train_stepis enabled, otherwise logs the epoch average.
- predict(X, mask=None, mask_timestamps=None, mask_units=None)[source]#
Generate model predictions for a batch.
Override this if the model requires masking information at inference time (e.g. for masked autoencoder models).
- Parameters:
X – Input batch dict containing
model_inputs.mask – Optional boolean mask for masked prediction.
mask_timestamps – Optional timestamps for masked positions.
mask_units – Optional unit indices for masked positions.
- Returns:
Model output predictions.
- Return type:
- training_step(X, y)[source]#
Compute loss for one training batch.
Override this to customize masking, auxiliary losses, or any model-specific training logic. The base implementation is a plain forward pass against the benchmark-fixed target.
- Parameters:
- Returns:
Scalar loss.
- Return type:
- setup_optimizers(ckpt)[source]#
Configure the AdamW optimizer and OneCycleLR scheduler.
Weight decay skips 1-D params and the names in
cfg.no_weight_decay. Override this to use a different optimizer or scheduler.