about summary refs log tree commit diff
path: root/pkgs/development/python-modules/skorch/default.nix
blob: 9351d806b154d18bbcd1fa8c9045d5ce2c1079e7 (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
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPypi,
  fetchpatch,
  pythonOlder,
  numpy,
  scikit-learn,
  scipy,
  tabulate,
  torch,
  tqdm,
  flaky,
  pandas,
  pytestCheckHook,
  safetensors,
  pythonAtLeast,
}:

buildPythonPackage rec {
  pname = "skorch";
  version = "0.15.0";
  format = "setuptools";

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-39XVBlCmbg162z9uL84GZrU+v+M8waXbGdVV72ZYf84=";
  };

  # Remove at next skorch release:
  patches = [
    (fetchpatch {
      name = "unbreak-tests-with-sklearn-1.4";
      url = "https://github.com/skorch-dev/skorch/commit/1f7a779d0aa78589e17262c206f5775f2fcd75f8.diff";
      hash = "sha256-X3SgjgDeq3PlBI13cC56LIL1dV1e+Z3tsBj9sz5pizo=";
    })
  ];

  disabled = pythonOlder "3.8";

  propagatedBuildInputs = [
    numpy
    scikit-learn
    scipy
    tabulate
    torch
    tqdm
  ];

  nativeCheckInputs = [
    flaky
    pandas
    pytestCheckHook
    safetensors
  ];

  # patch out pytest-cov dep/invocation
  postPatch = ''
    substituteInPlace setup.cfg  \
      --replace "--cov=skorch" ""  \
      --replace "--cov-report=term-missing" ""  \
      --replace "--cov-config .coveragerc" ""
  '';

  disabledTests =
    [
      # on CPU, these expect artifacts from previous GPU run
      "test_load_cuda_params_to_cpu"
      # failing tests
      "test_pickle_load"
    ]
    ++ lib.optionals stdenv.isDarwin [
      # there is a problem with the compiler selection
      "test_fit_and_predict_with_compile"
    ]
    ++ lib.optionals (pythonAtLeast "3.11") [
      # Python 3.11+ not yet supported for torch.compile
      # https://github.com/pytorch/pytorch/blob/v2.0.1/torch/_dynamo/eval_frame.py#L376-L377
      "test_fit_and_predict_with_compile"
    ];

  disabledTestPaths =
    [
      # tries to import `transformers` and download HuggingFace data
      "skorch/tests/test_hf.py"
    ]
    ++ lib.optionals (stdenv.hostPlatform.system != "x86_64-linux") [
      # torch.distributed is disabled by default in darwin
      # aarch64-linux also failed these tests
      "skorch/tests/test_history.py"
    ];

  pythonImportsCheck = [ "skorch" ];

  meta = with lib; {
    description = "Scikit-learn compatible neural net library using Pytorch";
    homepage = "https://skorch.readthedocs.io";
    changelog = "https://github.com/skorch-dev/skorch/blob/master/CHANGES.md";
    license = licenses.bsd3;
    maintainers = with maintainers; [ bcdarwin ];
  };
}