You can use the L-1 loss, since it’s the closest convex approximation of L-0: loss = torch.norm(output-target, p=1). If you feel confident and ok with discarding convexity, you can even try a fractional norm, e.g. L-1/2: loss = torch.norm(output-target, p=0.5). This latter choice may probably lead to unstable gradients, though.