2021-12-30 13:39:12 +00:00
|
|
|
# For the moment we only support the CPU and GPU backends of jaxlib. The TPU
|
|
|
|
# backend will require some additional work. Those wheels are located here:
|
|
|
|
# https://storage.googleapis.com/jax-releases/libtpu_releases.html.
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# See `python3Packages.jax.passthru` for CUDA tests.
|
2021-12-30 13:39:12 +00:00
|
|
|
|
2022-02-20 05:27:41 +00:00
|
|
|
{ absl-py
|
|
|
|
, autoPatchelfHook
|
|
|
|
, buildPythonPackage
|
|
|
|
, config
|
2023-08-10 07:59:29 +00:00
|
|
|
, fetchPypi
|
2022-02-20 05:27:41 +00:00
|
|
|
, fetchurl
|
|
|
|
, flatbuffers
|
2023-08-10 07:59:29 +00:00
|
|
|
, jaxlib-build
|
2022-02-20 05:27:41 +00:00
|
|
|
, lib
|
2023-08-10 07:59:29 +00:00
|
|
|
, ml-dtypes
|
2022-03-10 19:12:11 +00:00
|
|
|
, python
|
2022-02-20 05:27:41 +00:00
|
|
|
, scipy
|
|
|
|
, stdenv
|
|
|
|
# Options:
|
2023-08-04 22:07:22 +00:00
|
|
|
, cudaSupport ? config.cudaSupport
|
2024-01-02 11:29:13 +00:00
|
|
|
, cudaPackagesGoogle
|
2021-12-30 13:39:12 +00:00
|
|
|
}:
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
let
|
2024-02-29 20:09:43 +00:00
|
|
|
inherit (cudaPackagesGoogle) autoAddOpenGLRunpathHook cudaVersion;
|
2021-12-30 13:39:12 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
version = "0.4.24";
|
2023-08-10 07:59:29 +00:00
|
|
|
|
|
|
|
inherit (python) pythonVersion;
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
cudaLibPath = lib.makeLibraryPath (with cudaPackagesGoogle; [
|
|
|
|
cuda_cudart.lib # libcudart.so
|
|
|
|
cuda_cupti.lib # libcupti.so
|
|
|
|
cudnn.lib # libcudnn.so
|
|
|
|
libcufft.lib # libcufft.so
|
|
|
|
libcusolver.lib # libcusolver.so
|
|
|
|
libcusparse.lib # libcusparse.so
|
|
|
|
]);
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
# As of 2023-06-06, google/jax upstream is no longer publishing CPU-only wheels to their GCS bucket. Instead the
|
|
|
|
# official instructions recommend installing CPU-only versions via PyPI.
|
|
|
|
cpuSrcs =
|
|
|
|
let
|
2023-11-16 04:20:00 +00:00
|
|
|
getSrcFromPypi = { platform, dist, hash }: fetchPypi {
|
|
|
|
inherit version platform dist hash;
|
2023-08-10 07:59:29 +00:00
|
|
|
pname = "jaxlib";
|
|
|
|
format = "wheel";
|
|
|
|
# See the `disabled` attr comment below.
|
2023-11-16 04:20:00 +00:00
|
|
|
python = dist;
|
|
|
|
abi = dist;
|
2023-08-10 07:59:29 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2023-11-16 04:20:00 +00:00
|
|
|
"3.9-x86_64-linux" = getSrcFromPypi {
|
2023-08-10 07:59:29 +00:00
|
|
|
platform = "manylinux2014_x86_64";
|
2023-11-16 04:20:00 +00:00
|
|
|
dist = "cp39";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-6P5ArMoLZiUkHUoQ/mJccbNj5/7el/op+Qo6cGQ33xE=";
|
2023-08-10 07:59:29 +00:00
|
|
|
};
|
2023-11-16 04:20:00 +00:00
|
|
|
"3.9-aarch64-darwin" = getSrcFromPypi {
|
2023-08-10 07:59:29 +00:00
|
|
|
platform = "macosx_11_0_arm64";
|
2023-11-16 04:20:00 +00:00
|
|
|
dist = "cp39";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-23JQZRwMLtt7sK/JlCBqqRyfTVIAVJFN2sL+nAkQgvU=";
|
2023-08-10 07:59:29 +00:00
|
|
|
};
|
2023-11-16 04:20:00 +00:00
|
|
|
"3.9-x86_64-darwin" = getSrcFromPypi {
|
2023-08-10 07:59:29 +00:00
|
|
|
platform = "macosx_10_14_x86_64";
|
2023-11-16 04:20:00 +00:00
|
|
|
dist = "cp39";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-OgMedn9GHGs5THZf3pkP3Aw/jJ0vL5qK1b+Lzf634Ik=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
"3.10-x86_64-linux" = getSrcFromPypi {
|
|
|
|
platform = "manylinux2014_x86_64";
|
|
|
|
dist = "cp310";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-/VwUIIa7mTs/wLz0ArsEfNrz2pGriVVT5GX9XRFRxfY=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.10-aarch64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_11_0_arm64";
|
|
|
|
dist = "cp310";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-LgICOyDGts840SQQJh+yOMobMASb62llvJjpGvhzrSw=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.10-x86_64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_10_14_x86_64";
|
|
|
|
dist = "cp310";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-vhyULw+zBpz1UEi2tqgBMQEzY9a6YBgEIg6A4PPh3bQ=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
"3.11-x86_64-linux" = getSrcFromPypi {
|
|
|
|
platform = "manylinux2014_x86_64";
|
|
|
|
dist = "cp311";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-VJO/VVwBFkOEtq4y/sLVgAV8Cung01JULiuT6W96E/8=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.11-aarch64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_11_0_arm64";
|
|
|
|
dist = "cp311";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-VtuwXxurpSp1KI8ty1bizs5cdy8GEBN2MgS227sOCmE=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.11-x86_64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_10_14_x86_64";
|
|
|
|
dist = "cp311";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-4Dj5dEGKb9hpg3HlVogNO1Gc9UibJhy1eym2mjivxAQ=";
|
2023-08-10 07:59:29 +00:00
|
|
|
};
|
2021-12-30 13:39:12 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
"3.12-x86_64-linux" = getSrcFromPypi {
|
|
|
|
platform = "manylinux2014_x86_64";
|
|
|
|
dist = "cp312";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-TlrGVtb3NTLmhnILWPLJR+jISCZ5SUV4wxNFpSfkCBo=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.12-aarch64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_11_0_arm64";
|
|
|
|
dist = "cp312";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-FIwK5CGykQjteuWzLZnbtAggIxLQeGV96bXlZGEytN0=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
"3.12-x86_64-darwin" = getSrcFromPypi {
|
|
|
|
platform = "macosx_10_14_x86_64";
|
|
|
|
dist = "cp312";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-9/jw/wr6oUD9pOadVAaMRL086iVMUXwVgnUMcG1UNvE=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
};
|
2021-12-30 13:39:12 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# Note that the prebuilt jaxlib binary requires specific version of CUDA to
|
|
|
|
# work. The cuda12 jaxlib binaries only works with CUDA 12.2, and cuda11
|
|
|
|
# jaxlib binaries only works with CUDA 11.8. This is why we need to find a
|
|
|
|
# binary that matches the provided cudaVersion.
|
|
|
|
gpuSrcVersionString = "cuda${cudaVersion}-${pythonVersion}";
|
|
|
|
|
|
|
|
# Find new releases at https://storage.googleapis.com/jax-releases
|
2022-10-30 15:09:59 +00:00
|
|
|
# When upgrading, you can get these hashes from prefetch.sh. See
|
2023-08-10 07:59:29 +00:00
|
|
|
# https://github.com/google/jax/issues/12879 as to why this specific URL is the correct index.
|
2023-11-16 04:20:00 +00:00
|
|
|
gpuSrcs = {
|
2024-02-29 20:09:43 +00:00
|
|
|
"cuda12.2-3.9" = fetchurl {
|
2023-11-16 04:20:00 +00:00
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda12/jaxlib-${version}+cuda12.cudnn89-cp39-cp39-manylinux2014_x86_64.whl";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-xdJKLPtx+CIza2CrWKM3M0cZJzyNFVTTTsvlgh38bfM=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
"cuda12.2-3.10" = fetchurl {
|
2023-11-16 04:20:00 +00:00
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda12/jaxlib-${version}+cuda12.cudnn89-cp310-cp310-manylinux2014_x86_64.whl";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-QCjrOczD2mp+CDwVXBc0/4rJnAizeV62AK0Dpx9X6TE=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
"cuda12.2-3.11" = fetchurl {
|
2023-11-16 04:20:00 +00:00
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda12/jaxlib-${version}+cuda12.cudnn89-cp311-cp311-manylinux2014_x86_64.whl";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-Ipy3vk1yUplpNzECAFt63aOIhgEWgXG7hkoeTIk9bQQ=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
"cuda12.2-3.12" = fetchurl {
|
2023-11-16 04:20:00 +00:00
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda12/jaxlib-${version}+cuda12.cudnn89-cp312-cp312-manylinux2014_x86_64.whl";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-LSnZHaUga/8Z65iKXWBnZDk4yUpNykFTu3vukCchO6Q=";
|
|
|
|
};
|
|
|
|
"cuda11.8-3.9" = fetchurl {
|
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda11/jaxlib-${version}+cuda11.cudnn86-cp39-cp39-manylinux2014_x86_64.whl";
|
|
|
|
hash = "sha256-UmyugL0VjlXkiD7fuDPWgW8XUpr/QaP5ggp6swoZTzU=";
|
|
|
|
};
|
|
|
|
"cuda11.8-3.10" = fetchurl {
|
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda11/jaxlib-${version}+cuda11.cudnn86-cp310-cp310-manylinux2014_x86_64.whl";
|
|
|
|
hash = "sha256-luKULEiV1t/sO6eckDxddJTiOFa0dtJeDlrvp+WYmHk=";
|
|
|
|
};
|
|
|
|
"cuda11.8-3.11" = fetchurl {
|
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda11/jaxlib-${version}+cuda11.cudnn86-cp311-cp311-manylinux2014_x86_64.whl";
|
|
|
|
hash = "sha256-4+uJ8Ij6mFGEmjFEgi3fLnSLZs+v18BRoOt7mZuqydw=";
|
|
|
|
};
|
|
|
|
"cuda11.8-3.12" = fetchurl {
|
|
|
|
url = "https://storage.googleapis.com/jax-releases/cuda11/jaxlib-${version}+cuda11.cudnn86-cp312-cp312-manylinux2014_x86_64.whl";
|
|
|
|
hash = "sha256-bUDFb94Ar/65SzzR9RLIs/SL/HdjaPT1Su5whmjkS00=";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
2022-03-10 19:12:11 +00:00
|
|
|
};
|
2023-08-10 07:59:29 +00:00
|
|
|
|
2022-03-10 19:12:11 +00:00
|
|
|
in
|
2023-08-10 07:59:29 +00:00
|
|
|
buildPythonPackage {
|
2022-03-10 19:12:11 +00:00
|
|
|
pname = "jaxlib";
|
|
|
|
inherit version;
|
|
|
|
format = "wheel";
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
disabled = !(pythonVersion == "3.9" || pythonVersion == "3.10" || pythonVersion == "3.11" || pythonVersion == "3.12");
|
2022-03-10 19:12:11 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
# See https://discourse.nixos.org/t/ofborg-does-not-respect-meta-platforms/27019/6.
|
|
|
|
src =
|
|
|
|
if !cudaSupport then
|
|
|
|
(
|
2023-11-16 04:20:00 +00:00
|
|
|
cpuSrcs."${pythonVersion}-${stdenv.hostPlatform.system}"
|
2023-04-29 16:46:19 +00:00
|
|
|
or (throw "jaxlib-bin is not supported on ${stdenv.hostPlatform.system}")
|
2024-02-29 20:09:43 +00:00
|
|
|
) else gpuSrcs."${gpuSrcVersionString}";
|
2021-12-30 13:39:12 +00:00
|
|
|
|
|
|
|
# Prebuilt wheels are dynamically linked against things that nix can't find.
|
|
|
|
# Run `autoPatchelfHook` to automagically fix them.
|
2023-08-10 07:59:29 +00:00
|
|
|
nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ]
|
2024-02-29 20:09:43 +00:00
|
|
|
++ lib.optionals cudaSupport [ autoAddOpenGLRunpathHook ];
|
2021-12-30 13:39:12 +00:00
|
|
|
# Dynamic link dependencies
|
2023-08-10 07:59:29 +00:00
|
|
|
buildInputs = [ stdenv.cc.cc.lib ];
|
2021-12-30 13:39:12 +00:00
|
|
|
|
|
|
|
# jaxlib contains shared libraries that open other shared libraries via dlopen
|
|
|
|
# and these implicit dependencies are not recognized by ldd or
|
|
|
|
# autoPatchelfHook. That means we need to sneak them into rpath. This step
|
|
|
|
# must be done after autoPatchelfHook and the automatic stripping of
|
|
|
|
# artifacts. autoPatchelfHook runs in postFixup and auto-stripping runs in the
|
2024-02-29 20:09:43 +00:00
|
|
|
# patchPhase.
|
2021-12-30 13:39:12 +00:00
|
|
|
preInstallCheck = lib.optional cudaSupport ''
|
|
|
|
shopt -s globstar
|
|
|
|
|
|
|
|
for file in $out/**/*.so; do
|
2024-02-29 20:09:43 +00:00
|
|
|
patchelf --add-rpath "${cudaLibPath}" "$file"
|
2021-12-30 13:39:12 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
absl-py
|
|
|
|
flatbuffers
|
|
|
|
ml-dtypes
|
|
|
|
scipy
|
|
|
|
];
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# jaxlib looks for ptxas at runtime, eg when running `jax.random.PRNGKey(0)`.
|
|
|
|
# Linking into $out is the least bad solution. See
|
|
|
|
# * https://github.com/NixOS/nixpkgs/pull/164176#discussion_r828801621
|
|
|
|
# * https://github.com/NixOS/nixpkgs/pull/288829#discussion_r1493852211
|
|
|
|
# for more info.
|
2022-03-30 09:31:56 +00:00
|
|
|
postInstall = lib.optional cudaSupport ''
|
2024-02-29 20:09:43 +00:00
|
|
|
mkdir -p $out/${python.sitePackages}/jaxlib/cuda/bin
|
|
|
|
ln -s ${lib.getExe' cudaPackagesGoogle.cuda_nvcc "ptxas"} $out/${python.sitePackages}/jaxlib/cuda/bin/ptxas
|
2022-03-30 09:31:56 +00:00
|
|
|
'';
|
2021-12-30 13:39:12 +00:00
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
inherit (jaxlib-build) pythonImportsCheck;
|
2021-12-30 13:39:12 +00:00
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "XLA library for JAX";
|
2022-02-20 05:27:41 +00:00
|
|
|
homepage = "https://github.com/google/jax";
|
2022-06-26 10:26:21 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2022-02-20 05:27:41 +00:00
|
|
|
license = licenses.asl20;
|
2021-12-30 13:39:12 +00:00
|
|
|
maintainers = with maintainers; [ samuela ];
|
2022-11-27 09:42:12 +00:00
|
|
|
platforms = [ "aarch64-darwin" "x86_64-linux" "x86_64-darwin" ];
|
2024-01-02 11:29:13 +00:00
|
|
|
broken =
|
2024-02-29 20:09:43 +00:00
|
|
|
!(cudaSupport -> lib.versionAtLeast cudaVersion "11.1")
|
|
|
|
|| !(cudaSupport -> lib.versionAtLeast cudaPackagesGoogle.cudnn.version "8.2")
|
|
|
|
|| !(cudaSupport -> stdenv.isLinux)
|
|
|
|
|| !(cudaSupport -> (gpuSrcs ? "cuda${cudaVersion}-${pythonVersion}"));
|
2021-12-30 13:39:12 +00:00
|
|
|
};
|
|
|
|
}
|