From 5238dd92d5832789af6feb5a3a7de3cf59bd434b Mon Sep 17 00:00:00 2001 From: Conroy Cheers Date: Fri, 13 Jun 2025 18:27:05 +1000 Subject: [PATCH 1/3] python312Packages.py-libnuma: init at 1.2 --- .../python-modules/py-libnuma/default.nix | 47 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 49 insertions(+) create mode 100644 pkgs/development/python-modules/py-libnuma/default.nix diff --git a/pkgs/development/python-modules/py-libnuma/default.nix b/pkgs/development/python-modules/py-libnuma/default.nix new file mode 100644 index 000000000000..21e2d05547e0 --- /dev/null +++ b/pkgs/development/python-modules/py-libnuma/default.nix @@ -0,0 +1,47 @@ +{ + lib, + stdenv, + buildPythonPackage, + fetchFromGitHub, + pythonOlder, + setuptools, + numactl, +}: + +buildPythonPackage rec { + pname = "py-libnuma"; + version = "1.2"; + pyproject = true; + + src = fetchFromGitHub { + owner = "eedalong"; + repo = "pynuma"; + rev = "66cab0e008b850a04cfec5c4fb3f50bf28e3d488"; + hash = "sha256-ALYCcdN5eXrVWsTRwkHCwo4xsLMs/du3mUl1xSlo5iU="; + }; + + postPatch = '' + substituteInPlace numa/__init__.py \ + --replace-fail \ + 'LIBNUMA = CDLL(find_library("numa"))' \ + 'LIBNUMA = CDLL("${numactl}/lib/libnuma${stdenv.hostPlatform.extensions.sharedLibrary}")' + ''; + + build-system = [ setuptools ]; + + dependencies = [ + numactl + ]; + + # Tests write NUMA configuration, which may be persistent until reboot. + doCheck = false; + + pythonImportsCheck = [ "numa" ]; + + meta = { + description = "Python3 Interface to numa Linux library"; + homepage = "https://github.com/eedalong/pynuma"; + platforms = lib.platforms.linux; + license = lib.licenses.mit; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 4ee283b41fc4..a702e61d513d 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -11978,6 +11978,8 @@ self: super: with self; { py-improv-ble-client = callPackage ../development/python-modules/py-improv-ble-client { }; + py-libnuma = callPackage ../development/python-modules/py-libnuma { }; + py-libzfs = callPackage ../development/python-modules/py-libzfs { }; py-lru-cache = callPackage ../development/python-modules/py-lru-cache { }; From 5b0471b7ea062d0fb06c51111fe1e3379a8f5dfc Mon Sep 17 00:00:00 2001 From: Conroy Cheers Date: Thu, 12 Jun 2025 18:22:03 +1000 Subject: [PATCH 2/3] python312Packages.xgrammar: 0.1.16 -> 0.1.19 --- ...fix-find-nanobind-from-python-module.patch | 41 +++++++++++++++++++ .../python-modules/xgrammar/default.nix | 17 ++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/python-modules/xgrammar/0001-fix-find-nanobind-from-python-module.patch diff --git a/pkgs/development/python-modules/xgrammar/0001-fix-find-nanobind-from-python-module.patch b/pkgs/development/python-modules/xgrammar/0001-fix-find-nanobind-from-python-module.patch new file mode 100644 index 000000000000..bedcb2211665 --- /dev/null +++ b/pkgs/development/python-modules/xgrammar/0001-fix-find-nanobind-from-python-module.patch @@ -0,0 +1,41 @@ +From c01e056ee845ae973ec36cc50125492ef8c02c12 Mon Sep 17 00:00:00 2001 +From: Conroy Cheers +Date: Thu, 12 Jun 2025 17:45:27 +1000 +Subject: [PATCH] [Fix] find nanobind from Python module + +--- + cpp/nanobind/CMakeLists.txt | 4 ++++ + pyproject.toml | 2 +- + 2 files changed, 5 insertions(+), 1 deletion(-) + +diff --git a/cpp/nanobind/CMakeLists.txt b/cpp/nanobind/CMakeLists.txt +index 8ea5622..02500ac 100644 +--- a/cpp/nanobind/CMakeLists.txt ++++ b/cpp/nanobind/CMakeLists.txt +@@ -3,6 +3,10 @@ find_package( + COMPONENTS Interpreter Development.Module + REQUIRED + ) ++ ++execute_process( ++ COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir ++ OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR) + find_package(nanobind CONFIG REQUIRED) + + # Compile this source file seperately. Nanobind suggests to optimize bindings code for size, but +diff --git a/pyproject.toml b/pyproject.toml +index 11fae7d..d2078b1 100644 +--- a/pyproject.toml ++++ b/pyproject.toml +@@ -44,7 +44,7 @@ provider = "scikit_build_core.metadata.regex" + input = "python/xgrammar/version.py" + + [build-system] +-requires = ["scikit-build-core>=0.10.0", "nanobind==2.5.0"] ++requires = ["scikit-build-core>=0.10.0", "nanobind>=2.5.0"] + build-backend = "scikit_build_core.build" + + [tool.scikit-build] +-- +2.49.0 + diff --git a/pkgs/development/python-modules/xgrammar/default.nix b/pkgs/development/python-modules/xgrammar/default.nix index 90caf1208c0f..78cf62927f6d 100644 --- a/pkgs/development/python-modules/xgrammar/default.nix +++ b/pkgs/development/python-modules/xgrammar/default.nix @@ -7,7 +7,7 @@ # build-system cmake, ninja, - pybind11, + nanobind, scikit-build-core, # dependencies @@ -25,7 +25,7 @@ buildPythonPackage rec { pname = "xgrammar"; - version = "0.1.14"; + version = "0.1.19"; pyproject = true; src = fetchFromGitHub { @@ -33,13 +33,17 @@ buildPythonPackage rec { repo = "xgrammar"; tag = "v${version}"; fetchSubmodules = true; - hash = "sha256-ohsoc3g5XUp9vSXxyOGj20wXzCXZC02ktHYVQjDqNeM="; + hash = "sha256-0b2tJx1D/2X/uosbthHfevUpTCBtuSKNlxOKyidTotA="; }; + patches = [ + ./0001-fix-find-nanobind-from-python-module.patch + ]; + build-system = [ cmake ninja - pybind11 + nanobind scikit-build-core ]; dontUseCmakeConfigure = true; @@ -61,6 +65,11 @@ buildPythonPackage rec { writableTmpDirAsHomeHook ]; + NIX_CFLAGS_COMPILE = toString [ + # xgrammar hardcodes -flto=auto while using static linking, which can cause linker errors without this additional flag. + "-ffat-lto-objects" + ]; + disabledTests = [ # You are trying to access a gated repo. "test_grammar_compiler" From e58aa1c6e0f6fcb98d2fee3c9be5697baaef8ef7 Mon Sep 17 00:00:00 2001 From: Conroy Cheers Date: Fri, 13 Jun 2025 18:27:16 +1000 Subject: [PATCH 3/3] python312Packages.vllm: 0.9.0.1 -> 0.9.1 --- .../vllm/0005-drop-intel-reqs.patch | 21 +++++-- .../python-modules/vllm/default.nix | 59 +++++++++++-------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/pkgs/development/python-modules/vllm/0005-drop-intel-reqs.patch b/pkgs/development/python-modules/vllm/0005-drop-intel-reqs.patch index d324661f149a..9bf7d3cdf4d8 100644 --- a/pkgs/development/python-modules/vllm/0005-drop-intel-reqs.patch +++ b/pkgs/development/python-modules/vllm/0005-drop-intel-reqs.patch @@ -1,12 +1,25 @@ +From 7511784ceb9252091a9d63ac6b54dcc67dd2b262 Mon Sep 17 00:00:00 2001 +From: Conroy Cheers +Date: Fri, 13 Jun 2025 17:42:10 +1000 +Subject: [PATCH] drop intel reqs + +--- + requirements/cpu.txt | 3 --- + 1 file changed, 3 deletions(-) + diff --git a/requirements/cpu.txt b/requirements/cpu.txt -index 121330158..d41918883 100644 +index d7b0fc6d8..be2df751b 100644 --- a/requirements/cpu.txt +++ b/requirements/cpu.txt -@@ -20,7 +20,3 @@ datasets # for benchmark scripts - +@@ -24,8 +24,5 @@ datasets # for benchmark scripts # cpu cannot use triton 3.3.0 triton==3.2.0; platform_machine == "x86_64" -- + -# Intel Extension for PyTorch, only for x86_64 CPUs -intel-openmp==2024.2.1; platform_machine == "x86_64" -intel_extension_for_pytorch==2.7.0; platform_machine == "x86_64" + py-libnuma; platform_system != "Darwin" + psutil; platform_system != "Darwin" +-- +2.49.0 + diff --git a/pkgs/development/python-modules/vllm/default.nix b/pkgs/development/python-modules/vllm/default.nix index d17725026613..33f3ef4369c7 100644 --- a/pkgs/development/python-modules/vllm/default.nix +++ b/pkgs/development/python-modules/vllm/default.nix @@ -3,6 +3,7 @@ stdenv, python, buildPythonPackage, + pythonAtLeast, fetchFromGitHub, fetchpatch, symlinkJoin, @@ -67,6 +68,7 @@ opentelemetry-exporter-otlp, bitsandbytes, flashinfer, + py-libnuma, # internal dependency - for overriding in overlays vllm-flash-attn ? null, @@ -246,16 +248,19 @@ in buildPythonPackage rec { pname = "vllm"; - version = "0.9.0.1"; + version = "0.9.1"; pyproject = true; + # https://github.com/vllm-project/vllm/issues/12083 + disabled = pythonAtLeast "3.13"; + stdenv = torch.stdenv; src = fetchFromGitHub { owner = "vllm-project"; repo = "vllm"; tag = "v${version}"; - hash = "sha256-gNe/kdsDQno8Fd6mo29feWmbyC0c2+kljlVxY4v7R9U="; + hash = "sha256-sp7rDpewTPXTVRBJHJMj+8pJDS6wAu0/OTJZwbPPqKc="; }; patches = [ @@ -264,34 +269,33 @@ buildPythonPackage rec { url = "https://github.com/vllm-project/vllm/commit/6a5d7e45f52c3a13de43b8b4fa9033e3b342ebd2.patch"; hash = "sha256-KYthqu+6XwsYYd80PtfrMMjuRV9+ionccr7EbjE4jJE="; }) + (fetchpatch { + name = "fall-back-to-gloo-when-nccl-unavailable.patch"; + url = "https://github.com/vllm-project/vllm/commit/aa131a94410683b0a02e74fed2ce95e6c2b6b030.patch"; + hash = "sha256-jNlQZQ8xiW85JWyBjsPZ6FoRQsiG1J8bwzmQjnaWFBg="; + }) ./0002-setup.py-nix-support-respect-cmakeFlags.patch ./0003-propagate-pythonpath.patch ./0004-drop-lsmod.patch ./0005-drop-intel-reqs.patch ]; - postPatch = - '' - # pythonRelaxDeps does not cover build-system - substituteInPlace pyproject.toml \ - --replace-fail "torch ==" "torch >=" + postPatch = '' + # pythonRelaxDeps does not cover build-system + substituteInPlace pyproject.toml \ + --replace-fail "torch ==" "torch >=" - # Ignore the python version check because it hard-codes minor versions and - # lags behind `ray`'s python interpreter support - substituteInPlace CMakeLists.txt \ - --replace-fail \ - 'set(PYTHON_SUPPORTED_VERSIONS' \ - 'set(PYTHON_SUPPORTED_VERSIONS "${lib.versions.majorMinor python.version}"' + # Ignore the python version check because it hard-codes minor versions and + # lags behind `ray`'s python interpreter support + substituteInPlace CMakeLists.txt \ + --replace-fail \ + 'set(PYTHON_SUPPORTED_VERSIONS' \ + 'set(PYTHON_SUPPORTED_VERSIONS "${lib.versions.majorMinor python.version}"' - # Pass build environment PYTHONPATH to vLLM's Python configuration scripts - substituteInPlace CMakeLists.txt \ - --replace-fail '$PYTHONPATH' '$ENV{PYTHONPATH}' - '' - + lib.optionalString (nccl == null) '' - # On platforms where NCCL is not supported (e.g. Jetson), substitute Gloo (provided by Torch) - substituteInPlace vllm/distributed/parallel_state.py \ - --replace-fail '"nccl"' '"gloo"' - ''; + # Pass build environment PYTHONPATH to vLLM's Python configuration scripts + substituteInPlace CMakeLists.txt \ + --replace-fail '$PYTHONPATH' '$ENV{PYTHONPATH}' + ''; nativeBuildInputs = [ @@ -362,7 +366,6 @@ buildPythonPackage rec { outlines pandas prometheus-fastapi-instrumentator - psutil py-cpuinfo pyarrow pydantic @@ -392,9 +395,15 @@ buildPythonPackage rec { opentelemetry-api opentelemetry-exporter-otlp bitsandbytes + # vLLM needs Torch's compiler to be present in order to use torch.compile + torch.stdenv.cc ] ++ uvicorn.optional-dependencies.standard ++ aioprometheus.optional-dependencies.starlette + ++ lib.optionals stdenv.targetPlatform.isLinux [ + py-libnuma + psutil + ] ++ lib.optionals cudaSupport [ cupy pynvml @@ -404,11 +413,11 @@ buildPythonPackage rec { dontUseCmakeConfigure = true; cmakeFlags = [ + ] + ++ lib.optionals cudaSupport [ (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CUTLASS" "${lib.getDev cutlass}") (lib.cmakeFeature "FLASH_MLA_SRC_DIR" "${lib.getDev flashmla}") (lib.cmakeFeature "VLLM_FLASH_ATTN_SRC_DIR" "${lib.getDev vllm-flash-attn'}") - ] - ++ lib.optionals cudaSupport [ (lib.cmakeFeature "TORCH_CUDA_ARCH_LIST" "${gpuTargetString}") (lib.cmakeFeature "CUTLASS_NVCC_ARCHS_ENABLED" "${cudaPackages.flags.cmakeCudaArchitecturesString}") (lib.cmakeFeature "CUDA_TOOLKIT_ROOT_DIR" "${symlinkJoin {