Skip to content

Remove Trainer reference from lightning module and datamodule #7315

@edenlightning

Description

@edenlightning

Motivation: Remove trainer reference from LightningModule and LightningDataModule.

Benefits:

  • Better backwards compatibility: it should be easier to use the LightningModule of one version of Lightning with the Trainer from another version
  • Better API clarity: users today who call Trainer functions like fit/validate/predict inside of the LightningModule will run into issues with state management. The Trainer assumes these top-level APIs are not called from within another trainer context.

Possible solution: think about introducing a TrainerContext / TrainerState object to pass state and deprecate references to the trainer. This would be mostly read-only data that the LightningModule could leverage for various settings like progress (epoch/step count), distributed setting (global rank, local rank, data parallel/ddp/deepspeed/etc) and more.

The ambition is the lightning module has a tightly controlled view of the trainer, while the trainer has full insight into the module.

cc @Borda @tchaton @justusschock @awaelchli

Metadata

Metadata

Assignees

Labels

designIncludes a design discussiondiscussionIn a discussion stagefeatureIs an improvement or enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions