Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid edge case where Trainer wraps ReduceLROnPlateau in SequentialLR #41

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gerbilizer/training/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ def __init_model(self):
"threshold": scheduler_config.get("PLATEAU_THRESHOLD", 1e-4),
"min_lr": scheduler_config.get("MIN_LEARNING_RATE", 0),
}
if len(scheduler_configs) != 1:
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should probably be moved outside the for loop. I think it will fail to trigger the error here if the reduce on plateau scheduler is listed as the first of many schedulers

Copy link
Collaborator Author

@amanchoudhri amanchoudhri Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it might work actually? With lr scheduler config

"SCHEDULERS": [
    {
        "SCHEDULER_TYPE": "REDUCE_ON_PLATEAU",
        "MULTIPLICATIVE_DECAY_FACTOR": 0.5,
        "PATIENCE": 2
    },
    {
        "SCHEDULER_TYPE": "COSINE_ANNEALING",
        "MIN_LEARNING_RATE": 0.0,
    },
]

I get the desired error:
image

"ReduceLROnPlateau not supported by SequentialLR scheduling! "
f"Encountered configs of types: {[c['SCHEDULER_TYPE'] for c in scheduler_configs]}"
)
self.__scheduler = base_scheduler(self.__optim, **scheduler_args)
return
else:
raise NotImplementedError(
f'Unrecognized scheduler "{scheduler_config["SCHEDULER_TYPE"]}"'
Expand Down