← all repositories
davidtvs/pytorch-lr-finder

Stop guessing your learning rate

A PyTorch port of the fastai learning-rate finder that automates the "start at 1e-5 and pray" workflow.

1k stars Python ML FrameworksLLMOps · Eval
pytorch-lr-finder
Velocity · 7d
+0.4
★ / day
Trend
steady
star history

What it does Wraps a short pre-training run that ramps the learning rate from tiny to huge while tracking loss. You inspect the resulting curve and pick a sane value before your real training begins. It also supports cyclical learning rates by identifying the boundaries where loss starts descending and where it goes ragged.

The interesting bit The library implements two variants: fastai’s exponential training-loss approach (quick, plots against log LR) and Leslie Smith’s original linear evaluation-loss approach (slower but sharper, since eval loss diverges more cleanly). Both restore your model and optimizer state afterward, so the probe is non-destructive.

Key highlights

  • One-liner API: range_test()plot()reset()
  • Gradient accumulation support for simulating larger batch sizes
  • Mixed precision via both apex.amp and torch.amp
  • Handles non-standard DataLoader output shapes through TrainDataLoaderIter / ValDataLoaderIter wrappers
  • ~1,000 stars, actively maintained with CI and codecov

Caveats

  • The linear/evaluation mode can be “significantly longer” with a large validation set
  • Your optimizer must not already have an LR scheduler attached
  • Data must arrive (input, label)-ready; anything else needs the iterator workaround

Verdict Useful if you’re training PyTorch models from scratch and tired of grid-searching learning rates. Skip it if you’re already in the Hugging Face ecosystem or using fastai directly, which bundles similar functionality.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.