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 ] ++ etils.optional-dependencies.epath;
49
50 optional-dependencies = {
51 tensorflow = [ tensorflow ];
52 };
53
54 nativeCheckInputs = [
55 click
56 docutils
57 keras
58 pytestCheckHook
59 tensorflow
60 tensorflow-datasets
61 tf-keras
62 ];
63
64 # ImportError: `keras.optimizers.legacy` is not supported in Keras 3
65 preCheck = ''
66 export TF_USE_LEGACY_KERAS=True
67 '';
68
69 disabledTests = [
70 # AssertionError: 2 != 0 : 2 doctests failed
71 "test_doctest_sonnet.functional"
72
73 # AssertionError: Not equal to tolerance
74 "testComputationAgainstNumPy1"
75
76 # 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]
77 "testComputationAgainstNumPy0"
78 "testComputationAgainstNumPy1"
79 ];
80
81 pythonImportsCheck = [ "sonnet" ];
82
83 meta = {
84 description = "Library for building neural networks in TensorFlow";
85 homepage = "https://github.com/deepmind/sonnet";
86 changelog = "https://github.com/google-deepmind/sonnet/releases/tag/v${version}";
87 license = lib.licenses.asl20;
88 maintainers = with lib.maintainers; [ onny ];
89 };
90}