1{
2 buildPythonPackage,
3 pythonAtLeast,
4 fetchFromGitHub,
5 setuptools,
6 lib,
7 libjpeg,
8 numba,
9 opencv-python,
10 pandas,
11 pkg-config,
12 pytorch-pfn-extras,
13 terminaltables,
14 tqdm,
15 pytestCheckHook,
16 assertpy,
17 psutil,
18 torchvision,
19 webdataset,
20 stdenv,
21}:
22
23buildPythonPackage rec {
24 pname = "ffcv";
25 version = "1.0.0";
26 pyproject = true;
27
28 # version 1.0.0 uses distutils which was removed in Python 3.12
29 disabled = pythonAtLeast "3.12";
30
31 src = fetchFromGitHub {
32 owner = "libffcv";
33 repo = pname;
34 rev = "refs/tags/v${version}";
35 hash = "sha256-L2mwGFivq/gtAw+1D6U2jbW6VxYgetHX7OUrjwyybqE=";
36 };
37
38 # See https://github.com/libffcv/ffcv/issues/159.
39 postPatch = ''
40 substituteInPlace setup.py \
41 --replace-fail "'assertpy'," "" \
42 --replace-fail "'fastargs'," "" \
43 --replace-fail "'psutil'," "" \
44 '';
45
46 build-system = [ setuptools ];
47 nativeBuildInputs = [ pkg-config ];
48 buildInputs = [ libjpeg ];
49 propagatedBuildInputs = [
50 opencv-python
51 numba
52 pandas
53 pytorch-pfn-extras
54 terminaltables
55 tqdm
56 ];
57
58 pythonImportsCheck = [ "ffcv" ];
59
60 # C/C++ python modules are only in the installed output and not in the build
61 # directory. Since tests are run from the build directory python prefers to
62 # import the local module first which does not contain the C/C++ python
63 # modules and results in an import error. By changing the directory to
64 # 'tests' the build directory is no long available and python will import
65 # from the installed output in the nix store which does contain the C/C++
66 # python modules.
67 preCheck = ''
68 cd tests
69 '';
70
71 nativeCheckInputs = [
72 assertpy
73 psutil
74 pytestCheckHook
75 torchvision
76 webdataset
77 ];
78
79 disabledTestPaths = [
80 # Tests require network access and do not work in the sandbox
81 "test_augmentations.py"
82 # Occasionally causes the testing phase to hang
83 "test_basic_pipeline.py"
84 ];
85
86 disabledTests = [
87 # Tests require network access and do not work in the sandbox
88 "test_cifar_subset"
89 # Requires CUDA which is unfree and unfree packages are not built by Hydra
90 "test_cuda"
91 "test_gpu_normalization"
92 # torch.multiprocessing.spawn.ProcessRaisedException
93 "test_traversal_sequential_2"
94 "test_traversal_sequential_3"
95 "test_traversal_sequential_4"
96 "test_traversal_random_2"
97 "test_traversal_random_3"
98 "test_traversal_random_4"
99 "test_traversal_sequential_distributed_with_indices"
100 "test_traversal_random_distributed_with_indices"
101 ];
102
103 meta = {
104 description = "FFCV: Fast Forward Computer Vision";
105 homepage = "https://ffcv.io";
106 license = lib.licenses.asl20;
107 maintainers = with lib.maintainers; [
108 samuela
109 djacu
110 ];
111 # OSError: dlopen(libc.so.6, 0x0006): tried: '/usr/lib/libc.so.6' (no such file, not in dyld cache),
112 # 'libc.so.6' (no such file), '/usr/local/lib/libc.so.6' (no such file), '/usr/lib/libc.so.6' (no such file, not in dyld cache)
113 broken = stdenv.hostPlatform.isDarwin;
114 };
115}