Sweet! I knew it was wise to ask first

Thanks!

**UPDATE**:

**Wow** ā¦ so much simpler in v2! Below, for posterity sake so folks know what this looked like in the old days, this is what I had to do:

```
class GradientAccumulation(AccumulateScheduler):
_order = -40 # needs to run before the recorder
def __init__(self, learn:Learner, n_step:int = 1, drop_last:bool = False):
super().__init__(learn, n_step=n_step, drop_last=drop_last)
self.acc_samples = 0
self.acc_batches = 0
def on_batch_begin(self, last_input, last_target, **kwargs):
"accumulate samples and batches"
self.acc_samples += last_input[0].shape[0]
self.acc_batches += 1
def on_backward_end(self, **kwargs):
"accumulated step and reset samples, True will result in no stepping"
if (self.acc_batches % self.n_step) == 0:
for p in (self.learn.model.parameters()):
# wtg - not all params have a gradient here, so check for p.grad != None
if p.requires_grad and p.grad is not None:
p.grad.div_(self.acc_samples)
self.acc_samples = 0
else:
return {'skip_step':True, 'skip_zero':True}
def on_epoch_end(self, **kwargs):
"step the rest of the accumulated grads if not perfectly divisible"
for p in (self.learn.model.parameters()):
# wtg - not all params have a gradient here, so check for p.grad != None
if p.requires_grad and p.grad is not None:
p.grad.div_(self.acc_samples)
if not self.drop_last: self.learn.opt.step()
self.learn.opt.zero_grad()
```