diff --git a/.ci/docker/common/install_triton.sh b/.ci/docker/common/install_triton.sh index a965f0f743d4..f48140952c3a 100755 --- a/.ci/docker/common/install_triton.sh +++ b/.ci/docker/common/install_triton.sh @@ -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 diff --git a/.ci/pytorch/check_binary.sh b/.ci/pytorch/check_binary.sh index 78baf6a0761d..0f632f8006c0 100755 --- a/.ci/pytorch/check_binary.sh +++ b/.ci/pytorch/check_binary.sh @@ -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 diff --git a/.github/workflows/build-triton-wheel.yml b/.github/workflows/build-triton-wheel.yml index e0f1027b8a19..932d9c886302 100644 --- a/.github/workflows/build-triton-wheel.yml +++ b/.github/workflows/build-triton-wheel.yml @@ -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=$? diff --git a/.github/workflows/test-check-binary.yml b/.github/workflows/test-check-binary.yml index 0d31948f196a..5f0ad59d3a3b 100644 --- a/.github/workflows/test-check-binary.yml +++ b/.github/workflows/test-check-binary.yml @@ -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: | diff --git a/test/dynamo/test_error_messages.py b/test/dynamo/test_error_messages.py index e91e7ef52097..f525cd84b680 100644 --- a/test/dynamo/test_error_messages.py +++ b/test/dynamo/test_error_messages.py @@ -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, diff --git a/test/profiler/test_profiler_tree.py b/test/profiler/test_profiler_tree.py index bb605f008fec..75883c278b61 100644 --- a/test/profiler/test_profiler_tree.py +++ b/test/profiler/test_profiler_tree.py @@ -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 diff --git a/third_party/pybind11 b/third_party/pybind11 index a2e59f0e7065..f5fbe867d2d2 160000 --- a/third_party/pybind11 +++ b/third_party/pybind11 @@ -1 +1 @@ -Subproject commit a2e59f0e7065404b44dfe92a28aca47ba1378dc4 +Subproject commit f5fbe867d2d26e4a0a9177a51f6e568868ad3dc8 diff --git a/torch/csrc/Module.cpp b/torch/csrc/Module.cpp index 1f98b89bbfe5..2238e72f62ea 100644 --- a/torch/csrc/Module.cpp +++ b/torch/csrc/Module.cpp @@ -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(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( diff --git a/torch/utils/cpp_extension.py b/torch/utils/cpp_extension.py index 5c0d65ca4f20..f23ae6aafff7 100644 --- a/torch/utils/cpp_extension.py +++ b/torch/utils/cpp_extension.py @@ -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]