Hi,
Your Detail module modifies the temp tensor inplace.
Assuming that temp is a DxD-1 matrix, your for loops can be replaced by:
part1 = temp.narrow(1, 0, D-1) - temp.narrow(1, 1, D-1)
part2 = part1.narrow(1, -1, 1)
out = torch.cat([part1, part2], 1))

Also I am not sure if you get the output you want? Maybe you were expecting part2 = temp.narrow(1, -1, 1).