1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # dependencies
7 numpy,
8 lightning-utilities,
9 packaging,
10
11 # buildInputs
12 torch,
13
14 # tests
15 pytestCheckHook,
16 pytest-doctestplus,
17 pytest-xdist,
18 pytorch-lightning,
19 scikit-image,
20
21 # passthru
22 torchmetrics,
23}:
24
25buildPythonPackage rec {
26 pname = "torchmetrics";
27 version = "1.8.2";
28 pyproject = true;
29
30 src = fetchFromGitHub {
31 owner = "Lightning-AI";
32 repo = "torchmetrics";
33 tag = "v${version}";
34 hash = "sha256-OsU2JpKcbe1AuSIAyZLjDpFdsSk2q3kMGBcNXtIJm3Q=";
35 };
36
37 dependencies = [
38 numpy
39 lightning-utilities
40 packaging
41 ];
42
43 # Let the user bring their own instance
44 buildInputs = [ torch ];
45
46 nativeCheckInputs = [
47 pytestCheckHook
48 pytest-doctestplus
49 pytest-xdist
50 pytorch-lightning
51 scikit-image
52 ];
53
54 # A cyclic dependency in: integrations/test_lightning.py
55 doCheck = false;
56 passthru.tests.check = torchmetrics.overridePythonAttrs (_: {
57 pname = "${pname}-check";
58 doCheck = true;
59 # We don't have to install because the only purpose
60 # of this passthru test is to, well, test.
61 # This fixes having to set `catchConflicts` to false.
62 dontInstall = true;
63 });
64
65 disabledTestPaths = [
66 # These require too many "leftpad-level" dependencies
67 # Also too cross-dependent
68 "tests/unittests"
69
70 # AttributeError: partially initialized module 'pesq' has no attribute 'pesq' (most likely due to a circular import)
71 "examples/audio/pesq.py"
72
73 # Require internet access
74 "examples/text/bertscore.py"
75 "examples/image/clip_score.py"
76 "examples/text/perplexity.py"
77 "examples/text/rouge.py"
78
79 # A trillion import path mismatch errors
80 "src/torchmetrics"
81 ];
82
83 pythonImportsCheck = [ "torchmetrics" ];
84
85 meta = {
86 description = "Machine learning metrics for distributed, scalable PyTorch applications (used in pytorch-lightning)";
87 homepage = "https://lightning.ai/docs/torchmetrics/";
88 changelog = "https://github.com/Lightning-AI/torchmetrics/releases/tag/v${version}";
89 license = lib.licenses.asl20;
90 maintainers = with lib.maintainers; [ SomeoneSerge ];
91 };
92}