"""Callback to configure learning rate during training."""from__future__importannotationsfromcollections.abcimportIterablefromtypingimportAnyimportlightning.pytorchasplfromvis4d.engine.optim.schedulerimportLRSchedulerWrapper
[docs]classLRSchedulerCallback(pl.Callback):"""Callback to configure learning rate during training."""
[docs]defon_train_batch_end(# type: ignoreself,trainer:pl.Trainer,pl_module:pl.LightningModule,outputs:Any,batch:Any,batch_idx:int,)->None:"""Hook on training batch end."""schedulers=pl_module.lr_schedulers()ifnotisinstance(schedulers,Iterable):schedulers=[schedulers]# type: ignoreforschedulerinschedulers:ifschedulerisNone:continueassertisinstance(scheduler,LRSchedulerWrapper)scheduler.step_on_batch(trainer.global_step)