← all repositories
julvo/reloading

Edit your training loop mid-flight without restarting

A Python decorator that hot-reloads loop bodies and functions from source while preserving runtime state, aimed at ML workflows where restarting means losing hours of training.

1.1k stars Python Other AI
reloading
Velocity · 7d
+0.4
★ / day
Trend
steady
star history

What it does

reloading is a small Python utility that wraps iterators or functions to re-read their source code from disk before each iteration or invocation. You add a decorator or wrap a for loop, then edit the code while it runs. The next iteration picks up your changes; variables and model state stay intact.

The interesting bit

The trick is scope: it reloads the body of the loop or function, not the whole module, so local variables and accumulated training state survive. The README shows it wired into Keras callbacks, fastai LearnerCallback, and raw PyTorch/TensorFlow loops — the glue is always a little awkward, but it works.

Key highlights

  • Wrap any iterator: for i in reloading(range(1000), every=10): to throttle reloads in tight loops
  • Decorate functions with @reloading or @reloading(every=n)
  • forever=True gives an infinite reloading loop without an iterable
  • Examples provided for PyTorch, TensorFlow, Keras, and fastai
  • Single-file utility; install via pip install reloading

Caveats

  • The README notes you need both python and python3 in your path to run tests, which suggests some version assumptions worth checking
  • How it handles syntax errors during reload, or nested reloads, is not documented

Verdict

Worth a look if you train long-running models and want to tweak logging or save checkpoints without losing GPU hours. Less useful for short scripts or anything where a full restart is cheap.

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