Error: ‘PyArray_Descr’ has no member named ‘elsize’

I’m trying to compile a specific version of PyTorch (2.1.2) from source in Linux, but I’m facing the following issue:

[1861/1881] Building CXX object caffe2/torch/CMakeFiles/torch_python.dir/csrc/utils/tensor_numpy.cpp.o
  FAILED: caffe2/torch/CMakeFiles/torch_python.dir/csrc/utils/tensor_numpy.cpp.o
  /src/pytorch/torch/csrc/utils/tensor_numpy.cpp: In function ‘at::Tensor torch::utils::tensor_from_cuda_array_interface(PyObject*)’:
  /src/pytorch/torch/csrc/utils/tensor_numpy.cpp:404:34: error: ‘PyArray_Descr’ has no member named ‘elsize’
    404 |     dtype_size_in_bytes = descr->elsize;
        |                                  ^~~~~~

Maybe the cause is an incompatible version of NumPy that is being pulled in.

ps: my environment is actually a bit different. It’s a slightly patched PyTorch being built on riscv64 using qemu. But maybe the error is not related.

Downgrade numpy to <2.0 and try to rebuild PyTorch.

That worked. Thanks for the tip.