mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
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 https://github.com/pybind/pybind11/issues/5774, which effectively makes the `__qualname__` attribute of functions platform-dependent. Test plan: CI Pull Request resolved: https://github.com/pytorch/pytorch/pull/160754 Approved by: https://github.com/Skylion007
This commit is contained in:
committed by
PyTorch MergeBot
parent
089ad1d88b
commit
660b0b8128
@ -57,7 +57,7 @@ if [ ! -f setup.py ]; then
|
||||
cd python
|
||||
fi
|
||||
|
||||
pip_install pybind11==2.13.6
|
||||
pip_install pybind11==3.0.1
|
||||
|
||||
# TODO: remove patch setup.py once we have a proper fix for https://github.com/triton-lang/triton/issues/4527
|
||||
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
|
||||
|
@ -300,24 +300,3 @@ except RuntimeError as e:
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
###############################################################################
|
||||
# Check for C++ ABI compatibility to GCC-11 - GCC 13
|
||||
###############################################################################
|
||||
if [[ "$(uname)" == 'Linux' && "$PACKAGE_TYPE" == 'manywheel' ]]; then
|
||||
pushd /tmp
|
||||
# Per https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
|
||||
# gcc-11 is ABI16, gcc-13 is ABI18, gcc-14 is ABI19
|
||||
# gcc 11 - CUDA 11.8, xpu, rocm
|
||||
# gcc 13 - CUDA 12.6, 12.8 and cpu
|
||||
# Please see issue for reference: https://github.com/pytorch/pytorch/issues/152426
|
||||
if [[ "$(uname -m)" == "s390x" ]]; then
|
||||
cxx_abi="19"
|
||||
elif [[ "$DESIRED_CUDA" != 'xpu' && "$DESIRED_CUDA" != 'rocm'* ]]; then
|
||||
cxx_abi="18"
|
||||
else
|
||||
cxx_abi="16"
|
||||
fi
|
||||
python -c "import torch; exit(0 if torch._C._PYBIND11_BUILD_ABI == '_cxxabi10${cxx_abi}' else 1)"
|
||||
popd
|
||||
fi
|
||||
|
2
.github/workflows/build-triton-wheel.yml
vendored
2
.github/workflows/build-triton-wheel.yml
vendored
@ -145,7 +145,7 @@ jobs:
|
||||
fi
|
||||
|
||||
docker exec -t "${container_name}" yum install -y zlib-devel zip
|
||||
docker exec -t "${container_name}" "${PYTHON_EXECUTABLE}" -m pip install -U setuptools==78.1.0 pybind11==2.13.1 auditwheel wheel
|
||||
docker exec -t "${container_name}" "${PYTHON_EXECUTABLE}" -m pip install -U setuptools==78.1.0 pybind11==3.0.1 auditwheel wheel
|
||||
set +e
|
||||
docker exec -t "${container_name}" command -v pip
|
||||
has_pip=$?
|
||||
|
2
.github/workflows/test-check-binary.yml
vendored
2
.github/workflows/test-check-binary.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
||||
name: Test check_binary.sh for Linux CUDA
|
||||
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
|
||||
with:
|
||||
runner: linux.4xlarge.nvidia.gpu
|
||||
runner: linux.g4dn.4xlarge.nvidia.gpu
|
||||
docker-image: python:3.11
|
||||
docker-build-dir: "skip-docker-build"
|
||||
script: |
|
||||
|
@ -519,6 +519,13 @@ Attempted to call function marked as skipped
|
||||
first_graph_break = next(iter(counters["graph_break"].keys()))
|
||||
|
||||
first_graph_break = re.sub(r"mylib(_v\d+)?", "mylib", first_graph_break)
|
||||
# HACK: this patches around the fact that PyBind11 improperly sets the
|
||||
# __qualname__ attribute on functions and methods; see
|
||||
# https://github.com/pybind/pybind11/issues/5774. This should be removed if
|
||||
# that issue is fixed.
|
||||
first_graph_break = re.sub(
|
||||
r"pybind11_detail_function_record_v[^ .]+", "PyCapsule", first_graph_break
|
||||
)
|
||||
|
||||
self.assertExpectedInline(
|
||||
first_graph_break,
|
||||
|
@ -191,6 +191,16 @@ class ProfilerTree:
|
||||
name,
|
||||
)
|
||||
|
||||
# HACK: this patches around the fact that PyBind11 improperly sets the
|
||||
# __qualname__ attribute on functions and methods; see
|
||||
# https://github.com/pybind/pybind11/issues/5774. This should be removed if
|
||||
# that issue is fixed.
|
||||
name = re.sub(
|
||||
r"pybind11_builtins\.pybind11_detail_function_record_v[^ .]+",
|
||||
"PyCapsule",
|
||||
name,
|
||||
)
|
||||
|
||||
return re.sub("object at 0x[0-9a-fA-F]+>", "object at 0xXXXXXXXXXXXX>", name)
|
||||
|
||||
@classmethod
|
||||
|
2
third_party/pybind11
vendored
2
third_party/pybind11
vendored
Submodule third_party/pybind11 updated: a2e59f0e70...f5fbe867d2
@ -1362,7 +1362,7 @@ static PyObject* THPModule_qEngine(PyObject* _unused, PyObject* noargs) {
|
||||
static PyObject* THPModule_supportedQEngines(
|
||||
PyObject* _unused,
|
||||
PyObject* noargs) {
|
||||
auto qengines = at::globalContext().supportedQEngines();
|
||||
const auto& qengines = at::globalContext().supportedQEngines();
|
||||
auto list =
|
||||
THPObjectPtr(PyList_New(static_cast<Py_ssize_t>(qengines.size())));
|
||||
if (!list)
|
||||
@ -2481,13 +2481,16 @@ Call this whenever a new thread is created in order to propagate values from
|
||||
});
|
||||
|
||||
py_module.def(
|
||||
"_get_fp32_precision_getter", [](std::string backend, std::string op) {
|
||||
"_get_fp32_precision_getter",
|
||||
[](const std::string& backend, const std::string& op) {
|
||||
return at::globalContext().float32Precision(backend, op);
|
||||
});
|
||||
|
||||
py_module.def(
|
||||
"_set_fp32_precision_setter",
|
||||
[](std::string backend, std::string op, std::string precision) {
|
||||
[](const std::string& backend,
|
||||
const std::string& op,
|
||||
const std::string& precision) {
|
||||
at::globalContext().setFloat32Precision(backend, op, precision);
|
||||
return precision;
|
||||
});
|
||||
@ -2609,30 +2612,6 @@ Call this whenever a new thread is created in order to propagate values from
|
||||
|
||||
ASSERT_TRUE(set_module_attr("_GLIBCXX_USE_CXX11_ABI", Py_True));
|
||||
|
||||
// See note [Pybind11 ABI constants]
|
||||
#define SET_STR_DEFINE(name) \
|
||||
ASSERT_TRUE(set_module_attr("_" #name, THPUtils_packString(name)))
|
||||
|
||||
#ifdef PYBIND11_COMPILER_TYPE
|
||||
SET_STR_DEFINE(PYBIND11_COMPILER_TYPE);
|
||||
#else
|
||||
ASSERT_TRUE(
|
||||
set_module_attr("_" C10_STRINGIZE(PYBIND11_COMPILER_TYPE), Py_None));
|
||||
#endif
|
||||
|
||||
#ifdef PYBIND11_STDLIB
|
||||
SET_STR_DEFINE(PYBIND11_STDLIB);
|
||||
#else
|
||||
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_STDLIB), Py_None));
|
||||
#endif
|
||||
|
||||
#ifdef PYBIND11_BUILD_ABI
|
||||
SET_STR_DEFINE(PYBIND11_BUILD_ABI);
|
||||
#else
|
||||
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_BUILD_ABI), Py_None));
|
||||
#endif
|
||||
#undef SET_STR_DEFINE
|
||||
|
||||
py_module.def(
|
||||
"_set_conj", [](const at::Tensor& x, bool conj) { x._set_conj(conj); });
|
||||
py_module.def(
|
||||
|
@ -689,15 +689,6 @@ class BuildExtension(build_ext):
|
||||
# min supported CPython version.
|
||||
# See https://docs.python.org/3/c-api/stable.html#c.Py_LIMITED_API
|
||||
self._add_compile_flag(extension, f'-DPy_LIMITED_API={min_supported_cpython}')
|
||||
else:
|
||||
# pybind11 is not CPython API stable so don't add these flags used when
|
||||
# compiling pybind11 when pybind11 is not even used. otherwise, the build
|
||||
# logs are confusing.
|
||||
# See note [Pybind11 ABI constants]
|
||||
for name in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
|
||||
val = getattr(torch._C, f"_PYBIND11_{name}")
|
||||
if val is not None and not IS_WINDOWS:
|
||||
self._add_compile_flag(extension, f'-DPYBIND11_{name}="{val}"')
|
||||
self._define_torch_extension_name(extension)
|
||||
|
||||
if 'nvcc_dlink' in extension.extra_compile_args:
|
||||
@ -1714,25 +1705,6 @@ def load(name,
|
||||
is_standalone,
|
||||
keep_intermediates=keep_intermediates)
|
||||
|
||||
def _get_pybind11_abi_build_flags():
|
||||
# Note [Pybind11 ABI constants]
|
||||
#
|
||||
# Pybind11 before 2.4 used to build an ABI strings using the following pattern:
|
||||
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_BUILD_TYPE}__"
|
||||
# Since 2.4 compier type, stdlib and build abi parameters are also encoded like this:
|
||||
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_COMPILER_TYPE}{PYBIND11_STDLIB}{PYBIND11_BUILD_ABI}{PYBIND11_BUILD_TYPE}__"
|
||||
#
|
||||
# This was done in order to further narrow down the chances of compiler ABI incompatibility
|
||||
# that can cause a hard to debug segfaults.
|
||||
# For PyTorch extensions we want to relax those restrictions and pass compiler, stdlib and abi properties
|
||||
# captured during PyTorch native library compilation in torch/csrc/Module.cpp
|
||||
|
||||
abi_cflags = []
|
||||
for pname in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
|
||||
pval = getattr(torch._C, f"_PYBIND11_{pname}")
|
||||
if pval is not None and not IS_WINDOWS:
|
||||
abi_cflags.append(f'-DPYBIND11_{pname}=\\"{pval}\\"')
|
||||
return abi_cflags
|
||||
|
||||
def check_compiler_is_gcc(compiler):
|
||||
if not IS_LINUX:
|
||||
@ -1863,7 +1835,6 @@ def _check_and_build_extension_h_precompiler_headers(
|
||||
common_cflags += ['-DTORCH_API_INCLUDE_EXTENSION_H']
|
||||
|
||||
common_cflags += ['-std=c++17', '-fPIC']
|
||||
common_cflags += [f"{x}" for x in _get_pybind11_abi_build_flags()]
|
||||
common_cflags_str = listToString(common_cflags)
|
||||
|
||||
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,
|
||||
common_cflags.append(f'-DTORCH_EXTENSION_NAME={name}')
|
||||
common_cflags.append('-DTORCH_API_INCLUDE_EXTENSION_H')
|
||||
|
||||
common_cflags += [f"{x}" for x in _get_pybind11_abi_build_flags()]
|
||||
|
||||
# Windows does not understand `-isystem` and quotes flags later.
|
||||
if IS_WINDOWS:
|
||||
common_cflags += [f'-I{include}' for include in user_includes + system_includes]
|
||||
|
Reference in New Issue
Block a user