Skip to content

Automatic Optimization should be a property of the LightningModule, not the Trainer #4317

@ananthsub

Description

@ananthsub

🚀 Feature

https://pytorch-lightning.readthedocs.io/en/latest/optimizers.html#manual-optimization
To switch between manual and automatic optimization, we need to toggle this flag on the Trainer. However, all of the user code for optimization is inside the LightningModule. If we had this flag for automatic_optimization on the LightningModule instead, we'd keep all the user-facing optimization pieces in one place.

Pitch

Define a property method for automatic_optimization inside the LightningModule. this would be another model hook

By default:

@property
def automatic_optimization(self) -> bool:
    return True

Then we can set the corresponding properties on the trainer/training loop based on the LightningModule and deprecate the automatic_optimization flag on the Trainer

Metadata

Metadata

Assignees

Labels

featureIs an improvement or enhancementhelp wantedOpen to be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions