Variable epoch_length for different epochs
See original GitHub issue❓ 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
@pmneila well, I agree there is no proper way to do that. Here is a hacky approach to achieve what you’d like
Output
Anyway, I agree that separating epoch, iteration and epoch_length could be a interesting feature to have.
@pnmeila thanks for this discussion.
I think having such way to handle dynamic batch size and epoch length could lead to implementation as in the following paper
https://arxiv.org/abs/1711.00489