nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7
8 # build-system
9 setuptools,
10
11 # dependencies
12 addict,
13 distutils,
14 matplotlib,
15 numpy,
16 opencv4,
17 pyyaml,
18 rich,
19 termcolor,
20 yapf,
21
22 # tests
23 bitsandbytes,
24 dvclive,
25 lion-pytorch,
26 lmdb,
27 mlflow,
28 parameterized,
29 pytestCheckHook,
30 transformers,
31 writableTmpDirAsHomeHook,
32}:
33
34buildPythonPackage rec {
35 pname = "mmengine";
36 version = "0.10.7";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "open-mmlab";
41 repo = "mmengine";
42 tag = "v${version}";
43 hash = "sha256-hQnwenuxHQwl+DwQXbIfsKlJkmcRvcHV1roK7q2X1KA=";
44 };
45
46 patches = [
47 # Explicitly disable weights_only in torch.load calls
48 # https://github.com/open-mmlab/mmengine/pull/1650
49 (fetchpatch {
50 name = "torch-2.6.0-compat.patch";
51 url = "https://github.com/open-mmlab/mmengine/pull/1650/commits/c21b8431b2c625560a3866c65328cff0380ba1f8.patch";
52 hash = "sha256-SLr030IdYD9wM/jPJuZd+Dr1jjFx/5/YkJj/IwhnNQg=";
53 })
54 ];
55
56 postPatch =
57 # Fails in python >= 3.13
58 # exec(compile(f.read(), version_file, "exec")) does not populate the locals() namesp
59 # In python 3.13, the locals() dictionary in a function does not automatically update with
60 # changes made by exec().
61 # https://peps.python.org/pep-0558/
62 ''
63 substituteInPlace setup.py \
64 --replace-fail \
65 "return locals()['__version__']" \
66 "return '${version}'"
67 ''
68 + ''
69 substituteInPlace tests/test_config/test_lazy.py \
70 --replace-fail "import numpy.compat" ""
71 '';
72
73 build-system = [ setuptools ];
74
75 dependencies = [
76 addict
77 distutils
78 matplotlib
79 numpy
80 opencv4
81 pyyaml
82 rich
83 termcolor
84 yapf
85 ];
86
87 pythonImportsCheck = [ "mmengine" ];
88
89 nativeCheckInputs = [
90 bitsandbytes
91 dvclive
92 lion-pytorch
93 lmdb
94 mlflow
95 parameterized
96 pytestCheckHook
97 transformers
98 writableTmpDirAsHomeHook
99 ];
100
101 preCheck =
102 # Otherwise, the backprop hangs forever. More precisely, this exact line:
103 # https://github.com/open-mmlab/mmengine/blob/02f80e8bdd38f6713e04a872304861b02157905a/tests/test_runner/test_activation_checkpointing.py#L46
104 # Solution suggested in https://github.com/pytorch/pytorch/issues/91547#issuecomment-1370011188
105 ''
106 export MKL_NUM_THREADS=1
107 '';
108
109 disabledTestPaths = [
110 # Require unpackaged aim
111 "tests/test_visualizer/test_vis_backend.py::TestAimVisBackend"
112
113 # Cannot find SSL certificate
114 # _pygit2.GitError: OpenSSL error: failed to load certificates: error:00000000:lib(0)::reason(0)
115 "tests/test_visualizer/test_vis_backend.py::TestDVCLiveVisBackend"
116
117 # AttributeError: type object 'MagicMock' has no attribute ...
118 "tests/test_fileio/test_backends/test_petrel_backend.py::TestPetrelBackend"
119 ]
120 ++ lib.optionals stdenv.hostPlatform.isDarwin [
121 # RuntimeError: attempt to insert nil object from objects[1]
122 "tests/test_visualizer/test_visualizer.py::TestVisualizer::test_draw_featmap"
123 "tests/test_visualizer/test_visualizer.py::TestVisualizer::test_show"
124
125 # AssertionError: torch.bfloat16 != torch.float32
126 "tests/test_runner/test_amp.py::TestAmp::test_autocast"
127
128 # ValueError: User specified autocast device_type must be cuda or cpu, but got mps
129 "tests/test_runner/test_runner.py::TestRunner::test_test"
130 "tests/test_runner/test_runner.py::TestRunner::test_val"
131
132 # Fails in pytestCheckHook due to multiple copies accessing the same resources (nixpkgs-review
133 "tests/test_hooks/test_ema_hook.py::TestEMAHook::test_after_test_epoch"
134 "tests/test_hooks/test_ema_hook.py::TestEMAHook::test_after_val_epoch"
135 "tests/test_hooks/test_ema_hook.py::TestEMAHook::test_before_test_epoch"
136 "tests/test_hooks/test_ema_hook.py::TestEMAHook::test_before_val_epoch"
137 "tests/test_infer/test_infer.py"
138 "tests/test_runner/test_runner.py::TestRunner::test_checkpoint"
139
140 # torch.distributed.DistNetworkError: [...] message: address already in use
141 # Happens in nixpkgs-review due to the lack of network namespacing
142 # Note: These all worked fine in nix-build
143 "tests/test_dist/test_dist.py"
144 "tests/test_dist/test_utils.py" # fails in _init_dist_env
145 "tests/test_hooks/test_sync_buffers_hook.py::TestSyncBuffersHook::test_sync_buffers_hook"
146 "tests/test_model/test_model_utils.py::test_is_model_wrapper"
147 "tests/test_model/test_wrappers/test_model_wrapper.py::TestDistributedDataParallel"
148 "tests/test_optim/test_optimizer/test_optimizer.py::TestZeroOptimizer::test_zero_redundancy_optimizer"
149 "tests/test_runner/test_runner.py::TestRunner::test_custom_loop"
150 "tests/test_runner/test_runner.py::TestRunner::test_default_scope"
151 "tests/test_runner/test_runner.py::TestRunner::test_init"
152 "tests/test_runner/test_runner.py::TestRunner::test_train"
153 "tests/test_optim/test_optimizer/test_optimizer_wrapper.py::TestOptimWrapper::test_optim_context"
154 "tests/test_testing/test_runner_test_case.py"
155
156 # TypeError: 'BaseDataset' object is not callable
157 "tests/test_dataset/test_base_dataset.py::TestBaseDataset::test_get_subset[False-True]"
158 ];
159
160 disabledTests = [
161 # Require network access
162 "test_fileclient"
163 "test_http_backend"
164 "test_misc"
165
166 # RuntimeError
167 "test_dump"
168 "test_deepcopy"
169 "test_copy"
170 "test_lazy_import"
171
172 # AssertionError: os is not <module 'os' (frozen)>
173 "test_lazy_module"
174 ]
175 ++ lib.optionals stdenv.hostPlatform.isDarwin [
176 # Fails when max-jobs is set to use fewer processes than cores
177 # for example `AssertionError: assert 14 == 4`
178 "test_setup_multi_processes"
179
180 # Crashes in pytestCheckHook due to MPS incompatibility in torch
181 "test_with_runner"
182 ];
183
184 meta = {
185 description = "Library for training deep learning models based on PyTorch";
186 homepage = "https://github.com/open-mmlab/mmengine";
187 changelog = "https://github.com/open-mmlab/mmengine/releases/tag/v${version}";
188 license = with lib.licenses; [ asl20 ];
189 maintainers = with lib.maintainers; [ rxiao ];
190 };
191}