fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, darwin # Accelerate
6, llvmPackages # openmp
7, withMkl ? false, mkl
8, withCUDA ? false
9, withCuDNN ? false
10, cudaPackages
11# Enabling both withOneDNN and withOpenblas is broken
12# https://github.com/OpenNMT/CTranslate2/issues/1294
13, withOneDNN ? false, oneDNN
14, withOpenblas ? true, openblas
15, withRuy ? true
16
17# passthru tests
18, libretranslate
19, wyoming-faster-whisper
20}:
21
22let
23 cmakeBool = b: if b then "ON" else "OFF";
24in
25stdenv.mkDerivation rec {
26 pname = "ctranslate2";
27 version = "3.21.0";
28
29 src = fetchFromGitHub {
30 owner = "OpenNMT";
31 repo = "CTranslate2";
32 rev = "v${version}";
33 hash = "sha256-ehybfwwMYMKPPeyv05zgDxmw0zr35eoY8wc/tb7DQw0=";
34 fetchSubmodules = true;
35 };
36
37 nativeBuildInputs = [
38 cmake
39 ] ++ lib.optionals withCUDA [
40 cudaPackages.cuda_nvcc
41 ];
42
43 cmakeFlags = [
44 # https://opennmt.net/CTranslate2/installation.html#build-options
45 # https://github.com/OpenNMT/CTranslate2/blob/54810350e662ebdb01ecbf8e4a746f02aeff1dd7/python/tools/prepare_build_environment_linux.sh#L53
46 # https://github.com/OpenNMT/CTranslate2/blob/59d223abcc7e636c1c2956e62482bc3299cc7766/python/tools/prepare_build_environment_macos.sh#L12
47 "-DOPENMP_RUNTIME=COMP"
48 "-DWITH_CUDA=${cmakeBool withCUDA}"
49 "-DWITH_CUDNN=${cmakeBool withCuDNN}"
50 "-DWITH_DNNL=${cmakeBool withOneDNN}"
51 "-DWITH_OPENBLAS=${cmakeBool withOpenblas}"
52 "-DWITH_RUY=${cmakeBool withRuy}"
53 "-DWITH_MKL=${cmakeBool withMkl}"
54 ]
55 ++ lib.optional stdenv.isDarwin "-DWITH_ACCELERATE=ON";
56
57 buildInputs = lib.optionals withMkl [
58 mkl
59 ] ++ lib.optionals withCUDA [
60 cudaPackages.cuda_cudart
61 cudaPackages.libcublas
62 cudaPackages.libcurand
63 ] ++ lib.optionals withCuDNN [
64 cudaPackages.cudnn
65 ] ++ lib.optionals withOneDNN [
66 oneDNN
67 ] ++ lib.optionals withOpenblas [
68 openblas
69 ] ++ lib.optionals stdenv.isDarwin [
70 llvmPackages.openmp
71 darwin.apple_sdk.frameworks.Accelerate
72 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
73 darwin.apple_sdk.frameworks.CoreGraphics
74 darwin.apple_sdk.frameworks.CoreVideo
75 ];
76
77 passthru.tests = {
78 inherit
79 libretranslate
80 wyoming-faster-whisper
81 ;
82 };
83
84 meta = with lib; {
85 description = "Fast inference engine for Transformer models";
86 homepage = "https://github.com/OpenNMT/CTranslate2";
87 changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md";
88 license = licenses.mit;
89 maintainers = with maintainers; [ hexa misuzu ];
90 };
91}