[Build] Migrate vendored DeepGEMM from pybind to TORCH_LIBRARY (abi3) (#48962)

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Co-authored-by: Shengqi Chen <harry-chen@outlook.com>
This commit is contained in:
Chris Leonard
2026-10-06 08:39:04 -07:00
committed by GitHub
co-authored by Shengqi Chen
parent cbe1f9740d
commit cc73cca9c8
5 changed files with 105 additions and 155 deletions
+32 -28
View File
@@ -1,41 +1,45 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Assert the installed vLLM has a `_C.cpython-X.Y-*.so` for every CPython
covered by `requires-python`. Fails closed if a Python's `.so` is missing
from the wheel — i.e. the regression that surfaced in #41476/#41512.
"""Assert the vendored DeepGEMM package has the TORCH_LIBRARY binding layout.
Run from a CI test job after vLLM is installed, e.g. the H100 deepgemm
kernel tests in .buildkite/test_areas/kernels.yaml.
Expects ``deep_gemm/_C.py`` plus a single ``_C_extension*.so`` (abi3) under
``vllm.third_party.deep_gemm``. Run after vLLM is installed, e.g. the H100
deepgemm kernel tests in .buildkite/test_areas/kernels.yaml.
"""
import importlib.util
import os
import sys
from pathlib import Path
import regex as re
import tomllib
SO_RE = re.compile(r"^_C\.cpython-(\d)(\d+)-")
def main() -> int:
spec = importlib.util.find_spec("vllm.third_party.deep_gemm")
if spec is None or spec.origin is None:
print(
"vllm.third_party.deep_gemm not importable; is vllm installed?",
file=sys.stderr,
)
return 1
pkg_dir = Path(spec.origin).parent
shim = pkg_dir / "_C.py"
so_files = sorted(pkg_dir.glob("_C_extension*.so"))
missing = []
if not shim.is_file():
missing.append("_C.py")
if len(so_files) != 1:
missing.append("exactly one _C_extension*.so")
print(
f"deepgemm vendored binding: shim={shim.is_file()}, "
f"extensions={[p.name for p in so_files]}"
)
if missing:
print(f"missing: {missing}", file=sys.stderr)
return 1
return 0
def required_pythons() -> list[str]:
pyproject = Path(__file__).resolve().parent.parent / "pyproject.toml"
spec = tomllib.loads(pyproject.read_text())["project"]["requires-python"]
m = re.match(r">=3\.(\d+),<3\.(\d+)", spec)
if not m:
sys.exit(f"unexpected requires-python format: {spec!r}")
return [f"3.{v}" for v in range(int(m[1]), int(m[2]))]
spec = importlib.util.find_spec("vllm.third_party.deep_gemm")
if spec is None or spec.origin is None:
sys.exit("vllm.third_party.deep_gemm not importable; is vllm installed?")
pkg_dir = Path(spec.origin).parent
found = {f"{m[1]}.{m[2]}" for f in os.listdir(pkg_dir) if (m := SO_RE.match(f))}
required = required_pythons()
missing = [v for v in required if v not in found]
print(f"deepgemm _C: found {sorted(found)}, required {required}, missing {missing}")
sys.exit(1 if missing else 0)
if __name__ == "__main__":
raise SystemExit(main())