def test_lr_monitor_no_lr_scheduler_single_lr(tmp_path):
    """Test that learning rates are extracted and logged for no lr scheduler."""

    class CustomBoringModel(BoringModel):
        def configure_optimizers(self):
            return optim.SGD(self.parameters(), lr=0.1)

    model = CustomBoringModel()

    lr_monitor = LearningRateMonitor()
    trainer = Trainer(
        default_root_dir=tmp_path,
        max_epochs=2,
        limit_val_batches=0.1,
        limit_train_batches=0.5,
        callbacks=[lr_monitor],
        logger=CSVLogger(tmp_path),
    )

    trainer.fit(model)

    assert lr_monitor.lrs, "No learning rates logged"
    assert len(lr_monitor.lrs) == len(trainer.optimizers)
    assert list(lr_monitor.lrs) == ["lr-SGD"]
Test that learning rates are extracted and logged for no lr scheduler.
tests/tests_pytorch/callbacks/test_lr_monitor.py