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