Skip to content

Commit 660b0b8

Browse files
benjaminglass1pytorchmergebot
authored andcommitted
Update pybind11 submodule to 3.0.1 (#160754)
Upgrade to PyBind11 v3. This allows us to strip out our own (possibly broken?) handling of the C++ ABI when building extensions, in favor of the more-complete PyBind11 internal handling. Fixes a few test failures due to pybind/pybind11#5774, which effectively makes the `__qualname__` attribute of functions platform-dependent. Test plan: CI Pull Request resolved: #160754 Approved by: https://github.com/Skylion007
1 parent 089ad1d commit 660b0b8

File tree

9 files changed

+27
-83
lines changed

9 files changed

+27
-83
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==2.13.6
60+
pip_install pybind11==3.0.1
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: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,3 @@ 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==2.13.1 auditwheel wheel
148+
docker exec -t "${container_name}" "${PYTHON_EXECUTABLE}" -m pip install -U setuptools==78.1.0 pybind11==3.0.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.4xlarge.nvidia.gpu
33+
runner: linux.g4dn.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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,13 @@ 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+
)
522529

523530
self.assertExpectedInline(
524531
first_graph_break,

test/profiler/test_profiler_tree.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ 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+
194204
return re.sub("object at 0x[0-9a-fA-F]+>", "object at 0xXXXXXXXXXXXX>", name)
195205

196206
@classmethod

third_party/pybind11

Submodule pybind11 updated 257 files

torch/csrc/Module.cpp

Lines changed: 6 additions & 27 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-
auto qengines = at::globalContext().supportedQEngines();
1365+
const auto& qengines = at::globalContext().supportedQEngines();
13661366
auto list =
13671367
THPObjectPtr(PyList_New(static_cast<Py_ssize_t>(qengines.size())));
13681368
if (!list)
@@ -2481,13 +2481,16 @@ Call this whenever a new thread is created in order to propagate values from
24812481
});
24822482

24832483
py_module.def(
2484-
"_get_fp32_precision_getter", [](std::string backend, std::string op) {
2484+
"_get_fp32_precision_getter",
2485+
[](const std::string& backend, const std::string& op) {
24852486
return at::globalContext().float32Precision(backend, op);
24862487
});
24872488

24882489
py_module.def(
24892490
"_set_fp32_precision_setter",
2490-
[](std::string backend, std::string op, std::string precision) {
2491+
[](const std::string& backend,
2492+
const std::string& op,
2493+
const std::string& precision) {
24912494
at::globalContext().setFloat32Precision(backend, op, precision);
24922495
return precision;
24932496
});
@@ -2609,30 +2612,6 @@ Call this whenever a new thread is created in order to propagate values from
26092612

26102613
ASSERT_TRUE(set_module_attr("_GLIBCXX_USE_CXX11_ABI", Py_True));
26112614

2612-
// See note [Pybind11 ABI constants]
2613-
#define SET_STR_DEFINE(name) \
2614-
ASSERT_TRUE(set_module_attr("_" #name, THPUtils_packString(name)))
2615-
2616-
#ifdef PYBIND11_COMPILER_TYPE
2617-
SET_STR_DEFINE(PYBIND11_COMPILER_TYPE);
2618-
#else
2619-
ASSERT_TRUE(
2620-
set_module_attr("_" C10_STRINGIZE(PYBIND11_COMPILER_TYPE), Py_None));
2621-
#endif
2622-
2623-
#ifdef PYBIND11_STDLIB
2624-
SET_STR_DEFINE(PYBIND11_STDLIB);
2625-
#else
2626-
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_STDLIB), Py_None));
2627-
#endif
2628-
2629-
#ifdef PYBIND11_BUILD_ABI
2630-
SET_STR_DEFINE(PYBIND11_BUILD_ABI);
2631-
#else
2632-
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_BUILD_ABI), Py_None));
2633-
#endif
2634-
#undef SET_STR_DEFINE
2635-
26362615
py_module.def(
26372616
"_set_conj", [](const at::Tensor& x, bool conj) { x._set_conj(conj); });
26382617
py_module.def(

torch/utils/cpp_extension.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,6 @@ 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}"')
701692
self._define_torch_extension_name(extension)
702693

703694
if 'nvcc_dlink' in extension.extra_compile_args:
@@ -1714,25 +1705,6 @@ def load(name,
17141705
is_standalone,
17151706
keep_intermediates=keep_intermediates)
17161707

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
17361708

17371709
def check_compiler_is_gcc(compiler):
17381710
if not IS_LINUX:
@@ -1863,7 +1835,6 @@ def build_precompile_header(pch_cmd):
18631835
common_cflags += ['-DTORCH_API_INCLUDE_EXTENSION_H']
18641836

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

18691840
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)
@@ -2698,8 +2669,6 @@ def _write_ninja_file_to_build_library(path,
26982669
common_cflags.append(f'-DTORCH_EXTENSION_NAME={name}')
26992670
common_cflags.append('-DTORCH_API_INCLUDE_EXTENSION_H')
27002671

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

0 commit comments

Comments
 (0)