def test_lr_monitor_single_lr(tmp_path):
    """Test that learning rates are extracted and logged for single lr scheduler."""
    model = BoringModel()

    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 all(v is None for v in lr_monitor.last_momentum_values.values()), "Momentum should not be logged by default"
    assert all(v is None for v in lr_monitor.last_weight_decay_values.values()), (
        "Weight decay should not be logged by default"
    )
    assert len(lr_monitor.lrs) == len(trainer.lr_scheduler_configs)
    assert list(lr_monitor.lrs) == ["lr-SGD"]
Test that learning rates are extracted and logged for single lr scheduler.
tests/tests_pytorch/callbacks/test_lr_monitor.py