Skip to content

Commit

Permalink
python312Packages.bitsandbytes: 0.43.1 -> 0.44.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Oct 20, 2024
1 parent 373bed2 commit eee442b
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions pkgs/development/python-modules/bitsandbytes/default.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
{
lib,
torch,
symlinkJoin,
buildPythonPackage,
fetchFromGitHub,
python,
pythonOlder,
cmake,
setuptools,
wheel,
torch,
scipy,
symlinkJoin,
}:

let
pname = "bitsandbytes";
version = "0.43.1";
version = "0.44.1";

inherit (torch) cudaCapabilities cudaPackages cudaSupport;
inherit (cudaPackages) backendStdenv cudaVersion;
inherit (torch) cudaPackages cudaSupport;
inherit (cudaPackages) cudaVersion;

# NOTE: torchvision doesn't use cudnn; torch does!
# For this reason it is not included.
cuda-common-redist = with cudaPackages; [
cuda_cccl # <thrust/*>
libcublas # cublas_v2.h
cuda_cccl.dev # <thrust/*>
libcublas.dev # cublas_v2.h
libcublas.lib
libcurand
libcusolver # cusolverDn.h
libcusparse # cusparse.h
libcusparse.dev # cusparse.h
libcusparse.lib
];

cuda-native-redist = symlinkJoin {
name = "cuda-native-redist-${cudaVersion}";
paths =
with cudaPackages;
[
cuda_cudart # cuda_runtime.h cuda_runtime_api.h
cuda_cudart.dev # cuda_runtime.h cuda_runtime_api.h
cuda_cudart.lib
cuda_cudart.static
cuda_nvcc
]
++ cuda-common-redist;
Expand All @@ -48,47 +50,38 @@ buildPythonPackage {
inherit pname version;
pyproject = true;

disabled = pythonOlder "3.7";

src = fetchFromGitHub {
owner = "TimDettmers";
repo = "bitsandbytes";
rev = "refs/tags/${version}";
hash = "sha256-GFbFKPdV96DXPA+PZO4h0zdBclN670fb0PGv4QPHWHU=";
hash = "sha256-yvxD5ymMK5p4Xg7Csx/90mPV3yxUC6QUuF/8BKO2p0k=";
};

postPatch =
''
substituteInPlace Makefile --replace "/usr/bin/g++" "g++" --replace "lib64" "lib"
substituteInPlace bitsandbytes/cuda_setup/main.py \
--replace "binary_path = package_dir / self.binary_name" \
"binary_path = Path('$out/${python.sitePackages}/${pname}')/self.binary_name"
''
+ lib.optionalString torch.cudaSupport ''
substituteInPlace bitsandbytes/cuda_setup/main.py \
--replace "/usr/local/cuda/lib64" "${cuda-native-redist}/lib"
'';

CUDA_HOME = "${cuda-native-redist}";

preBuild =
if torch.cudaSupport then
with torch.cudaPackages;
let
cudaVersion = lib.concatStrings (lib.splitVersion torch.cudaPackages.cudaMajorMinorVersion);
in
''make CUDA_VERSION=${cudaVersion} cuda${cudaMajorVersion}x''
else
''make CUDA_VERSION=CPU cpuonly'';

nativeBuildInputs = [
build-system = [
cmake
setuptools
wheel
] ++ lib.optionals torch.cudaSupport [ cuda-native-redist ];
] ++ lib.optionals cudaSupport [ cuda-native-redist ];

dontUseCmakeConfigure = true;

buildInputs = lib.optionals torch.cudaSupport [ cuda-redist ];
buildInputs = lib.optionals cudaSupport [ cuda-redist ];

preBuild =
if cudaSupport then
''
export NVCC_APPEND_FLAGS="-I${cuda-native-redist}/include -L${cuda-native-redist}/lib"
cmake -DCMAKE_CXX_FLAGS="-I${cuda-native-redist}/include" -DCOMPUTE_BACKEND=cuda -S .
make
''
else
''
cmake -DCOMPUTE_BACKEND=cpu -S .
make
'';

propagatedBuildInputs = [
dependencies = [
scipy
torch
];
Expand All @@ -97,11 +90,11 @@ buildPythonPackage {

pythonImportsCheck = [ "bitsandbytes" ];

meta = with lib; {
meta = {
description = "8-bit CUDA functions for PyTorch";
homepage = "https://github.com/TimDettmers/bitsandbytes";
changelog = "https://github.com/TimDettmers/bitsandbytes/releases/tag/${version}";
license = licenses.mit;
maintainers = with maintainers; [ bcdarwin ];
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ bcdarwin ];
};
}

0 comments on commit eee442b

Please sign in to comment.