Learn Before
Example
Cosine Learning Rate Schedule Example
To empirically demonstrate the impact of a cosine learning rate schedule, a neural network can be trained using an optimizer configured with this scheduler. The schedule dictates that the learning rate decreases gently at the beginning, drops more steeply, and then refines the solution at the end with a very small step size. While this approach can lead to improved training results and final accuracy—particularly in computer vision tasks—such improvements are heuristic and not strictly guaranteed across all models and datasets.
net = net_fn() trainer = torch.optim.SGD(net.parameters(), lr=0.3) train(net, train_iter, test_iter, num_epochs, loss, trainer, device, scheduler)
0
1
Updated 2026-05-18
Tags
D2L
Dive into Deep Learning @ D2L