Create a tensor using torch::from_blob failed

I use torch::from_blob in C++ to create a tensor, and failed with "The deleter and context arguments are mutually exclusive.“
it seems that the it is because the tensorMaker is with both deleter and context which i don’t know why.
my code is like below:
‘’’
x = torch::from_blob(data, {shape0, shape1}, torch::TensoorOptions().dtype(torch::kF32));
‘’’
p.s. it seems the error occurs when i update torch from 1.10 to 1.13. And only when building with release will this happen
i’d be grateful if anyone can give some advice

Could you try to create the tensor first using torch::from_blob, clone it afterwards, and finally transform to the desired dtype? torch::from_blob will share the same memory coming from data and in previous versions maybe providing additional options would create a copy of the data for you while it’s now disallowed.

hanks for reply!
in the code above, data is from a vector<float>, so i use tensorOptions.dtype(torch::kF32) not to change the dtype of the data but to specify the dtype of the data. i suppose this will not lead to copy of the data.
additionally, i tried your advice, but got the same failure, i’m not sure if i’ve done the correct thing as you suggest.

x = torch.from_blob(data, {shape0, shape1});
xc = x.clone();
xc.toType(torch::kI64);

supprise to find only calling from_blob(void*, at::IntArrayRef, const at::TensorOption &) alse leads to the same failure. code is like:

std::vector<float> data(shape0 * shape1 * 10, 1); // only to ensure the data size is enough
from_blob(data.data(), {shape0, shape1});

Ah OK, in this case I’ve understood the error message wrong as the at::TensorOptions argument it used to specify how to interpret the data. The error is raised from here](pytorch/Functions.cpp at fbc803df0c420db84429c51599f4fa4354b4493f · pytorch/pytorch · GitHub) but I’m unsure how both arguments are set.
Are you seeing the same issue using e.g.:

float data[] = {1, 2, 3, 4, 5, 6};
auto f = from_blob(data, {1, 2, 3});

I’ve found that the error is because that the directory of build is not cleared :joy: , something( perhaps cmake cache etc.) generated when i used the old version of libtorch is still there. thank you anyway.