The solution to the MAE criterion gives you the median, while the solution to the MSE criterion gives you the mean. In the former case you’ll get a robust solution, which means that your solution is robust to outliers, but might have multiple minima. So even though your derivative is partially constant, it’s still a valid approach, at least for some problems. Note that you’ll still get different signs for predictions smaller or greater than your median. I have to admit I’ve never used the MAE criterion for a “real” problem, so I’m not sure how it’ll perform using a deep learning model.
Hastie et al. describe both criteria way better than I can possibly do it in Elements of Statistical Learning, page 18-20 1.
In the case of cross entropy loss, the derivative would be prob_i - target_i, where prob_i is the softmax output at position i and target_i is the target value at position i.
Here is a small manual example:
batch_size = 2
nb_classes = 5
logits = torch.randn(batch_size, nb_classes, requires_grad=True)
target = torch.empty(batch_size, dtype=torch.long).random_(nb_classes)

grad = F.softmax(logits, 1)
grad[torch.arange(batch_size), target] -= 1
grad = grad/batch_size

# Compare with PyTorch implementation
ce = F.cross_entropy(logits, target)
ce.backward()

print('Manual grad:\n{}\nPyTorch grad:\n{}'.format(
    grad, logits.grad))