Skip to content

Commit 1b34e04

Browse files
Revert "Update pybind11 submodule to 3.0.1 (pytorch#160754)"
This reverts commit 660b0b8. Reverted pytorch#160754 on behalf of https://github.com/atalman due to please see pytorch#160754 (comment) ([comment](pytorch#160754 (comment)))
1 parent 1ce4232 commit 1b34e04

File tree

9 files changed

+83
-27
lines changed

9 files changed

+83
-27
lines changed

.ci/docker/common/install_triton.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if [ ! -f setup.py ]; then
5757
cd python
5858
fi
5959

60-
pip_install pybind11==3.0.1
60+
pip_install pybind11==2.13.6
6161

6262
# TODO: remove patch setup.py once we have a proper fix for https://github.com/triton-lang/triton/issues/4527
6363
as_jenkins sed -i -e 's/https:\/\/tritonlang.blob.core.windows.net\/llvm-builds/https:\/\/oaitriton.blob.core.windows.net\/public\/llvm-builds/g' setup.py

.ci/pytorch/check_binary.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,24 @@ except RuntimeError as e:
300300
exit 1
301301
fi
302302
fi
303+
304+
###############################################################################
305+
# Check for C++ ABI compatibility to GCC-11 - GCC 13
306+
###############################################################################
307+
if [[ "$(uname)" == 'Linux' && "$PACKAGE_TYPE" == 'manywheel' ]]; then
308+
pushd /tmp
309+
# Per https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
310+
# gcc-11 is ABI16, gcc-13 is ABI18, gcc-14 is ABI19
311+
# gcc 11 - CUDA 11.8, xpu, rocm
312+
# gcc 13 - CUDA 12.6, 12.8 and cpu
313+
# Please see issue for reference: https://github.com/pytorch/pytorch/issues/152426
314+
if [[ "$(uname -m)" == "s390x" ]]; then
315+
cxx_abi="19"
316+
elif [[ "$DESIRED_CUDA" != 'xpu' && "$DESIRED_CUDA" != 'rocm'* ]]; then
317+
cxx_abi="18"
318+
else
319+
cxx_abi="16"
320+
fi
321+
python -c "import torch; exit(0 if torch._C._PYBIND11_BUILD_ABI == '_cxxabi10${cxx_abi}' else 1)"
322+
popd
323+
fi

.github/workflows/build-triton-wheel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
fi
146146
147147
docker exec -t "${container_name}" yum install -y zlib-devel zip
148-
docker exec -t "${container_name}" "${PYTHON_EXECUTABLE}" -m pip install -U setuptools==78.1.0 pybind11==3.0.1 auditwheel wheel
148+
docker exec -t "${container_name}" "${PYTHON_EXECUTABLE}" -m pip install -U setuptools==78.1.0 pybind11==2.13.1 auditwheel wheel
149149
set +e
150150
docker exec -t "${container_name}" command -v pip
151151
has_pip=$?

.github/workflows/test-check-binary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
name: Test check_binary.sh for Linux CUDA
3131
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
3232
with:
33-
runner: linux.g4dn.4xlarge.nvidia.gpu
33+
runner: linux.4xlarge.nvidia.gpu
3434
docker-image: python:3.11
3535
docker-build-dir: "skip-docker-build"
3636
script: |

test/dynamo/test_error_messages.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,6 @@ def f(x):
519519
first_graph_break = next(iter(counters["graph_break"].keys()))
520520

521521
first_graph_break = re.sub(r"mylib(_v\d+)?", "mylib", first_graph_break)
522-
# HACK: this patches around the fact that PyBind11 improperly sets the
523-
# __qualname__ attribute on functions and methods; see
524-
# https://github.com/pybind/pybind11/issues/5774. This should be removed if
525-
# that issue is fixed.
526-
first_graph_break = re.sub(
527-
r"pybind11_detail_function_record_v[^ .]+", "PyCapsule", first_graph_break
528-
)
529522

530523
self.assertExpectedInline(
531524
first_graph_break,

test/profiler/test_profiler_tree.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,6 @@ def fmt_name(name: str) -> str:
191191
name,
192192
)
193193

194-
# HACK: this patches around the fact that PyBind11 improperly sets the
195-
# __qualname__ attribute on functions and methods; see
196-
# https://github.com/pybind/pybind11/issues/5774. This should be removed if
197-
# that issue is fixed.
198-
name = re.sub(
199-
r"pybind11_builtins\.pybind11_detail_function_record_v[^ .]+",
200-
"PyCapsule",
201-
name,
202-
)
203-
204194
return re.sub("object at 0x[0-9a-fA-F]+>", "object at 0xXXXXXXXXXXXX>", name)
205195

206196
@classmethod

third_party/pybind11

Submodule pybind11 updated 257 files

torch/csrc/Module.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ static PyObject* THPModule_qEngine(PyObject* _unused, PyObject* noargs) {
13621362
static PyObject* THPModule_supportedQEngines(
13631363
PyObject* _unused,
13641364
PyObject* noargs) {
1365-
const auto& qengines = at::globalContext().supportedQEngines();
1365+
auto qengines = at::globalContext().supportedQEngines();
13661366
auto list =
13671367
THPObjectPtr(PyList_New(static_cast<Py_ssize_t>(qengines.size())));
13681368
if (!list)
@@ -2473,16 +2473,13 @@ Call this whenever a new thread is created in order to propagate values from
24732473
});
24742474

24752475
py_module.def(
2476-
"_get_fp32_precision_getter",
2477-
[](const std::string& backend, const std::string& op) {
2476+
"_get_fp32_precision_getter", [](std::string backend, std::string op) {
24782477
return at::globalContext().float32Precision(backend, op);
24792478
});
24802479

24812480
py_module.def(
24822481
"_set_fp32_precision_setter",
2483-
[](const std::string& backend,
2484-
const std::string& op,
2485-
const std::string& precision) {
2482+
[](std::string backend, std::string op, std::string precision) {
24862483
at::globalContext().setFloat32Precision(backend, op, precision);
24872484
return precision;
24882485
});
@@ -2604,6 +2601,30 @@ Call this whenever a new thread is created in order to propagate values from
26042601

26052602
ASSERT_TRUE(set_module_attr("_GLIBCXX_USE_CXX11_ABI", Py_True));
26062603

2604+
// See note [Pybind11 ABI constants]
2605+
#define SET_STR_DEFINE(name) \
2606+
ASSERT_TRUE(set_module_attr("_" #name, THPUtils_packString(name)))
2607+
2608+
#ifdef PYBIND11_COMPILER_TYPE
2609+
SET_STR_DEFINE(PYBIND11_COMPILER_TYPE);
2610+
#else
2611+
ASSERT_TRUE(
2612+
set_module_attr("_" C10_STRINGIZE(PYBIND11_COMPILER_TYPE), Py_None));
2613+
#endif
2614+
2615+
#ifdef PYBIND11_STDLIB
2616+
SET_STR_DEFINE(PYBIND11_STDLIB);
2617+
#else
2618+
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_STDLIB), Py_None));
2619+
#endif
2620+
2621+
#ifdef PYBIND11_BUILD_ABI
2622+
SET_STR_DEFINE(PYBIND11_BUILD_ABI);
2623+
#else
2624+
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_BUILD_ABI), Py_None));
2625+
#endif
2626+
#undef SET_STR_DEFINE
2627+
26072628
py_module.def(
26082629
"_set_conj", [](const at::Tensor& x, bool conj) { x._set_conj(conj); });
26092630
py_module.def(

torch/utils/cpp_extension.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,15 @@ def build_extensions(self) -> None:
689689
# min supported CPython version.
690690
# See https://docs.python.org/3/c-api/stable.html#c.Py_LIMITED_API
691691
self._add_compile_flag(extension, f'-DPy_LIMITED_API={min_supported_cpython}')
692+
else:
693+
# pybind11 is not CPython API stable so don't add these flags used when
694+
# compiling pybind11 when pybind11 is not even used. otherwise, the build
695+
# logs are confusing.
696+
# See note [Pybind11 ABI constants]
697+
for name in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
698+
val = getattr(torch._C, f"_PYBIND11_{name}")
699+
if val is not None and not IS_WINDOWS:
700+
self._add_compile_flag(extension, f'-DPYBIND11_{name}="{val}"')
692701
self._define_torch_extension_name(extension)
693702

694703
if 'nvcc_dlink' in extension.extra_compile_args:
@@ -1705,6 +1714,25 @@ def load(name,
17051714
is_standalone,
17061715
keep_intermediates=keep_intermediates)
17071716

1717+
def _get_pybind11_abi_build_flags():
1718+
# Note [Pybind11 ABI constants]
1719+
#
1720+
# Pybind11 before 2.4 used to build an ABI strings using the following pattern:
1721+
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_BUILD_TYPE}__"
1722+
# Since 2.4 compier type, stdlib and build abi parameters are also encoded like this:
1723+
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_COMPILER_TYPE}{PYBIND11_STDLIB}{PYBIND11_BUILD_ABI}{PYBIND11_BUILD_TYPE}__"
1724+
#
1725+
# This was done in order to further narrow down the chances of compiler ABI incompatibility
1726+
# that can cause a hard to debug segfaults.
1727+
# For PyTorch extensions we want to relax those restrictions and pass compiler, stdlib and abi properties
1728+
# captured during PyTorch native library compilation in torch/csrc/Module.cpp
1729+
1730+
abi_cflags = []
1731+
for pname in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
1732+
pval = getattr(torch._C, f"_PYBIND11_{pname}")
1733+
if pval is not None and not IS_WINDOWS:
1734+
abi_cflags.append(f'-DPYBIND11_{pname}=\\"{pval}\\"')
1735+
return abi_cflags
17081736

17091737
def check_compiler_is_gcc(compiler):
17101738
if not IS_LINUX:
@@ -1835,6 +1863,7 @@ def build_precompile_header(pch_cmd):
18351863
common_cflags += ['-DTORCH_API_INCLUDE_EXTENSION_H']
18361864

18371865
common_cflags += ['-std=c++17', '-fPIC']
1866+
common_cflags += [f"{x}" for x in _get_pybind11_abi_build_flags()]
18381867
common_cflags_str = listToString(common_cflags)
18391868

18401869
pch_cmd = format_precompiler_header_cmd(compiler, head_file, head_file_pch, common_cflags_str, torch_include_dirs_str, extra_cflags_str, extra_include_paths_str)
@@ -2669,6 +2698,8 @@ def _write_ninja_file_to_build_library(path,
26692698
common_cflags.append(f'-DTORCH_EXTENSION_NAME={name}')
26702699
common_cflags.append('-DTORCH_API_INCLUDE_EXTENSION_H')
26712700

2701+
common_cflags += [f"{x}" for x in _get_pybind11_abi_build_flags()]
2702+
26722703
# Windows does not understand `-isystem` and quotes flags later.
26732704
if IS_WINDOWS:
26742705
common_cflags += [f'-I{include}' for include in user_includes + system_includes]

0 commit comments

Comments
 (0)