How to make the following sort codes differentiable?

            scores, indices = torch.sort(scores_final[:, 0], descending=True)
            keypoints_scores=scores[:self.num_keypoints].unsqueeze(1)
            # post processing
            object_points=object_points.permute(0,2,1).squeeze(0)
            sorted_points = object_points[indices]
            keypoints= sorted_points[:self.num_keypoints, :3]

Some messages about the codes above:
varibales:
scores_final: an output of a neural network, has gradients.
object_points: data from point cloud, has no gradinets.
I want to make the codes differentiable. Thanks a lot.

Indices are not usefully differentiable as their gradient will be zero everywhere and Inf or undefined at the rounding points. Since the cloud points are not attached to any computation graph and are only sorted by constant indices, their output also won’t be attached to the network output.