summary refs log tree commit diff
path: root/pkgs/development/python-modules/openai-whisper/default.nix
blob: 68f692e4c37a25c60beda4655fe4eeaa9d593982 (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
{ lib
, fetchFromGitHub
, buildPythonPackage
, substituteAll
, cudaSupport ? false

# runtime
, ffmpeg-headless

# propagates
, numpy
, torch
, torchWithCuda
, tqdm
, more-itertools
, transformers
, numba
, openai-triton
, scipy
, tiktoken

# tests
, pytestCheckHook
}:

buildPythonPackage rec {
  pname = "whisper";
  version = "20230918";
  format = "setuptools";

  src = fetchFromGitHub {
    owner = "openai";
    repo = pname;
    rev = "refs/tags/v${version}";
    hash = "sha256-wBAanFVEIIzTcoX40P9eI26UdEu0SC/xuife/zi2Xho=";
  };

  patches = [
    (substituteAll {
      src = ./ffmpeg-path.patch;
      ffmpeg = ffmpeg-headless;
    })
  ];

  propagatedBuildInputs = [
    numpy
    tqdm
    more-itertools
    transformers
    numba
    scipy
    tiktoken
  ] ++ lib.optionals (!cudaSupport) [
    torch
  ] ++ lib.optionals (cudaSupport) [
    openai-triton
    torchWithCuda
  ];

  postPatch = ''
    substituteInPlace requirements.txt \
      --replace "tiktoken==0.3.3" "tiktoken>=0.3.3"
  ''
  # openai-triton is only needed for CUDA support.
  # triton needs CUDA to be build.
  # -> by making it optional, we can build whisper without unfree packages enabled
  + lib.optionalString (!cudaSupport) ''
    sed -i '/if sys.platform.startswith("linux") and platform.machine() == "x86_64":/{N;d}' setup.py
  '';

  preCheck = ''
    export HOME=$TMPDIR
  '';

  nativeCheckInputs = [
    pytestCheckHook
  ];

  disabledTests = [
    # requires network access to download models
    "test_transcribe"
    # requires NVIDIA drivers
    "test_dtw_cuda_equivalence"
    "test_median_filter_equivalence"
  ];

  meta = with lib; {
    changelog = "https://github.com/openai/whisper/blob/v$[version}/CHANGELOG.md";
    description = "General-purpose speech recognition model";
    homepage = "https://github.com/openai/whisper";
    license = licenses.mit;
    maintainers = with maintainers; [ hexa MayNiklas ];
  };
}