From 6f5f13529e41d77ebee3e17fa2cd3ef70162bd2e Mon Sep 17 00:00:00 2001 From: desert-sailor Date: Fri, 18 Jul 2025 17:37:35 +0800 Subject: [PATCH] Backport: Make PyTorch compilable against upcoming Numpy-2.0 --- ...ompilable-against-upcoming-Numpy-2.0.patch | 28 +++++++++++++++++++ pytorch.spec | 6 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 0005-Make-PyTorch-compilable-against-upcoming-Numpy-2.0.patch diff --git a/0005-Make-PyTorch-compilable-against-upcoming-Numpy-2.0.patch b/0005-Make-PyTorch-compilable-against-upcoming-Numpy-2.0.patch new file mode 100644 index 0000000..3ec9228 --- /dev/null +++ b/0005-Make-PyTorch-compilable-against-upcoming-Numpy-2.0.patch @@ -0,0 +1,28 @@ +From 9094662fc03e1309351841c017ba567893a0668c Mon Sep 17 00:00:00 2001 +From: desert-sailor +Date: Mon, 21 Jul 2025 09:15:17 +0800 +Subject: [PATCH] Make PyTorch compilable against upcoming Numpy-2.0 + +--- + torch/csrc/utils/tensor_numpy.cpp | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/torch/csrc/utils/tensor_numpy.cpp b/torch/csrc/utils/tensor_numpy.cpp +index 46c347c9..14bcb29a 100644 +--- a/torch/csrc/utils/tensor_numpy.cpp ++++ b/torch/csrc/utils/tensor_numpy.cpp +@@ -401,7 +401,11 @@ at::Tensor tensor_from_cuda_array_interface(PyObject* obj) { + throw ValueError("cannot parse `typestr`"); + } + dtype = numpy_dtype_to_aten(descr->type_num); ++#if NPY_ABI_VERSION >= 0x02000000 ++ dtype_size_in_bytes = PyDataType_ELSIZE(descr); ++#else + dtype_size_in_bytes = descr->elsize; ++#endif + TORCH_INTERNAL_ASSERT(dtype_size_in_bytes > 0); + } + +-- +2.43.0 + diff --git a/pytorch.spec b/pytorch.spec index c1fe83a..14dbc3e 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -1,7 +1,7 @@ %global _empty_manifest_terminate_build 0 Name: pytorch Version: 2.1.2 -Release: 5 +Release: 6 Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration License: BSD-3-Clause URL: https://pytorch.org/ @@ -15,6 +15,7 @@ Patch3: 0003-Fix-for-PyTorch-mobile-flatbuffer-loader-out-of-bounds-reads.patch %ifarch loongarch64 Patch4: 0004-Add-loongarch64-support-for-third_party.patch %endif +Patch5: 0005-Make-PyTorch-compilable-against-upcoming-Numpy-2.0.patch BuildRequires: g++ Requires: python3-future Requires: python3-numpy @@ -93,6 +94,9 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog +* Fri Jul 18 2025 Dongxing Wang - 2.1.2-6 +- Backport: Make PyTorch compilable against upcoming Numpy-2.0 + * Wed Mar 5 2025 zhangzikang - 2.1.2-5 - Sync from 24.03sp1: Fix build error for loongarch64 -- Gitee