Pl_module vs trainer.model in Callbacks

In callbacks, we can use either pl_module or trainer. model to access the actual lightning model that does the job. What is the difference?

pl_module is your LightningModule instance, while trainer.model can be an instance that wraps your LightningModule in certain strategies. For example, if you use DDP,

  • pl_module is an instance of LightningModule, and
  • trainer.model is DistributedDataParallel.

1 Like