summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/keras/default.nix
blob: ccf56f460f61a91a1cc8ee11486df2970cfd9614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  setuptools,

  # dependencies
  absl-py,
  distutils,
  h5py,
  ml-dtypes,
  namex,
  numpy,
  onnxruntime,
  optree,
  orbax-checkpoint,
  packaging,
  pythonAtLeast,
  rich,
  scikit-learn,
  tensorflow,
  tf2onnx,

  # tests
  dm-tree,
  jax,
  pandas,
  pydot,
  pytestCheckHook,
  tf-keras,
  torch,
  writableTmpDirAsHomeHook,
}:

buildPythonPackage (finalAttrs: {
  pname = "keras";
  version = "3.13.1";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "keras-team";
    repo = "keras";
    tag = "v${finalAttrs.version}";
    hash = "sha256-oFlEgic6M6ZRqDl6RvAbQccW8RIHC4fEGWJyNPidDHM=";
  };

  build-system = [
    setuptools
  ];

  dependencies = [
    absl-py
    h5py
    ml-dtypes
    namex
    numpy
    onnxruntime
    optree
    orbax-checkpoint
    packaging
    rich
    scikit-learn
    tensorflow
    tf2onnx
  ]
  ++ lib.optionals (pythonAtLeast "3.12") [ distutils ];

  pythonImportsCheck = [
    "keras"
    "keras._tf_keras"
  ];

  nativeCheckInputs = [
    dm-tree
    jax
    pandas
    pydot
    pytestCheckHook
    tf-keras
    torch
    writableTmpDirAsHomeHook
  ];

  disabledTests = [
    # Require unpackaged `grain`
    "test_fit_with_data_adapter_grain_dataloader"
    "test_fit_with_data_adapter_grain_datast"
    "test_fit_with_data_adapter_grain_datast_with_len"
    "test_image_dataset_from_directory_binary_grain"
    "test_image_dataset_from_directory_color_modes_grain"
    "test_image_dataset_from_directory_crop_to_aspect_ratio_grain"
    "test_image_dataset_from_directory_follow_links_grain"
    "test_image_dataset_from_directory_manual_labels_grain"
    "test_image_dataset_from_directory_multiclass_grain"
    "test_image_dataset_from_directory_no_labels_grain"
    "test_image_dataset_from_directory_not_batched_grain"
    "test_image_dataset_from_directory_pad_to_aspect_ratio_grain"
    "test_image_dataset_from_directory_shuffle_grain"
    "test_image_dataset_from_directory_validation_split_grain"
    "test_sample_count_grain"
    "test_text_dataset_from_directory_binary_grain"
    "test_text_dataset_from_directory_follow_links_grain"
    "test_text_dataset_from_directory_manual_labels_grain"
    "test_text_dataset_from_directory_multiclass_grain"
    "test_text_dataset_from_directory_not_batched_grain"
    "test_text_dataset_from_directory_standalone_grain"
    "test_text_dataset_from_directory_validation_split_grain"

    # Tries to install the package in the sandbox
    "test_keras_imports"

    # TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
    "test_reloading_default_saved_model"
  ]
  ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
    # Hangs forever
    "test_fit_with_data_adapter"
  ];

  disabledTestPaths = [
    # Require unpackaged `grain`
    "keras/src/layers/preprocessing/data_layer_test.py"
    "keras/src/layers/preprocessing/image_preprocessing/resizing_test.py"
    "keras/src/layers/preprocessing/rescaling_test.py"
    "keras/src/trainers/data_adapters/grain_dataset_adapter_test.py"

    # These tests succeed when run individually, but crash within the full test suite:
    # ImportError: /nix/store/4bw0x7j3wfbh6i8x3plmzknrdwdzwfla-abseil-cpp-20240722.1/lib/libabsl_cord_internal.so.2407.0.0:
    # undefined symbol: _ZN4absl12lts_2024072216strings_internal13StringifySink6AppendESt17basic_string_viewIcSt11char_traitsIcEE
    "keras/src/export/onnx_test.py"

    # Require internet access
    "integration_tests/dataset_tests"
    "keras/src/applications/applications_test.py"

    # TypeError: test_custom_fit.<locals>.CustomModel.train_step() missing 1 required positional argument: 'data'
    "integration_tests/jax_custom_fit_test.py"

    # RuntimeError: Virtual devices cannot be modified after being initialized
    "integration_tests/tf_distribute_training_test.py"

    # AttributeError: 'CustomModel' object has no attribute 'zero_grad'
    "integration_tests/torch_custom_fit_test.py"

    # Fails for an unclear reason:
    # self.assertLen(list(net.parameters()), 2
    # AssertionError: 0 != 2
    "integration_tests/torch_workflow_test.py"

    # TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
    "keras/src/backend/tensorflow/saved_model_test.py"
  ];

  meta = {
    description = "Multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch";
    homepage = "https://keras.io";
    changelog = "https://github.com/keras-team/keras/releases/tag/${finalAttrs.src.tag}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ GaetanLepage ];
  };
})