1{
2 buildPythonPackage,
3 pythonAtLeast,
4 fetchFromGitHub,
5 setuptools,
6 lib,
7 libjpeg,
8 numba,
9 opencv4,
10 pandas,
11 pkg-config,
12 pytorch-pfn-extras,
13 terminaltables,
14 tqdm,
15 pytestCheckHook,
16 assertpy,
17 psutil,
18 torchvision,
19 webdataset,
20}:
21
22buildPythonPackage rec {
23 pname = "ffcv";
24 version = "1.0.0";
25 pyproject = true;
26
27 # version 1.0.0 uses distutils which was removed in Python 3.12
28 disabled = pythonAtLeast "3.12";
29
30 src = fetchFromGitHub {
31 owner = "libffcv";
32 repo = pname;
33 rev = "refs/tags/v${version}";
34 hash = "sha256-L2mwGFivq/gtAw+1D6U2jbW6VxYgetHX7OUrjwyybqE=";
35 };
36
37 # See https://github.com/libffcv/ffcv/issues/159.
38 postPatch = ''
39 substituteInPlace setup.py \
40 --replace-fail "'assertpy'," "" \
41 --replace-fail "'fastargs'," "" \
42 --replace-fail "'opencv-python'," "" \
43 --replace-fail "'psutil'," "" \
44 '';
45
46 build-system = [ setuptools ];
47 nativeBuildInputs = [ pkg-config ];
48 buildInputs = [ libjpeg ];
49 propagatedBuildInputs = [
50 opencv4
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 };
112}