Skip to content
Change Python code while it's running using a reloading loop
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
reloading
.gitignore
LICENSE.txt
MANIFEST
README.md
setup.cfg
setup.py

README.md

reloading

pypi badge

A Python utility to reload a loop body from source on each iteration without losing state

Useful for editing PyTorch code during training. This lets you e.g. add logging, print statistics or save the model without restarting the training and, therefore, without losing the training progress.

Demo

Install

pip install reloading

Usage

Simply wrap the iterator in a for loop with reloading, e.g.

from reloading import reloading

for i in reloading(range(10)):
    # here could be your training loop
    print(i)

This will reload the loop body from the source file before each iteration.

You can’t perform that action at this time.