Variable epoch_length for different epochs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 726
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 5
Description
❓ Questions/Help/Support
Hi,
I'm working with a model that increases in complexity during training. To avoid memory issues, I reduce the batch size accordingly at each epoch. This means that, for a fixed length of the dataset, the number of iterations per epoch increases each epoch.
Something like this:
batch_size_per_epoch = [16, 8, 4, 2]
dataset = ImageDataset(...)
loaders = (DataLoader(dataset, batch_size=bs, shuffle=True) for bs in batch_size_per_epoch)
# Then I can run the engine either with
for i, loader in enumerate(loaders):
engine.run(loader, max_epochs=i+1)
# or by calling engine.set_data in a properly defined event handler.
The problem is that engine.state.epoch_length is set once for the first loader and the subsequent loaders run as many iterations as the first one. Setting engine.state.epoch_length by hand is not only ugly, but also messes up the saving/loading of the engine (epoch and iterations are inferred assuming a fixed epoch length).
Is there any way to use variable epoch lengths or variable batch sizes with ignite? I've been thinking of building a new engine for each epoch, but keeping the state from previous engines, saving, loading and reusing the loggers/metrics/handlers is rather messy. Is there an alternative?
Best
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at engine.run and engine.state.epoch_length, then inspect how engine state is saved and loaded. Reproduce the example with successive DataLoaders using batch sizes 16, 8, 4, and 2; done means epoch boundaries, iteration counts, and save/load state remain correct for variable epoch lengths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100