suppose you forward pass on  6 datapoints (6 images) and you want to perform GD on 36 datapoints (images)
Let dataloader load input with dimension [6x3x224x224] then
for i,(input,target) in enumerate(dataloader):
    output = model(input)
    loss = lossfn(output, target)
    loss.backward() #Only stores the gradients at all nodes
    if (i+1)%6==0:
        loss = loss / 6 # Since we add up loss for 6 minibatches, we would takes mean of loss at end
        optim.step() #Uses the gradients to backpropogagte after 6 batches
        optim.zero_grad()