about summary refs log tree commit diff
path: root/pkgs/development/python-modules/ffcv/default.nix
blob: d9c37657adf366ac52809d53354f230df0d796ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
  buildPythonPackage,
  pythonAtLeast,
  fetchFromGitHub,
  setuptools,
  lib,
  libjpeg,
  numba,
  opencv4,
  pandas,
  pkg-config,
  pytorch-pfn-extras,
  terminaltables,
  tqdm,
  pytestCheckHook,
  assertpy,
  psutil,
  torchvision,
  webdataset,
}:

buildPythonPackage rec {
  pname = "ffcv";
  version = "1.0.0";
  pyproject = true;

  # version 1.0.0 uses distutils which was removed in Python 3.12
  disabled = pythonAtLeast "3.12";

  src = fetchFromGitHub {
    owner = "libffcv";
    repo = pname;
    rev = "refs/tags/v${version}";
    hash = "sha256-L2mwGFivq/gtAw+1D6U2jbW6VxYgetHX7OUrjwyybqE=";
  };

  # See https://github.com/libffcv/ffcv/issues/159.
  postPatch = ''
    substituteInPlace setup.py \
      --replace-fail "'assertpy'," "" \
      --replace-fail "'fastargs'," "" \
      --replace-fail "'opencv-python'," "" \
      --replace-fail "'psutil'," "" \
  '';

  build-system = [ setuptools ];
  nativeBuildInputs = [ pkg-config ];
  buildInputs = [ libjpeg ];
  propagatedBuildInputs = [
    opencv4
    numba
    pandas
    pytorch-pfn-extras
    terminaltables
    tqdm
  ];

  pythonImportsCheck = [ "ffcv" ];

  # C/C++ python modules are only in the installed output and not in the build
  # directory. Since tests are run from the build directory python prefers to
  # import the local module first which does not contain the C/C++ python
  # modules and results in an import error. By changing the directory to
  # 'tests' the build directory is no long available and python will import
  # from the installed output in the nix store which does contain the C/C++
  # python modules.
  preCheck = ''
    cd tests
  '';

  nativeCheckInputs = [
    assertpy
    psutil
    pytestCheckHook
    torchvision
    webdataset
  ];

  disabledTestPaths = [
    # Tests require network access and do not work in the sandbox
    "test_augmentations.py"
    # Occasionally causes the testing phase to hang
    "test_basic_pipeline.py"
  ];

  disabledTests = [
    # Tests require network access and do not work in the sandbox
    "test_cifar_subset"
    # Requires CUDA which is unfree and unfree packages are not built by Hydra
    "test_cuda"
    "test_gpu_normalization"
    # torch.multiprocessing.spawn.ProcessRaisedException
    "test_traversal_sequential_2"
    "test_traversal_sequential_3"
    "test_traversal_sequential_4"
    "test_traversal_random_2"
    "test_traversal_random_3"
    "test_traversal_random_4"
    "test_traversal_sequential_distributed_with_indices"
    "test_traversal_random_distributed_with_indices"
  ];

  meta = {
    description = "FFCV: Fast Forward Computer Vision";
    homepage = "https://ffcv.io";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [
      samuela
      djacu
    ];
  };
}