Commit 4fb7cb4a authored by Someone Serge's avatar Someone Serge
Browse files

python311Packages.vllm: postPatch -> patches

parent d40fd0fd
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
From f6a7748bee79fc2e1898968fef844daacfa7860b Mon Sep 17 00:00:00 2001
From: SomeoneSerge <else@someonex.net>
Date: Wed, 31 Jul 2024 12:02:53 +0000
Subject: [PATCH 1/2] setup.py: don't ask for hipcc --version

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 72ef26f1..01e006f9 100644
--- a/setup.py
+++ b/setup.py
@@ -279,6 +279,7 @@ def _install_punica() -> bool:
 
 
 def get_hipcc_rocm_version():
+    return "0.0" # `hipcc --version` misbehaves ("unresolved paths") inside the nix sandbox
     # Run the hipcc --version command
     result = subprocess.run(['hipcc', '--version'],
                             stdout=subprocess.PIPE,
-- 
2.45.1
+40 −0
Original line number Diff line number Diff line
From 10b7e8330bdba319a4162cceb8e5dd4280215b04 Mon Sep 17 00:00:00 2001
From: SomeoneSerge <else@someonex.net>
Date: Wed, 31 Jul 2024 12:06:15 +0000
Subject: [PATCH 2/2] setup.py: nix-support (respect cmakeFlags)

---
 setup.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/setup.py b/setup.py
index 01e006f9..14762146 100644
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,15 @@ from setuptools import Extension, find_packages, setup
 from setuptools.command.build_ext import build_ext
 from torch.utils.cpp_extension import CUDA_HOME
 
+import os
+import json
+
+if "NIX_ATTRS_JSON_FILE" in os.environ:
+    with open(os.environ["NIX_ATTRS_JSON_FILE"], "r") as f:
+        NIX_ATTRS = json.load(f)
+else:
+    NIX_ATTRS = { "cmakeFlags": os.environ.get("cmakeFlags", "").split() }
+
 
 def load_module_from_path(module_name, path):
     spec = importlib.util.spec_from_file_location(module_name, path)
@@ -159,6 +168,7 @@ class cmake_build_ext(build_ext):
             '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}'.format(outdir),
             '-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY={}'.format(self.build_temp),
             '-DVLLM_TARGET_DEVICE={}'.format(VLLM_TARGET_DEVICE),
+            *NIX_ATTRS["cmakeFlags"],
         ]
 
         verbose = envs.VERBOSE
-- 
2.45.1
+5 −10
Original line number Diff line number Diff line
@@ -69,16 +69,10 @@ buildPythonPackage rec {
    hash = "sha256-++DK2Y2zz+1KrEcdQc5XFrSjc7fCwMD2DQ/RqY7PoFU=";
  };

  # hipcc --version works badly on NixOS due to unresolved paths.
  postPatch =
    ''
      substituteInPlace setup.py \
        --replace 'cmake_args = [' 'cmake_args = ["-DFETCHCONTENT_SOURCE_DIR_CUTLASS=${cutlass}",'
    ''
    + lib.optionalString rocmSupport ''
      substituteInPlace setup.py \
        --replace "'hipcc', '--version'" "'${writeShellScript "hipcc-version-stub" "echo HIP version: 0.0"}'"
    '';
  patches = [
    ./0001-setup.py-don-t-ask-for-hipcc-version.patch
    ./0002-setup.py-nix-support-respect-cmakeFlags.patch
  ];

  nativeBuildInputs = [
    cmake
@@ -149,6 +143,7 @@ buildPythonPackage rec {
    ];

  dontUseCmakeConfigure = true;
  cmakeFlags = [ (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CUTLASS" "${lib.getDev cutlass}") ];

  # Otherwise it tries to enumerate host supported ROCM gfx archs, and that is not possible due to sandboxing.
  PYTORCH_ROCM_ARCH = lib.optionalString rocmSupport (