Skip to content

Add cosine annealing to LR scheduler options #182

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

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions sparse_autoencoder/train/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def setup_optimizer(
)

lr_scheduler: LRScheduler | None = None

if hyperparameters["optimizer"]["lr_scheduler"] == "reduce_on_plateau":
lr_scheduler = ReduceLROnPlateau(optimizer=optim, patience=10) # type: ignore

elif hyperparameters["optimizer"]["lr_scheduler"] == "cosine_annealing":
lr_scheduler = CosineAnnealingLR(
optimizer=optim,
T_max=10,
)
if "lr_scheduler" in hyperparameters["optimizer"]:
if hyperparameters["optimizer"]["lr_scheduler"] == "reduce_on_plateau":
lr_scheduler = ReduceLROnPlateau(optimizer=optim, patience=10) # type: ignore

elif hyperparameters["optimizer"]["lr_scheduler"] == "cosine_annealing":
lr_scheduler = CosineAnnealingLR(
optimizer=optim,
T_max=10,
)

return optim, lr_scheduler

Expand Down
4 changes: 3 additions & 1 deletion sparse_autoencoder/train/sweep_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class OptimizerHyperparameters(NestedParameter):
Whether to use a fused implementation of the optimizer (may be faster on CUDA).
"""

lr_scheduler: Parameter[Literal["reduce_on_plateau"]] | None = None
lr_scheduler: Parameter[Literal["reduce_on_plateau", "cosine_annealing"]] | None = field(
default=None
)
"""Learning rate scheduler."""


Expand Down