2021-12-06 16:07:01 +00:00
|
|
|
{ lib
|
2022-03-05 16:20:37 +00:00
|
|
|
, blas
|
2021-12-06 16:07:01 +00:00
|
|
|
, buildPythonPackage
|
2023-08-10 07:59:29 +00:00
|
|
|
, setuptools
|
|
|
|
, importlib-metadata
|
2021-12-06 16:07:01 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, jaxlib
|
2023-04-29 16:46:19 +00:00
|
|
|
, jaxlib-bin
|
2024-01-02 11:29:13 +00:00
|
|
|
, hypothesis
|
2022-03-05 16:20:37 +00:00
|
|
|
, lapack
|
2022-09-09 14:08:57 +00:00
|
|
|
, matplotlib
|
2023-08-10 07:59:29 +00:00
|
|
|
, ml-dtypes
|
2021-12-06 16:07:01 +00:00
|
|
|
, numpy
|
|
|
|
, opt-einsum
|
|
|
|
, pytestCheckHook
|
2022-02-20 05:27:41 +00:00
|
|
|
, pytest-xdist
|
2021-12-06 16:07:01 +00:00
|
|
|
, pythonOlder
|
|
|
|
, scipy
|
2023-04-29 16:46:19 +00:00
|
|
|
, stdenv
|
2021-09-18 10:52:07 +00:00
|
|
|
}:
|
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
let
|
|
|
|
usingMKL = blas.implementation == "mkl" || lapack.implementation == "mkl";
|
2023-04-29 16:46:19 +00:00
|
|
|
# jaxlib is broken on aarch64-* as of 2023-03-05, but the binary wheels work
|
|
|
|
# fine. jaxlib is only used in the checkPhase, so switching backends does not
|
|
|
|
# impact package behavior. Get rid of this once jaxlib is fixed on aarch64-*.
|
|
|
|
jaxlib' = if jaxlib.meta.broken then jaxlib-bin else jaxlib;
|
2022-03-05 16:20:37 +00:00
|
|
|
in
|
2021-09-18 10:52:07 +00:00
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "jax";
|
2024-01-02 11:29:13 +00:00
|
|
|
version = "0.4.23";
|
2023-10-09 19:29:22 +00:00
|
|
|
pyproject = true;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
disabled = pythonOlder "3.9";
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "google";
|
2023-11-16 04:20:00 +00:00
|
|
|
repo = "jax";
|
2023-04-29 16:46:19 +00:00
|
|
|
# google/jax contains tags for jax and jaxlib. Only use jax tags!
|
|
|
|
rev = "refs/tags/${pname}-v${version}";
|
2024-01-02 11:29:13 +00:00
|
|
|
hash = "sha256-PDa3yVH/sszGbWkVkJ+19FdOr3oqdYk+OdbeUTMTDuU=";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
# The version is automatically set to ".dev" if this variable is not set.
|
|
|
|
# https://github.com/google/jax/commit/e01f2617b85c5bdffc5ffb60b3d8d8ca9519a1f3
|
|
|
|
JAX_RELEASE = "1";
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
# jaxlib is _not_ included in propagatedBuildInputs because there are
|
|
|
|
# different versions of jaxlib depending on the desired target hardware. The
|
2023-04-29 16:46:19 +00:00
|
|
|
# JAX project ships separate wheels for CPU, GPU, and TPU.
|
2021-12-06 16:07:01 +00:00
|
|
|
propagatedBuildInputs = [
|
2023-08-10 07:59:29 +00:00
|
|
|
ml-dtypes
|
2021-12-06 16:07:01 +00:00
|
|
|
numpy
|
|
|
|
opt-einsum
|
|
|
|
scipy
|
2023-08-10 07:59:29 +00:00
|
|
|
] ++ lib.optional (pythonOlder "3.10") importlib-metadata;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2024-01-02 11:29:13 +00:00
|
|
|
hypothesis
|
2023-04-29 16:46:19 +00:00
|
|
|
jaxlib'
|
2022-09-09 14:08:57 +00:00
|
|
|
matplotlib
|
2021-12-06 16:07:01 +00:00
|
|
|
pytestCheckHook
|
2022-02-20 05:27:41 +00:00
|
|
|
pytest-xdist
|
2021-12-06 16:07:01 +00:00
|
|
|
];
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
# high parallelism will result in the tests getting stuck
|
|
|
|
dontUsePytestXdist = true;
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
# NOTE: Don't run the tests in the expiremental directory as they require flax
|
|
|
|
# which creates a circular dependency. See https://discourse.nixos.org/t/how-to-nix-ify-python-packages-with-circular-dependencies/14648/2.
|
|
|
|
# Not a big deal, this is how the JAX docs suggest running the test suite
|
|
|
|
# anyhow.
|
2021-12-06 16:07:01 +00:00
|
|
|
pytestFlagsArray = [
|
2022-04-27 09:35:20 +00:00
|
|
|
"--numprocesses=4"
|
2021-12-06 16:07:01 +00:00
|
|
|
"-W ignore::DeprecationWarning"
|
|
|
|
"tests/"
|
|
|
|
];
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
disabledTests = [
|
|
|
|
# Exceeds tolerance when the machine is busy
|
|
|
|
"test_custom_linear_solve_aux"
|
2023-03-15 16:39:30 +00:00
|
|
|
# UserWarning: Explicitly requested dtype <class 'numpy.float64'>
|
|
|
|
# requested in astype is not available, and will be truncated to
|
|
|
|
# dtype float32. (With numpy 1.24)
|
|
|
|
"testKde3"
|
|
|
|
"testKde5"
|
|
|
|
"testKde6"
|
2022-04-27 09:35:20 +00:00
|
|
|
] ++ lib.optionals usingMKL [
|
|
|
|
# See
|
|
|
|
# * https://github.com/google/jax/issues/9705
|
|
|
|
# * https://discourse.nixos.org/t/getting-different-results-for-the-same-build-on-two-equally-configured-machines/17921
|
|
|
|
# * https://github.com/NixOS/nixpkgs/issues/161960
|
2022-03-05 16:20:37 +00:00
|
|
|
"test_custom_linear_solve_cholesky"
|
|
|
|
"test_custom_root_with_aux"
|
|
|
|
"testEigvalsGrad_shape"
|
2023-05-24 13:37:59 +00:00
|
|
|
] ++ lib.optionals stdenv.isAarch64 [
|
2023-04-29 16:46:19 +00:00
|
|
|
# See https://github.com/google/jax/issues/14793.
|
|
|
|
"test_for_loop_fixpoint_correctly_identifies_loop_varying_residuals_unrolled_for_loop"
|
|
|
|
"testQdwhWithRandomMatrix3"
|
|
|
|
"testScanGrad_jit_scan"
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
# See https://github.com/google/jax/issues/17867.
|
|
|
|
"test_array"
|
|
|
|
"test_async"
|
|
|
|
"test_copy0"
|
|
|
|
"test_device_put"
|
|
|
|
"test_make_array_from_callback"
|
|
|
|
"test_make_array_from_single_device_arrays"
|
2023-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
# Fails on some hardware due to some numerical error
|
|
|
|
# See https://github.com/google/jax/issues/18535
|
|
|
|
"testQdwhWithOnRankDeficientInput5"
|
2022-03-05 16:20:37 +00:00
|
|
|
];
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
disabledTestPaths = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
|
2023-05-24 13:37:59 +00:00
|
|
|
# RuntimeWarning: invalid value encountered in cast
|
|
|
|
"tests/lax_test.py"
|
2022-08-12 12:06:08 +00:00
|
|
|
];
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
pythonImportsCheck = [ "jax" ];
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Differentiate, compile, and transform Numpy code";
|
2021-12-06 16:07:01 +00:00
|
|
|
homepage = "https://github.com/google/jax";
|
|
|
|
license = licenses.asl20;
|
2021-09-18 10:52:07 +00:00
|
|
|
maintainers = with maintainers; [ samuela ];
|
|
|
|
};
|
|
|
|
}
|