1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch2,
7
8 # build-system
9 setuptools,
10
11 # dependencies
12 addict,
13 matplotlib,
14 numpy,
15 opencv4,
16 pyyaml,
17 rich,
18 termcolor,
19 yapf,
20
21 # checks
22 bitsandbytes,
23 coverage,
24 dvclive,
25 lion-pytorch,
26 lmdb,
27 mlflow,
28 parameterized,
29 pytestCheckHook,
30 transformers,
31}:
32
33buildPythonPackage rec {
34 pname = "mmengine";
35 version = "0.10.5";
36 pyproject = true;
37
38 src = fetchFromGitHub {
39 owner = "open-mmlab";
40 repo = "mmengine";
41 rev = "refs/tags/v${version}";
42 hash = "sha256-bZ6O4UOYUCwq11YmgRWepOIngYxYD/fNfM/VmcyUv9k=";
43 };
44
45 patches = [
46 (fetchpatch2 {
47 name = "mmengine-torch-2.5-compat.patch";
48 url = "https://github.com/open-mmlab/mmengine/commit/4c22f78cdea2981a2b48a167e9feffe4721f8901.patch";
49 hash = "sha256-k+IFLeqTEVUGGiqmZg56LK64H/UTvpGN20GJT59wf4A=";
50 })
51 (fetchpatch2 {
52 # Bug reported upstream in https://github.com/open-mmlab/mmengine/issues/1575
53 # PR: https://github.com/open-mmlab/mmengine/pull/1589
54 name = "adapt-to-pytest-breaking-change";
55 url = "https://patch-diff.githubusercontent.com/raw/open-mmlab/mmengine/pull/1589.patch";
56 hash = "sha256-lyKf1GCLOPMpDttJ4s9hbATIGCVkiQhtyLfH9WzMWrw=";
57 })
58 ];
59
60 build-system = [ setuptools ];
61
62 dependencies = [
63 addict
64 matplotlib
65 numpy
66 opencv4
67 pyyaml
68 rich
69 termcolor
70 yapf
71 ];
72
73 nativeCheckInputs = [
74 bitsandbytes
75 coverage
76 dvclive
77 lion-pytorch
78 lmdb
79 mlflow
80 parameterized
81 pytestCheckHook
82 transformers
83 ];
84
85 preCheck =
86 ''
87 export HOME=$(mktemp -d)
88 ''
89 # Otherwise, the backprop hangs forever. More precisely, this exact line:
90 # https://github.com/open-mmlab/mmengine/blob/02f80e8bdd38f6713e04a872304861b02157905a/tests/test_runner/test_activation_checkpointing.py#L46
91 # Solution suggested in https://github.com/pytorch/pytorch/issues/91547#issuecomment-1370011188
92 + ''
93 export MKL_NUM_THREADS=1
94 '';
95
96 pythonImportsCheck = [ "mmengine" ];
97
98 disabledTestPaths = [
99 # AttributeError
100 "tests/test_fileio/test_backends/test_petrel_backend.py"
101 # Freezes forever?
102 "tests/test_runner/test_activation_checkpointing.py"
103 # missing dependencies
104 "tests/test_visualizer/test_vis_backend.py"
105 ];
106
107 disabledTests = [
108 # Tests are disabled due to sandbox
109 "test_fileclient"
110 "test_http_backend"
111 "test_misc"
112 # RuntimeError
113 "test_dump"
114 "test_deepcopy"
115 "test_copy"
116 "test_lazy_import"
117 # AssertionError
118 "test_lazy_module"
119 # Require unpackaged aim
120 "test_experiment"
121 "test_add_config"
122 "test_add_image"
123 "test_add_scalar"
124 "test_add_scalars"
125 "test_close"
126 ];
127
128 meta = {
129 description = "Library for training deep learning models based on PyTorch";
130 homepage = "https://github.com/open-mmlab/mmengine";
131 changelog = "https://github.com/open-mmlab/mmengine/releases/tag/v${version}";
132 license = with lib.licenses; [ asl20 ];
133 maintainers = with lib.maintainers; [ rxiao ];
134 broken =
135 stdenv.hostPlatform.isDarwin || (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
136 };
137}