2023-07-15 17:15:38 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, cmake
|
|
|
|
, darwin # Accelerate
|
|
|
|
, llvmPackages # openmp
|
|
|
|
, withMkl ? false, mkl
|
2023-11-16 04:20:00 +00:00
|
|
|
, withCUDA ? false
|
|
|
|
, withCuDNN ? false
|
|
|
|
, cudaPackages
|
2023-07-15 17:15:38 +00:00
|
|
|
# Enabling both withOneDNN and withOpenblas is broken
|
|
|
|
# https://github.com/OpenNMT/CTranslate2/issues/1294
|
|
|
|
, withOneDNN ? false, oneDNN
|
|
|
|
, withOpenblas ? true, openblas
|
|
|
|
, withRuy ? true
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
# passthru tests
|
|
|
|
, libretranslate
|
|
|
|
, wyoming-faster-whisper
|
2023-07-15 17:15:38 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cmakeBool = b: if b then "ON" else "OFF";
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "ctranslate2";
|
2024-04-21 15:54:59 +00:00
|
|
|
version = "4.2.0";
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "OpenNMT";
|
|
|
|
repo = "CTranslate2";
|
|
|
|
rev = "v${version}";
|
2024-04-21 15:54:59 +00:00
|
|
|
hash = "sha256-P/aXrzaCF6Rz99Pz9CkpR/FlWXCj04q/4swiAddcwKk=";
|
2023-07-15 17:15:38 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
2023-11-16 04:20:00 +00:00
|
|
|
] ++ lib.optionals withCUDA [
|
|
|
|
cudaPackages.cuda_nvcc
|
2023-07-15 17:15:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
# https://opennmt.net/CTranslate2/installation.html#build-options
|
|
|
|
# https://github.com/OpenNMT/CTranslate2/blob/54810350e662ebdb01ecbf8e4a746f02aeff1dd7/python/tools/prepare_build_environment_linux.sh#L53
|
|
|
|
# https://github.com/OpenNMT/CTranslate2/blob/59d223abcc7e636c1c2956e62482bc3299cc7766/python/tools/prepare_build_environment_macos.sh#L12
|
|
|
|
"-DOPENMP_RUNTIME=COMP"
|
2023-11-16 04:20:00 +00:00
|
|
|
"-DWITH_CUDA=${cmakeBool withCUDA}"
|
|
|
|
"-DWITH_CUDNN=${cmakeBool withCuDNN}"
|
2023-07-15 17:15:38 +00:00
|
|
|
"-DWITH_DNNL=${cmakeBool withOneDNN}"
|
|
|
|
"-DWITH_OPENBLAS=${cmakeBool withOpenblas}"
|
|
|
|
"-DWITH_RUY=${cmakeBool withRuy}"
|
|
|
|
"-DWITH_MKL=${cmakeBool withMkl}"
|
|
|
|
]
|
|
|
|
++ lib.optional stdenv.isDarwin "-DWITH_ACCELERATE=ON";
|
|
|
|
|
|
|
|
buildInputs = lib.optionals withMkl [
|
|
|
|
mkl
|
2023-11-16 04:20:00 +00:00
|
|
|
] ++ lib.optionals withCUDA [
|
2024-01-02 11:29:13 +00:00
|
|
|
cudaPackages.cuda_cccl # <nv/target> required by the fp16 headers in cudart
|
2023-11-16 04:20:00 +00:00
|
|
|
cudaPackages.cuda_cudart
|
|
|
|
cudaPackages.libcublas
|
|
|
|
cudaPackages.libcurand
|
2024-01-02 11:29:13 +00:00
|
|
|
] ++ lib.optionals (withCUDA && withCuDNN) [
|
2023-11-16 04:20:00 +00:00
|
|
|
cudaPackages.cudnn
|
2023-07-15 17:15:38 +00:00
|
|
|
] ++ lib.optionals withOneDNN [
|
|
|
|
oneDNN
|
|
|
|
] ++ lib.optionals withOpenblas [
|
|
|
|
openblas
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
llvmPackages.openmp
|
|
|
|
darwin.apple_sdk.frameworks.Accelerate
|
|
|
|
] ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
|
|
|
|
darwin.apple_sdk.frameworks.CoreGraphics
|
|
|
|
darwin.apple_sdk.frameworks.CoreVideo
|
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
passthru.tests = {
|
|
|
|
inherit
|
|
|
|
libretranslate
|
|
|
|
wyoming-faster-whisper
|
|
|
|
;
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Fast inference engine for Transformer models";
|
2024-04-21 15:54:59 +00:00
|
|
|
mainProgram = "ct2-translator";
|
2023-07-15 17:15:38 +00:00
|
|
|
homepage = "https://github.com/OpenNMT/CTranslate2";
|
|
|
|
changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md";
|
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ hexa misuzu ];
|
2024-01-02 11:29:13 +00:00
|
|
|
broken =
|
|
|
|
(lib.versionOlder cudaPackages.cudaVersion "11.4")
|
|
|
|
|| !(withCuDNN -> withCUDA);
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
}
|