Hi,
From a quick look, it seems like your Module version handles batch differently than the autograd version no?
Also once you are sure that the forward give the same thing, you can check the backward implementation of the autograd with: torch.autograd.gradcheck(Diceloss.apply, (sample_input, sample_target)), where the inputs are double precision, with the input requirering gradients.