Do you use the builtin cpp_extension 70 to bind your cpp code? That would allow you to work directly with Tensors and avoid potential errors where your buffer memory might get freed/reused before your python code is done with it.