import torch class WarmUpLR(torch.optim.lr_scheduler._LRScheduler): def __init__(self, optimizer, total_iters, last_epoch=-1): self.total_iters = total_iters super().__init__(optimizer, last_epoch=last_epoch) def get_lr(self): return [base_lr * self.last_epoch / (self.total_iters + 1e-8) for base_lr in self.base_lrs]