Thanks! This is working well!
Could you elaborate a bit what indices -= indices.min(dim=1, keepdims=True)[0] is doing?
This solution creates another tensor for the updated result, which is fine. I wonder if there is any in-place way that can save the extra memory cost.