1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 setuptools,
8
9 # dependencies
10 dm-tree,
11 etils,
12 numpy,
13 tabulate,
14 wrapt,
15
16 # tests
17 click,
18 docutils,
19 keras,
20 pytestCheckHook,
21 tensorflow,
22 tensorflow-datasets,
23 tf-keras,
24}:
25
26buildPythonPackage rec {
27 pname = "dm-sonnet";
28 version = "2.0.2";
29 pyproject = true;
30
31 src = fetchFromGitHub {
32 owner = "deepmind";
33 repo = "sonnet";
34 tag = "v${version}";
35 hash = "sha256-WkloUbqSyPG3cbLG8ktsjdluACkCbUZ7t6rYWst8rs8=";
36 };
37
38 build-system = [
39 setuptools
40 ];
41
42 dependencies = [
43 dm-tree
44 etils
45 numpy
46 tabulate
47 wrapt
48 ]
49 ++ etils.optional-dependencies.epath;
50
51 optional-dependencies = {
52 tensorflow = [ tensorflow ];
53 };
54
55 nativeCheckInputs = [
56 click
57 docutils
58 keras
59 pytestCheckHook
60 tensorflow
61 tensorflow-datasets
62 tf-keras
63 ];
64
65 # ImportError: `keras.optimizers.legacy` is not supported in Keras 3
66 preCheck = ''
67 export TF_USE_LEGACY_KERAS=True
68 '';
69
70 disabledTests = [
71 # AssertionError: 2 != 0 : 2 doctests failed
72 "test_doctest_sonnet.functional"
73
74 # AssertionError: Not equal to tolerance
75 "testComputationAgainstNumPy1"
76
77 # tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute MatMul as input #1(zero-based) was expected to be a float tensor but is a half tensor [Op:MatMul]
78 "testComputationAgainstNumPy0"
79 "testComputationAgainstNumPy1"
80 ];
81
82 pythonImportsCheck = [ "sonnet" ];
83
84 meta = {
85 description = "Library for building neural networks in TensorFlow";
86 homepage = "https://github.com/deepmind/sonnet";
87 changelog = "https://github.com/google-deepmind/sonnet/releases/tag/v${version}";
88 license = lib.licenses.asl20;
89 maintainers = with lib.maintainers; [ onny ];
90 };
91}