I solved it.
do it like this
    torch::Tensor batched_imgs = tensors[0].new_full({ (int64_t)tensors.size() ,tensors[0].size(0),max_size_first, max_size_second },0);
   
    std::vector<torch::Tensor> image_sizes;
    for (int i = 0; i < tensors.size(); ++i) 
    {
        batched_imgs[i].narrow(/*dim=*/1, /*start=*/0, /*length=*/tensors[i].size(1))
            .narrow(/*dim=*/2, /*start=*/0, /*length=*/tensors[i].size(2)).copy_(tensors[i]);
    }