def __init__(self, tensor, inner_scheduler_cfg, last_epoch=-1): mock_optimizer = torch.optim.SGD([torch.zeros(1)], lr=tensor.item()) self.tensor = tensor scheduler_cls = get_scheduler_cls(inner_scheduler_cfg.pop("type")) self.inner_scheduler = scheduler_cls(mock_optimizer, **inner_scheduler_cfg) super(TensorScheduler, self).__init__(mock_optimizer, last_epoch)
def init_scheduler(optimizer, cfg): if cfg and optimizer is not None: cfg = {k:v for k, v in six.iteritems(cfg)} sch_cls = get_scheduler_cls(cfg.pop("type")) return sch_cls(optimizer, **cfg) return None