Skip to content

Commit d16d420

Browse files
fix numpy2.0/2.1 bug in release/2.6 (#67958)
* 升级编译所需要的依赖 * cherry-pick-np2.0 * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: XieYunshen <[email protected]>
1 parent 64c6937 commit d16d420

34 files changed

+207
-175
lines changed

cmake/external/pybind11.cmake

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@ include(ExternalProject)
1717
set(PYBIND_PREFIX_DIR ${THIRD_PARTY_PATH}/pybind)
1818
set(PYBIND_SOURCE_DIR ${PYBIND_PREFIX_DIR}/src/extern_pybind)
1919
set(PYBIND_INCLUDE_DIR ${PYBIND_SOURCE_DIR}/include)
20-
set(PYBIND_TAG v2.10.3)
2120
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/pybind)
2221
set(SOURCE_INCLUDE_DIR ${SOURCE_DIR}/include)
2322

2423
include_directories(${PYBIND_INCLUDE_DIR})
2524

25+
# It can be safely removed in gcc9.1+
2626
set(PYBIND_PATCH_COMMAND "")
27-
if(NOT WIN32)
28-
file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/pybind/cast.h.patch
29-
native_dst)
27+
if(LINUX
28+
AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
29+
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
30+
set(PYBIND_TAG v2.12.0)
31+
file(TO_NATIVE_PATH
32+
${PADDLE_SOURCE_DIR}/patches/pybind/detail/internals.h.patch native_dst)
3033
# Note: [Why calling some `git` commands before `patch`?]
31-
# Paddle's CI uses cache to accelarate the make process. However, error might raise when patch codes in two scenarios:
34+
# Paddle's CI uses cache to accelerate the make process. However, error might raise when patch codes in two scenarios:
3235
# 1. Patch to the wrong version: the tag version of CI's cache falls behind PYBIND_TAG, use `git checkout ${PYBIND_TAG}` to solve this.
3336
# 2. Patch twice: the tag version of cache == PYBIND_TAG, but patch has already applied to cache.
3437
set(PYBIND_PATCH_COMMAND
3538
git checkout -- . && git checkout ${PYBIND_TAG} && patch -Nd
36-
${SOURCE_INCLUDE_DIR}/pybind11 < ${native_dst})
39+
${SOURCE_INCLUDE_DIR}/pybind11/detail < ${native_dst})
3740
endif()
3841

3942
ExternalProject_Add(

paddle/fluid/pybind/tensor.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ void BindTensor(pybind11::module &m) { // NOLINT
215215
// TensorToPyArray() according to the dtype and copy
216216
// parameters.
217217
"__array__",
218-
[](phi::DenseTensor &self, py::object dtype, py::object copy) {
219-
return TensorToPyArray(self);
218+
[](phi::DenseTensor &self, py::object dtype, py::object copy) { //NOLINT
219+
return TensorToPyArray(self,copy);
220220
},
221221
py::arg("dtype") = py::none(),
222222
py::arg("copy") = py::none())

paddle/fluid/pybind/tensor_py.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,7 @@ inline phi::DenseTensor *PySliceTensor(const phi::DenseTensor &self,
955955
}
956956
}
957957

958-
inline py::array TensorToPyArray(const phi::DenseTensor &tensor,
959-
bool need_deep_copy = false) {
958+
inline py::array TensorToPyArray(const phi::DenseTensor &tensor,py::object copy=py::none()) {
960959
if (!tensor.IsInitialized()) {
961960
return py::array();
962961
}
@@ -984,9 +983,8 @@ inline py::array TensorToPyArray(const phi::DenseTensor &tensor,
984983

985984
std::string py_dtype_str = details::TensorDTypeToPyDTypeStr(
986985
framework::TransToProtoVarType(tensor.dtype()));
987-
988986
if (!is_gpu_tensor && !is_xpu_tensor && !is_custom_device_tensor) {
989-
if (!need_deep_copy) {
987+
if (!copy.is_none()&& !copy) {
990988
auto base = py::cast(std::move(tensor));
991989
return py::array(py::dtype(py_dtype_str.c_str()),
992990
py_dims,

paddle/scripts/paddle_build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if "%WITH_PYTHON%" == "ON" (
111111
where pip
112112
python -m pip install --upgrade pip
113113
python -m pip install -r %work_dir%\paddle\scripts\compile_requirements.txt
114-
python -m pip install -r %work_dir%\python\requirements.txt
114+
python -m pip install -r %work_dir%\python\requirements.txt --no-cache-dir --force-reinstall
115115
if !ERRORLEVEL! NEQ 0 (
116116
echo pip install requirements.txt failed!
117117
exit /b 5

paddle/scripts/paddle_build.sh

+13-12
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ function run_setup(){
35443544
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
35453545
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/
35463546
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib
3547-
pip3.8 install --user -r ${PADDLE_ROOT}/python/requirements.txt
3547+
pip3.8 install --user -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
35483548
else
35493549
exit 1
35503550
fi
@@ -3557,7 +3557,7 @@ function run_setup(){
35573557
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
35583558
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/
35593559
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
3560-
pip3.9 install --user -r ${PADDLE_ROOT}/python/requirements.txt
3560+
pip3.9 install --user -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
35613561
else
35623562
exit 1
35633563
fi
@@ -3570,7 +3570,7 @@ function run_setup(){
35703570
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.10/bin/python3
35713571
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/
35723572
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
3573-
pip3.10 install --user -r ${PADDLE_ROOT}/python/requirements.txt
3573+
pip3.10 install --user -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
35743574
else
35753575
exit 1
35763576
fi
@@ -3583,7 +3583,7 @@ function run_setup(){
35833583
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.11/bin/python3
35843584
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11/
35853585
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib
3586-
pip3.11 install --user -r ${PADDLE_ROOT}/python/requirements.txt
3586+
pip3.11 install --user -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
35873587
else
35883588
exit 1
35893589
fi
@@ -3596,7 +3596,7 @@ function run_setup(){
35963596
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.12/bin/python3
35973597
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.12/include/python3.12/
35983598
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.12/lib/libpython3.12.dylib
3599-
pip3.12 install --user -r ${PADDLE_ROOT}/python/requirements.txt
3599+
pip3.12 install --user -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36003600
else
36013601
exit 1
36023602
fi
@@ -3611,7 +3611,7 @@ function run_setup(){
36113611
export PYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python3.8
36123612
export PYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.8.0/include/python3.8
36133613
export PYTHON_LIBRARIES=/opt/_internal/cpython-3.8.0/lib/libpython3.so
3614-
pip3.8 install -r ${PADDLE_ROOT}/python/requirements.txt
3614+
pip3.8 install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36153615
pip3.8 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt
36163616
elif [ "$1" == "cp39-cp39" ]; then
36173617
export LD_LIBRARY_PATH=/opt/_internal/cpython-3.9.0/lib/:${LD_LIBRARY_PATH}
@@ -3620,7 +3620,7 @@ function run_setup(){
36203620
export PYTHON_EXECUTABLE=/opt/_internal/cpython-3.9.0/bin/python3.9
36213621
export PYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.9.0/include/python3.9
36223622
export PYTHON_LIBRARIES=/opt/_internal/cpython-3.9.0/lib/libpython3.so
3623-
pip3.9 install -r ${PADDLE_ROOT}/python/requirements.txt
3623+
pip3.9 install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36243624
pip3.9 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt
36253625
elif [ "$1" == "cp310-cp310" ]; then
36263626
export LD_LIBRARY_PATH=/opt/_internal/cpython-3.10.0/lib/:${LD_LIBRARY_PATH}
@@ -3629,7 +3629,7 @@ function run_setup(){
36293629
export PYTHON_EXECUTABLE=/opt/_internal/cpython-3.10.0/bin/python3.10
36303630
export PYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.10.0/include/python3.10
36313631
export PYTHON_LIBRARIES=/opt/_internal/cpython-3.10.0/lib/libpython3.so
3632-
pip3.10 install -r ${PADDLE_ROOT}/python/requirements.txt
3632+
pip3.10 install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36333633
pip3.10 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt
36343634
elif [ "$1" == "cp311-cp311" ]; then
36353635
export LD_LIBRARY_PATH=/opt/_internal/cpython-3.11.0/lib/:${LD_LIBRARY_PATH}
@@ -3638,7 +3638,7 @@ function run_setup(){
36383638
export PYTHON_EXECUTABLE=/opt/_internal/cpython-3.11.0/bin/python3.11
36393639
export PYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.11.0/include/python3.11
36403640
export PYTHON_LIBRARIES=/opt/_internal/cpython-3.11.0/lib/libpython3.so
3641-
pip3.11 install -r ${PADDLE_ROOT}/python/requirements.txt
3641+
pip3.11 install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36423642
pip3.11 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt
36433643
elif [ "$1" == "cp312-cp312" ]; then
36443644
export LD_LIBRARY_PATH=/opt/_internal/cpython-3.12.0/lib/:${LD_LIBRARY_PATH}
@@ -3647,14 +3647,15 @@ function run_setup(){
36473647
export PYTHON_EXECUTABLE=/opt/_internal/cpython-3.12.0/bin/python3.12
36483648
export PYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.12.0/include/python3.12
36493649
export PYTHON_LIBRARIES=/opt/_internal/cpython-3.12.0/lib/libpython3.so
3650-
pip3.12 install -r ${PADDLE_ROOT}/python/requirements.txt
3651-
pip3.12 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt
3650+
pip3.12 install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
3651+
pip3.12 install -r ${PADDLE_ROOT}/paddle/scripts/compile_requirements.txt --no-cache-dir --force-reinstall
36523652
fi
36533653
else
3654-
pip install -r ${PADDLE_ROOT}/python/requirements.txt
3654+
pip install -r ${PADDLE_ROOT}/python/requirements.txt --no-cache-dir --force-reinstall
36553655
fi
36563656
fi
36573657

3658+
36583659
if [ "$SYSTEM" == "Darwin" ]; then
36593660
WITH_DISTRIBUTE="OFF"
36603661
WITH_AVX=${WITH_AVX:-ON}

patches/pybind/cast.h.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ index 3a404602..9054478c 100644
1212
+ return caster;
1313
}
1414
template <typename T>
15-
typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>
15+
typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h
2+
index c1047e4a..e09a6495 100644
3+
--- a/include/pybind11/detail/internals.h
4+
+++ b/include/pybind11/detail/internals.h
5+
@@ -193,11 +193,18 @@ struct internals {
6+
PyTypeObject *default_metaclass;
7+
PyObject *instance_base;
8+
#if defined(WITH_THREAD)
9+
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8
10+
+#pragma GCC diagnostic push
11+
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
12+
+#endif
13+
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
14+
PYBIND11_TLS_KEY_INIT(tstate)
15+
# if PYBIND11_INTERNALS_VERSION > 4
16+
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
17+
# endif // PYBIND11_INTERNALS_VERSION > 4
18+
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8
19+
+#pragma GCC diagnostic pop
20+
+#endif
21+
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
22+
PyInterpreterState *istate = nullptr;

python/paddle/hapi/callbacks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1279,10 +1279,10 @@ def _reset(self):
12791279
self.mode == 'auto' and 'acc' not in self.monitor
12801280
):
12811281
self.monitor_op = lambda a, b: np.less(a, b - self.min_delta)
1282-
self.best = np.Inf
1282+
self.best = np.inf
12831283
else:
12841284
self.monitor_op = lambda a, b: np.greater(a, b + self.min_delta)
1285-
self.best = -np.Inf
1285+
self.best = -np.inf
12861286
self.cooldown_counter = 0
12871287
self.wait = 0
12881288

0 commit comments

Comments
 (0)