Fractional number of epochs

Dear fastai devs/users,

I’ve been working with pretty big datasets and I’ve noticed that it’s not currently possible (easy) to train for less than an epoch.

Say you wanted to train for a few batches, then stop and do something else, etc. I know it can be done with callbacks, but they are kind of painful to set up. Besides, the OneCycleScheduler, one of the coolest parts of fast.ai, won’t work correctly.

I would love to be able to do this:
learn.fit_one_cycle(0.5)
and have it train for half an epoch, with the one cycle scheduler correctly figuring out the annealing.

I’ve forked and already made all necessary modifications and can, if you wish, do a pull request. It looks to me like everything is working, and the learning rates are correct, and the progress bar is working correctly too. But this modification does require some changes across files: in particular, I had to modify all callbacks to take Union[int,float] for n_epochs and cyc_len. It’s working nicely now, at least in my limited testing:

Let me know if you’d like any changes before I do my pull request, or if you think this is a bad/unneeded idea.

2 Likes

This seems useful, I like it :slight_smile:

Why not use filter_by_rand or use_partial_data methods? I’m not quite sure what the technical difference between the two methods are, but if you want to train for half an epoch, isn’t that pretty much the same as training on half the data?