graph LR
BaseTrainer["BaseTrainer"]
train_iter["train_iter"]
optim_ops["optim_ops"]
eval_ops["eval_ops"]
save_model["save_model"]
train_iter_custom["train_iter_custom"]
BaseTrainer -- "invokes" --> train_iter
BaseTrainer -- "triggers" --> optim_ops
BaseTrainer -- "calls" --> eval_ops
BaseTrainer -- "utilizes" --> save_model
train_iter -- "delegates to" --> train_iter_custom
The Trainer subsystem is primarily defined by the torchgan.trainer.base_trainer module, with the BaseTrainer class serving as its central orchestrator. This subsystem encapsulates all logic related to the training lifecycle of Generative Adversarial Networks (GANs).
The central orchestration unit for the entire GAN training lifecycle. It manages epochs, iterations, coordinates data flow, invokes model forward passes, calculates losses, updates model parameters via optimizers, evaluates metrics, and handles logging and model persistence.
Related Classes/Methods:
Executes a single forward and backward pass for the generator and discriminator models, including loss computation. This method embodies the core iterative training logic.
Related Classes/Methods:
Encapsulates the logic for performing optimization steps, such as calculating gradients and updating model parameters using configured optimizers. This is a critical component for the "Optimizers" pattern.
Related Classes/Methods:
Manages the evaluation phase during training, calculating and reporting performance metrics on a validation set. This aligns with the "Metrics" and "Logging and Visualization" patterns.
Related Classes/Methods:
Handles the saving of trained models, enabling checkpointing and final model storage. This is essential for model persistence and recovery.
Related Classes/Methods:
Provides an explicit 'Extensibility Pattern' hook for users to inject custom training logic within a single iteration without modifying the core train_iter method. This is a key architectural feature for user customization.
Related Classes/Methods: