diff options
author | Ben Sima <ben@bsima.me> | 2023-08-07 17:57:42 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2023-08-07 18:02:13 -0400 |
commit | 44b1f8d5bc2ffcb00f56b0096476501e7e0cd458 (patch) | |
tree | d005a849d15fe8ef59ed7523b7997d6529020125 /Biz/Bild/Deps/bitsandbytes.nix | |
parent | edb55ff54b9f81c0942f4120eedd72357d7b3d7c (diff) |
Get ava.py running with nixified builds
I had to redo some of my python overrides and crib the bitsandbytes.nix
from upstream.
Ava is failing because:
ValueError: Tokenizer class LlamaTokenizer does not exist or is not
currently imported.
I think this means I need to update my nixpkgs pin, so I'm gonna
snapshot my work in git, do the update, and that might obviate the local
bitsandbytes.nix anyway.
Diffstat (limited to 'Biz/Bild/Deps/bitsandbytes.nix')
-rw-r--r-- | Biz/Bild/Deps/bitsandbytes.nix | 144 |
1 files changed, 74 insertions, 70 deletions
diff --git a/Biz/Bild/Deps/bitsandbytes.nix b/Biz/Bild/Deps/bitsandbytes.nix index 8d4fa53..b87c0c4 100644 --- a/Biz/Bild/Deps/bitsandbytes.nix +++ b/Biz/Bild/Deps/bitsandbytes.nix @@ -1,94 +1,98 @@ { lib -, fetchgit , buildPythonPackage -, pytorch +, fetchFromGitHub +, python +, pythonOlder +, pytestCheckHook , setuptools -, typer -, linuxPackages -, pytest - -# CUDA -, cudaSupport ? true -, cudaPackages ? {} -, addOpenGLRunpath ? null -, gcc +, torch +, einops +, lion-pytorch +, scipy +, symlinkJoin }: let - inherit (linuxPackages) nvidia_x11; - inherit (cudaPackages) cudatoolkit; - cudaVersion = - lib.strings.removeSuffix "0" - (lib.strings.concatStrings - (lib.strings.splitString "." cudatoolkit.version)); - libraryPath = lib.strings.makeLibraryPath [ - cudatoolkit - cudatoolkit.lib - nvidia_x11 - ]; -in buildPythonPackage rec { pname = "bitsandbytes"; - version = "unstable-2022-12-21"; + version = "0.38.0"; + + 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 + libcurand + libcusolver # cusolverDn.h + libcusparse # cusparse.h + ]; - src = fetchgit { - url = "https://simatime.com/git/ben/bitsandbytes.git"; - rev = "31ef751bea48eeee2e0e95aca79df8e59b4c25c4"; - sha256 = "sha256-/a2NFVuMSvSDELeXyfDdU9FZEJcDxCLa4VbMWBUCRI0="; + cuda-native-redist = symlinkJoin { + name = "cuda-native-redist-${cudaVersion}"; + paths = with cudaPackages; [ + cuda_cudart # cuda_runtime.h cuda_runtime_api.h + cuda_nvcc + ] ++ cuda-common-redist; }; - # any exe must be wrapped with this, it doesn't effect the build but it does - # show up on the logs so keep it here for documentation purposes - LD_LIBRARY_PATH = libraryPath; + cuda-redist = symlinkJoin { + name = "cuda-redist-${cudaVersion}"; + paths = cuda-common-redist; + }; + +in +buildPythonPackage { + inherit pname version; + format = "pyproject"; - # this allows the build system to find nvcc - CUDA_HOME = "${cudatoolkit}"; + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "TimDettmers"; + repo = pname; + rev = "refs/tags/${version}"; + hash = "sha256-gGlbzTDvZNo4MhcYzLvWuB2ec7q+Qt5/LtTbJ0Rc+Kk="; + }; - preBuild = '' - make cuda11x CUDA_VERSION=${cudaVersion} GPP=${gcc}/bin/g++ -j3 - ## this python doesn't know where to get libcuda, so explicitly tell it - ## this is probably really bad practice, fix this - substituteInPlace bitsandbytes/cuda_setup/main.py \ - --replace "libcuda.so" "${nvidia_x11}/lib/libcuda.so" + postPatch = '' + substituteInPlace Makefile --replace "/usr/bin/g++" "g++" --replace "lib64" "lib" + substituteInPlace bitsandbytes/cuda_setup/main.py \ + --replace "binary_path = package_dir / binary_name" \ + "binary_path = Path('$out/${python.sitePackages}/${pname}')/binary_name" + '' + lib.optionalString torch.cudaSupport '' + substituteInPlace bitsandbytes/cuda_setup/main.py \ + --replace "/usr/local/cuda/lib64" "${cuda-native-redist}/lib" ''; - propagatedBuildInputs = [ - (pytorch.override({ inherit cudaSupport;})) - setuptools - ] ++ lib.optionals cudaSupport [ - typer - cudatoolkit - cudatoolkit.lib - nvidia_x11 - ]; + CUDA_HOME = "${cuda-native-redist}"; - nativeBuildInputs = lib.optionals cudaSupport [ - gcc - addOpenGLRunpath - ]; + 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''; - preFixup = lib.optionalString cudaSupport '' - find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib - do - addOpenGLRunpath "$lib" - patchelf \ - --set-rpath "${libraryPath}" \ - "$lib" - done - ''; + nativeBuildInputs = [ setuptools ] ++ lib.optionals torch.cudaSupport [ cuda-native-redist ]; + buildInputs = lib.optionals torch.cudaSupport [ cuda-redist ]; - checkInputs = [ - pytest + propagatedBuildInputs = [ + torch ]; - # disabled because the test suite cannot find any GPUs in the nix sandbox - doCheck = false; + doCheck = false; # tests require CUDA and also GPU access + nativeCheckInputs = [ pytestCheckHook einops lion-pytorch scipy ]; pythonImportsCheck = [ - "torch" - # this tries to load and verify the cuda device on import, since this runs - # in the nix sandbox it will fail with a bunch of errors, but curiously the - # build still succeeds... "bitsandbytes" ]; -} + meta = with lib; { + homepage = "https://github.com/TimDettmers/bitsandbytes"; + description = "8-bit CUDA functions for PyTorch"; + license = licenses.mit; + maintainers = with maintainers; [ bcdarwin ]; + }; +} |