Thanks for the reply.
The problem was the non-contiguous memory distribution for the tensor. So the raw memory copy failed. Using the contiguous method on the tensor and returning the data pointer worked