Skip to content

Instantly share code, notes, and snippets.

@jakelevi1996
Created November 14, 2024 19:36
Show Gist options
  • Save jakelevi1996/898b48bb5fadb47ece1ff6a4e4477528 to your computer and use it in GitHub Desktop.
Save jakelevi1996/898b48bb5fadb47ece1ff6a4e4477528 to your computer and use it in GitHub Desktop.
Compare linear and cosine learning rate schedules
import numpy as np
from jutility import plotting, util, cli, units
t_max = 300
t_max = 100
lr0 = 1e-3
lr1 = 1e-5
lr1 = 0
t = np.arange(t_max)
x1 = lr1 + 0.5 * (lr0 - lr1) * (1 + np.cos(np.pi * t / t_max))
x2 = np.linspace(lr0, lr1, t_max, endpoint=False)
plotting.MultiPlot(
plotting.Subplot(
plotting.Line(t, x1),
plotting.Line(t, x2, c="r"),
),
plotting.Subplot(
plotting.Line(t, x1),
plotting.Line(t, x2, c="r"),
log_y=True,
),
).save()
@jakelevi1996
Copy link
Author

image

@jakelevi1996
Copy link
Author

With lr1 = 1e-5:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment