lr_scheduler.OneCycleLR "ValueError: Tried to step X+2 times. The specified number of total steps is X."

OK I think I’ve just figured out what I was doing wrong - I wasn’t passing a max_epochs argument to the Trainer() instantiation, as I was defining this within the Lightning Module for the LR Scheduling instead. So the trainer.fit() operation wanted to continue training, but the training on the LR Scheduler had ended already, causing the extra step error.

Would it be correct to say the best way to pass it to Trainer would be as follows?:

    net = audioNet16k(num_classes=num_classes, 
                       epochs=1,
                       lr=2e-3, 
                       loss_func=nn.CrossEntropyLoss(),
                       metric=Accuracy(),
                       steps_per_epoch=len(data.train_dataloader()))
    trainer = Trainer(gpus=1, 
                      deterministic=True,
                      max_epochs=net.epochs,
                      auto_lr_find=False, 
                      callbacks=[lr_monitor])
2 Likes