You can simply use std::sort (for CPU tensors) or thrust::sort (for CUDA tensors) on the tensor’s data pointer, given that your tensor is contiguous.
The snippet below is built for libtorch, but the behavior is exactly the same in ATen:
#include <torch/torch.h>
#include <iostream>

int main(){
	torch::Tensor x = torch::tensor({1, 3, 4, 2, 0, 5, 9});
	int *x_ptr = x.data<int>();
	std::sort(x_ptr + 1, x_ptr + 4, std::less<int>()); // sorting {3, 4, 2}
	std::cout << x << std::endl; // prints 1 2 3 4 0 5 9
	return 0;
}