espnet3.systems.esp2_codec.src.gan_trainer.build_gan_trainer
Less than 1 minute
espnet3.systems.esp2_codec.src.gan_trainer.build_gan_trainer
espnet3.systems.esp2_codec.src.gan_trainer.build_gan_trainer(training_config, model) → GANLightningTrainer
Build the shared GAN Lightning trainer for any AbsGANESPnetModel.
Wraps model in a GANLightningModule (which drives the manual generator/discriminator optimization loop) and hands it to a GANLightningTrainer configured from the recipe’s training config.
- Parameters:
- training_config – Resolved training config. The following fields are read:
trainer(Lightning trainer kwargs plus the GAN-onlygansub-block),exp_dir(checkpoint/log destination),best_model_criterion(checkpoint selection rules), and theoptimizers/schedulersblocks consumed byGANLightningModule. - model – The GAN model to train. Expected to be an
espnet2.train.abs_gan_espnet_model.AbsGANESPnetModel, i.e. a model exposinggeneratoranddiscriminatorsubmodules and aforward(..., forward_generator=...)signature.
- training_config – Resolved training config. The following fields are read:
- Returns: A trainer ready for
.fit()or.collect_stats(). - Return type:GANLightningTrainer
Examples
```python from espnet3.systems.esp2_codec.src.gan_trainer import build_gan_trainer from espnet3.utils.task_utils import get_espnet_model
model = get_espnet_model(config.task, config.model) trainer = build_gan_trainer(config, model) trainer.fit()
```ESP2CodecSystem picks this path automatically for GAN models:
```python if isinstance(model, AbsGANESPnetModel):
return build_gan_trainer(config, model)
```