1
Fork 0
mirror of https://https.git.savannah.gnu.org/git/guix.git/ synced 2025-07-13 02:20:53 +02:00

gnu: Add ctranslate2.

* gnu/packages/machine-learning.scm (ctranslate2): New variable.
* gnu/packages/patches/CTranslate2-local-build.patch: New file.
* gnu/local.mk: Record patch.

Co-authored-by: Nicolas Graves <ngraves@ngraves.fr>
Change-Id: I61f04d92c9f4c7bff41b62867ef43e8cf3ad87ea
This commit is contained in:
Fi guadec 2025-06-15 02:07:16 +02:00 committed by Andreas Enge
parent 1146cfa250
commit ef846411d5
No known key found for this signature in database
GPG key ID: F7D5C9BF765C61E3
3 changed files with 176 additions and 0 deletions

View file

@ -1163,6 +1163,7 @@ dist_patch_DATA = \
%D%/packages/patches/crda-optional-gcrypt.patch \
%D%/packages/patches/clucene-contribs-lib.patch \
%D%/packages/patches/csvkit-set-locale-for-tests.patch \
%D%/packages/patches/ctranslate2-local-build.patch \
%D%/packages/patches/cube-nocheck.patch \
%D%/packages/patches/cups-minimal-Address-PPD-injection-issues.patch \
%D%/packages/patches/curl-CVE-2024-8096.patch \

View file

@ -30,6 +30,7 @@
;;; Copyright © 2024 Spencer King <spencer.king@geneoscopy.com>
;;; Copyright © 2024, 2025 David Elsing <david.elsing@posteo.net>
;;; Copyright © 2024 Andy Tai <atai@atai.org>
;;; Copyright © 2025 Lapearldot <lapearldot@disroot.org>
;;;
;;; This file is part of GNU Guix.
;;;
@ -107,6 +108,7 @@
#:use-module (gnu packages libffi)
#:use-module (gnu packages linux)
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (gnu packages maths)
#:use-module (gnu packages mpi)
#:use-module (gnu packages ninja)
@ -6291,6 +6293,50 @@ Transformers is backed by the three most popular deep learning libraries —
Jax, PyTorch and TensorFlow with a seamless integration between them.")
(license license:asl2.0)))
(define-public ctranslate2
(package
(name "ctranslate2")
(version "4.6.0")
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/OpenNMT/CTranslate2")
(commit (string-append "v" version))))
(file-name (git-file-name "CTranslate2" version))
(sha256 (base32 "0sngxjq5rmrgjabgxfazdnhfn3wpfi62n226f4k47cx1xjjkllcd"))
(patches (search-patches "ctranslate2-local-build.patch"))))
(build-system cmake-build-system)
(arguments
(list
#:test-target "ctranslate2_test"
;; XXX: mkl and openblas seem incompatible.
#:configure-flags `(list "-DBUILD_TESTS=ON"
"-DWITH_ACCELERATE=OFF"
"-DWITH_RUY=OFF"
"-DWITH_DNNL=ON"
"-DWITH_CUDA=OFF"
"-DWITH_CUDNN=OFF"
"-DWITH_MKL=OFF"
"-DWITH_OPENBLAS=ON")))
(native-inputs (list libomp
cxxopts
spdlog
googletest
cpu-features
oneapi-dnnl
openblas))
(home-page "https://opennmt.net/CTranslate2/")
(synopsis "Fast inference engine for Transformer models")
(description "CTranslate2 is a C++ and Python library for efficient
inference with Transformer models.
The project implements a custom runtime that applies many performance
optimization techniques such as weights quantization, layers fusion, batch
reordering, etc., to accelerate and reduce the memory usage of Transformer
models on CPU and GPU.")
(license license:expat)))
(define-public python-hmmlearn
(package
(name "python-hmmlearn")

View file

@ -0,0 +1,129 @@
Patch subprojects to use guix builds instead
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62b99d1..c1ac38a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -98,7 +98,7 @@ else()
endif()
find_package(Threads)
-add_subdirectory(third_party/spdlog EXCLUDE_FROM_ALL)
+find_package( spdlog)
set(PRIVATE_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src
@@ -249,9 +249,10 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)|(AMD64)")
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS OFF)
set(BUILD_TESTING OFF)
- add_subdirectory(third_party/cpu_features EXCLUDE_FROM_ALL)
+ find_package( CpuFeatures)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")
- list(APPEND LIBRARIES cpu_features)
+ find_library( CPU_FEATURES_LIBRARIES cpu_features)
+ list(APPEND LIBRARIES ${CPU_FEATURES_LIBRARIES})
endif()
if(ENABLE_CPU_DISPATCH)
@@ -349,8 +350,8 @@ if(WITH_MKL)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
set(MKL_LIBRARIES
- ${MKL_LIBRARY_DIR}/libmkl_core.a
- ${MKL_LIBRARY_DIR}/libmkl_intel_ilp64.a
+ ${MKL_LIBRARY_DIR}/libmkl_core.so
+ ${MKL_LIBRARY_DIR}/libmkl_intel_ilp64.so
)
endif()
@@ -358,19 +359,19 @@ if(WITH_MKL)
if(WIN32)
list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/mkl_intel_thread.lib)
else()
- list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_intel_thread.a)
+ list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_intel_thread.so)
endif()
elseif(OPENMP_RUNTIME STREQUAL "COMP")
if(WIN32)
message(FATAL_ERROR "Building with MKL requires Intel OpenMP")
else()
- list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_gnu_thread.a)
+ list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_gnu_thread.so)
endif()
elseif(OPENMP_RUNTIME STREQUAL "NONE")
if(WIN32)
list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/mkl_sequential.lib)
else()
- list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_sequential.a)
+ list(APPEND MKL_LIBRARIES ${MKL_LIBRARY_DIR}/libmkl_sequential.so)
endif()
endif()
list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${MKL_INCLUDE_DIR})
@@ -439,6 +440,7 @@ if (WITH_RUY)
add_definitions(-DCT2_WITH_RUY)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CPUINFO_LIBRARY_TYPE static CACHE STRING "cpuinfo library type")
+ # if package found and appended to libraries, issue with linking
add_subdirectory(third_party/ruy EXCLUDE_FROM_ALL)
unset(CMAKE_POSITION_INDEPENDENT_CODE)
list(APPEND LIBRARIES ruy)
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index 3311ad3..7d90693 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -1,14 +1,12 @@
-if (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../third_party/cxxopts/include")
- message(FATAL_ERROR "The client dependency repository (cxxopts) is missing! "
- "You probably didn't clone the project with --recursive. You can include it "
- "by calling \"git submodule update --init --recursive\"")
-endif()
-
add_executable(translator
translator.cc
)
+find_path(
+ CXXOPTS_ROOT
+ include/cxxopts.hpp
+)
target_include_directories(translator
- PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/cxxopts/include
+ PRIVATE ${CXXOPTS_ROOT}/include
)
target_link_libraries(translator
PRIVATE ${PROJECT_NAME}
diff --git a/src/cpu/cpu_info.cc b/src/cpu/cpu_info.cc
index 9030ac7..6949644 100644
--- a/src/cpu/cpu_info.cc
+++ b/src/cpu/cpu_info.cc
@@ -4,7 +4,7 @@
#include <cstring>
-#include <cpuinfo_x86.h>
+#include <cpu_features/cpuinfo_x86.h>
namespace ctranslate2 {
namespace cpu {
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 283c49d..9ca6cc8 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,7 +2,7 @@ enable_testing()
option(BUILD_GMOCK "" OFF)
option(INSTALL_GTEST "" OFF)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest)
+find_package( GTest)
add_executable(ctranslate2_test
batching_test.cc
@@ -20,7 +20,7 @@ target_include_directories(ctranslate2_test PRIVATE
)
target_link_libraries(ctranslate2_test
${PROJECT_NAME}
- gtest_main
+ gtest
)
add_executable(benchmark_ops