-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Describe the bug
All solvers currently use torch.optim.lr_scheduler.ConstantLR as the default scheduler, which should keep the learning rate fixed throughout training. However, this is not what happens in practice.
The default scheduler is instantiated through TorchScheduler, which receives only the scheduler class and no additional arguments. As a result, the scheduler is created with PyTorch’s defaults: factor=1/3, total_iters=5, and last_epoch=-1.
Because of this, for the first total_iters epochs the learning rate is scaled by factor, meaning that the first five epochs run at 0.0003333 instead of the expected 0.001.
Reference: https://docs.pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ConstantLR.html
To Reproduce
Insert this line at the beginning of training_step of the SolverInterface class to print the learning rate at every epoch:
print(self._pina_optimizers[0].instance.param_groups[0]["lr"])Then, run the following code:
from pina.solver import PINN
from pina.trainer import Trainer
from pina.model import FeedForward
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
# Problem
problem = Poisson()
problem.discretise_domain(10)
# Model
model = FeedForward(len(problem.input_variables), len(problem.output_variables))
# Solver
solver = PINN(problem=problem, model=model)
# Trainer
trainer = Trainer(solver=solver, max_epochs=10)
trainer.train()Expected behavior
The learning rate for the default scheduler should always be constant.