I’m not entirely sure what could be causing this. It seems that the L1-loss implemented by pytorch uses torch.mean rather than division by size. Have a look at the functions _pointwise_loss and l1_loss here:

  
      github.com
  
  
    pytorch/pytorch/blob/408c84de7c4d852beffb9c64e2351b16cfff8a1f/torch/nn/functional.py#L1385 10

    loss = loss * weight


if not reduce:
    return loss
elif size_average:
    return loss.mean()
else:
    return loss.sum()




def _pointwise_loss(lambd, lambd_optimized, input, target, size_average=True, reduce=True):
if target.requires_grad:
    d = lambd(input, target)
    if not reduce:
        return d
    return torch.mean(d) if size_average else torch.sum(d)
else:
    return lambd_optimized(input, target, size_average, reduce)




smooth_l1_loss = _add_docstr(torch._C._nn.smooth_l1_loss, r"""