1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 absl-py,
12 distutils,
13 h5py,
14 ml-dtypes,
15 namex,
16 numpy,
17 tf2onnx,
18 onnxruntime,
19 optree,
20 packaging,
21 pythonAtLeast,
22 rich,
23 scikit-learn,
24 tensorflow,
25
26 # tests
27 dm-tree,
28 jax,
29 pandas,
30 pydot,
31 pytestCheckHook,
32 tf-keras,
33 torch,
34 writableTmpDirAsHomeHook,
35}:
36
37buildPythonPackage rec {
38 pname = "keras";
39 version = "3.10.0";
40 pyproject = true;
41
42 src = fetchFromGitHub {
43 owner = "keras-team";
44 repo = "keras";
45 tag = "v${version}";
46 hash = "sha256-N0RlXnmSYJvD4/a47U4EjMczw1VIyereZoPicjgEkAI=";
47 };
48
49 build-system = [
50 setuptools
51 ];
52
53 dependencies = [
54 absl-py
55 h5py
56 ml-dtypes
57 namex
58 numpy
59 tf2onnx
60 onnxruntime
61 optree
62 packaging
63 rich
64 scikit-learn
65 tensorflow
66 ]
67 ++ lib.optionals (pythonAtLeast "3.12") [ distutils ];
68
69 pythonImportsCheck = [
70 "keras"
71 "keras._tf_keras"
72 ];
73
74 nativeCheckInputs = [
75 dm-tree
76 jax
77 pandas
78 pydot
79 pytestCheckHook
80 tf-keras
81 torch
82 writableTmpDirAsHomeHook
83 ];
84
85 disabledTests = [
86 # NameError: name 'MockRemat' is not defined
87 # https://github.com/keras-team/keras/issues/21126
88 "test_functional_model_with_remat"
89
90 # Tries to install the package in the sandbox
91 "test_keras_imports"
92
93 # TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
94 "test_reloading_default_saved_model"
95 ]
96 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
97 # Hangs forever
98 "test_fit_with_data_adapter"
99 ];
100
101 disabledTestPaths = [
102 # These tests succeed when run individually, but crash within the full test suite:
103 # ImportError: /nix/store/4bw0x7j3wfbh6i8x3plmzknrdwdzwfla-abseil-cpp-20240722.1/lib/libabsl_cord_internal.so.2407.0.0:
104 # undefined symbol: _ZN4absl12lts_2024072216strings_internal13StringifySink6AppendESt17basic_string_viewIcSt11char_traitsIcEE
105 "keras/src/export/onnx_test.py"
106
107 # Require internet access
108 "integration_tests/dataset_tests"
109 "keras/src/applications/applications_test.py"
110
111 # TypeError: test_custom_fit.<locals>.CustomModel.train_step() missing 1 required positional argument: 'data'
112 "integration_tests/jax_custom_fit_test.py"
113
114 # RuntimeError: Virtual devices cannot be modified after being initialized
115 "integration_tests/tf_distribute_training_test.py"
116
117 # AttributeError: 'CustomModel' object has no attribute 'zero_grad'
118 "integration_tests/torch_custom_fit_test.py"
119
120 # Fails for an unclear reason:
121 # self.assertLen(list(net.parameters()), 2
122 # AssertionError: 0 != 2
123 "integration_tests/torch_workflow_test.py"
124
125 # TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
126 "keras/src/backend/tensorflow/saved_model_test.py"
127 ];
128
129 meta = {
130 description = "Multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch";
131 homepage = "https://keras.io";
132 changelog = "https://github.com/keras-team/keras/releases/tag/v${version}";
133 license = lib.licenses.mit;
134 maintainers = with lib.maintainers; [ GaetanLepage ];
135 };
136}