It depends what you mean by sorting.
If you just want gradients to flow from the sorted output back to the unsorted output, it works fine. As this can be seen as just shuffling the Tensor values.
And the sort operator in pytorch does exactly that.