Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in Translation #79

Merged
merged 10 commits into from
Apr 1, 2024
2 changes: 2 additions & 0 deletions .github/actions/build-plugin/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ runs:
}

.github/scripts/Build-Windows.ps1 @BuildArgs
env:
CPU_OR_CUDA: ${{ inputs.cublas }}

- name: Create Summary 📊
if: contains(fromJSON('["Linux", "macOS"]'),runner.os)
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/Package-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function Package {
$BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json
$ProductName = $BuildSpec.name
$ProductVersion = $BuildSpec.version
$CudaName = "cuda${Cublas}"
# Check if $cublas is cpu or cuda
if ( $Cublas -eq 'cpu' ) {
$CudaName = 'cpu'
} else {
$CudaName = "cuda${Cublas}"
}

$OutputName = "${ProductName}-${ProductVersion}-windows-${Target}-${CudaName}"

Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ endif()
include(cmake/BuildWhispercpp.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Whispercpp)

include(cmake/BuildCTranslate2.cmake)
include(cmake/BuildSentencepiece.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ct2 sentencepiece)

target_sources(
${CMAKE_PROJECT_NAME}
PRIVATE src/plugin-main.c
Expand All @@ -65,6 +69,8 @@ target_sources(
src/whisper-utils/whisper-processing.cpp
src/model-utils/model-downloader.cpp
src/model-utils/model-downloader-ui.cpp
src/whisper-utils/whisper-utils.cpp)
src/model-utils/model-infos.cpp
src/whisper-utils/whisper-utils.cpp
src/translation/translation.cpp)

set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})
36 changes: 20 additions & 16 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@
"patch": 0
},
"configurePresets": [
{
"name": "template",
"hidden": true,
"cacheVariables": {
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
}
},
{
"name": "macos",
"displayName": "macOS Universal",
"description": "Build for macOS 11.0+ (Universal binary)",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_macos",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"generator": "Xcode",
"warnings": {"dev": true, "deprecated": true},
"warnings": { "dev": true, "deprecated": true },
"cacheVariables": {
"QT_VERSION": "6",
"CMAKE_OSX_DEPLOYMENT_TARGET": "11.0",
"CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}",
"CODESIGN_TEAM": "$penv{CODESIGN_TEAM}",
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
"CODESIGN_TEAM": "$penv{CODESIGN_TEAM}"
}
},
{
Expand All @@ -41,6 +48,7 @@
"name": "windows-x64",
"displayName": "Windows x64",
"description": "Build for Windows x64",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_x64",
"condition": {
"type": "equals",
Expand All @@ -49,12 +57,10 @@
},
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"warnings": {"dev": true, "deprecated": true},
"warnings": { "dev": true, "deprecated": true },
"cacheVariables": {
"QT_VERSION": "6",
"CMAKE_SYSTEM_VERSION": "10.0.18363.657",
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
"CMAKE_SYSTEM_VERSION": "10.0.18363.657"
}
},
{
Expand All @@ -70,19 +76,18 @@
"name": "linux-x86_64",
"displayName": "Linux x86_64",
"description": "Build for Linux x86_64",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_x86_64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"generator": "Ninja",
"warnings": {"dev": true, "deprecated": true},
"warnings": { "dev": true, "deprecated": true },
"cacheVariables": {
"QT_VERSION": "6",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
Expand All @@ -99,19 +104,18 @@
"name": "linux-aarch64",
"displayName": "Linux aarch64",
"description": "Build for Linux aarch64",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_aarch64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"generator": "Ninja",
"warnings": {"dev": true, "deprecated": true},
"warnings": { "dev": true, "deprecated": true },
"cacheVariables": {
"QT_VERSION": "6",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
Expand Down
22 changes: 11 additions & 11 deletions buildspec.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"dependencies": {
"obs-studio": {
"version": "29.1.2",
"version": "30.0.2",
"baseUrl": "https://github.com/obsproject/obs-studio/archive/refs/tags",
"label": "OBS sources",
"hashes": {
"macos": "215f1fa5772c5dd9f3d6e35b0cb573912b00320149666a77864f9d305525504b",
"windows-x64": "46d451f3f42b9d2c59339ec268165849c7b7904cdf1cc2a8d44c015815a9e37d"
"macos": "be12c3ad0a85713750d8325e4b1db75086223402d7080d0e3c2833d7c5e83c27",
"windows-x64": "970058c49322cfa9cd6d620abb393fed89743ba7e74bd9dbb6ebe0ea8141d9c7"
}
},
"prebuilt": {
"version": "2023-04-12",
"version": "2023-11-03",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built obs-deps",
"hashes": {
"macos": "9535c6e1ad96f7d49960251e85a245774088d48da1d602bb82f734b10219125a",
"windows-x64": "c13a14a1acc4224b21304d97b63da4121de1ed6981297e50496fbc474abc0503"
"macos": "90c2fc069847ec2768dcc867c1c63b112c615ed845a907dc44acab7a97181974",
"windows-x64": "d0825a6fb65822c993a3059edfba70d72d2e632ef74893588cf12b1f0d329ce6"
}
},
"qt6": {
"version": "2023-04-12",
"version": "2023-11-03",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built Qt6",
"hashes": {
"macos": "eb7614544ab4f3d2c6052c797635602280ca5b028a6b987523d8484222ce45d1",
"windows-x64": "4d39364b8a8dee5aa24fcebd8440d5c22bb4551c6b440ffeacce7d61f2ed1add"
"macos": "ba4a7152848da0053f63427a2a2cb0a199af3992997c0db08564df6f48c9db98",
"windows-x64": "bc57dedf76b47119a6dce0435a2f21b35b08c8f2948b1cb34a157320f77732d1"
},
"debugSymbols": {
"windows-x64": "f34ee5067be19ed370268b15c53684b7b8aaa867dc800b68931df905d679e31f"
"windows-x64": "fd8ecd1d8cd2ef049d9f4d7fb5c134f784836d6020758094855dfa98bd025036"
}
}
},
Expand All @@ -45,7 +45,7 @@
}
},
"name": "obs-localvocal",
"version": "0.2.0",
"version": "0.2.1",
"author": "Roy Shilkrot",
"website": "https://github.com/occ-ai/obs-localvocal",
"email": "[email protected]",
Expand Down
104 changes: 104 additions & 0 deletions cmake/BuildCTranslate2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# build the CTranslate2 library from source https://github.com/OpenNMT/CTranslate2.git

include(ExternalProject)
include(FetchContent)

if(APPLE)

FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libctranslate2-macos-Release-1.1.1.tar.gz
URL_HASH SHA256=da04d88ecc1ea105f8ee672e4eab33af96e50c999c5cc8170e105e110392182b)
FetchContent_MakeAvailable(ctranslate2_fetch)

add_library(ct2 INTERFACE)
target_link_libraries(ct2 INTERFACE "-framework Accelerate" ${ctranslate2_fetch_SOURCE_DIR}/lib/libctranslate2.a
${ctranslate2_fetch_SOURCE_DIR}/lib/libcpu_features.a)
set_target_properties(ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ctranslate2_fetch_SOURCE_DIR}/include)
target_compile_options(ct2 INTERFACE -Wno-shorten-64-to-32)

elseif(WIN32)

# check CPU_OR_CUDA environment variable
if(NOT DEFINED ENV{CPU_OR_CUDA})
message(FATAL_ERROR "Please set the CPU_OR_CUDA environment variable to either CPU or CUDA")
endif()

if($ENV{CPU_OR_CUDA} STREQUAL "cpu")
FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cpu.zip
URL_HASH SHA256=30ff8b2499b8d3b5a6c4d6f7f8ddbc89e745ff06e0050b645e3b7c9b369451a3)
else()
# add compile definitions for CUDA
add_compile_definitions(POLYGLOT_WITH_CUDA)
add_compile_definitions(POLYGLOT_CUDA_VERSION=$ENV{CPU_OR_CUDA})

if($ENV{CPU_OR_CUDA} STREQUAL "12.2.0")
FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda12.2.0.zip
URL_HASH SHA256=131724d510f9f2829970953a1bc9e4e8fb7b4cbc8218e32270dcfe6172a51558)
elseif($ENV{CPU_OR_CUDA} STREQUAL "11.8.0")
FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda11.8.0.zip
URL_HASH SHA256=a120bee82f821df35a4646add30ac18b5c23e4e16b56fa7ba338eeae336e0d81)
else()
message(FATAL_ERROR "Unsupported CUDA version: $ENV{CPU_OR_CUDA}")
endif()
endif()

FetchContent_MakeAvailable(ctranslate2_fetch)

add_library(ct2 INTERFACE)
target_link_libraries(ct2 INTERFACE ${ctranslate2_fetch_SOURCE_DIR}/lib/ctranslate2.lib)
set_target_properties(ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ctranslate2_fetch_SOURCE_DIR}/include)
target_compile_options(ct2 INTERFACE /wd4267 /wd4244 /wd4305 /wd4996 /wd4099)

file(GLOB CT2_DLLS ${ctranslate2_fetch_SOURCE_DIR}/bin/*.dll)
install(FILES ${CT2_DLLS} DESTINATION "obs-plugins/64bit")
else()
set(CT2_VERSION "4.1.1")
set(CT2_URL "https://github.com/OpenNMT/CTranslate2.git")
set(CT2_OPENBLAS_CMAKE_ARGS -DWITH_OPENBLAS=OFF)

set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
set(CT2_LIB_INSTALL_LOCATION lib/${CMAKE_SHARED_LIBRARY_PREFIX}ctranslate2${CMAKE_STATIC_LIBRARY_SUFFIX})

ExternalProject_Add(
ct2_build
GIT_REPOSITORY ${CT2_URL}
GIT_TAG v${CT2_VERSION}
GIT_PROGRESS 1
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}
CMAKE_GENERATOR ${CMAKE_GENERATOR}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}
BUILD_BYPRODUCTS <INSTALL_DIR>/${CT2_LIB_INSTALL_LOCATION}
CMAKE_ARGS -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DWITH_CUDA=OFF
-DWITH_MKL=OFF
-DWITH_TESTS=OFF
-DWITH_EXAMPLES=OFF
-DWITH_TFLITE=OFF
-DWITH_TRT=OFF
-DWITH_PYTHON=OFF
-DWITH_SERVER=OFF
-DWITH_COVERAGE=OFF
-DWITH_PROFILING=OFF
-DBUILD_CLI=OFF
${CT2_OPENBLAS_CMAKE_ARGS}
${CT2_CMAKE_PLATFORM_OPTIONS})
ExternalProject_Get_Property(ct2_build INSTALL_DIR)

add_library(ct2::ct2 STATIC IMPORTED GLOBAL)
add_dependencies(ct2::ct2 ct2_build)
set_target_properties(ct2::ct2 PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/${CT2_LIB_INSTALL_LOCATION})

add_library(ct2 INTERFACE)
target_link_libraries(ct2 INTERFACE ct2::ct2)
set_target_properties(ct2::ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)

endif()
61 changes: 61 additions & 0 deletions cmake/BuildSentencepiece.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# build sentencepiece from "https://github.com/google/sentencepiece.git"

if(APPLE)

include(FetchContent)

FetchContent_Declare(
sentencepiece_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libsentencepiece-macos-Release-1.1.1.tar.gz
URL_HASH SHA256=c911f1e84ea94925a8bc3fd3257185b2e18395075509c8659cc7003a979e0b32)
FetchContent_MakeAvailable(sentencepiece_fetch)
add_library(sentencepiece INTERFACE)
target_link_libraries(sentencepiece INTERFACE ${sentencepiece_fetch_SOURCE_DIR}/lib/libsentencepiece.a)
set_target_properties(sentencepiece PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${sentencepiece_fetch_SOURCE_DIR}/include)
elseif(WIN32)

FetchContent_Declare(
sentencepiece_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/sentencepiece-windows-0.2.0-Release.zip
URL_HASH SHA256=846699c7fa1e8918b71ed7f2bd5cd60e47e51105e1d84e3192919b4f0f10fdeb)
FetchContent_MakeAvailable(sentencepiece_fetch)
add_library(sentencepiece INTERFACE)
target_link_libraries(sentencepiece INTERFACE ${sentencepiece_fetch_SOURCE_DIR}/lib/sentencepiece.lib)
set_target_properties(sentencepiece PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${sentencepiece_fetch_SOURCE_DIR}/include)

else()

set(SP_URL
"https://github.com/google/sentencepiece.git"
CACHE STRING "URL of sentencepiece repository")

set(SP_CMAKE_OPTIONS -DSPM_ENABLE_SHARED=OFF)
set(SENTENCEPIECE_INSTALL_LIB_LOCATION lib/${CMAKE_STATIC_LIBRARY_PREFIX}sentencepiece${CMAKE_STATIC_LIBRARY_SUFFIX})

include(ExternalProject)

ExternalProject_Add(
sentencepiece_build
GIT_REPOSITORY ${SP_URL}
GIT_TAG v0.1.99
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}
CMAKE_GENERATOR ${CMAKE_GENERATOR}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}
BUILD_BYPRODUCTS <INSTALL_DIR>/${SENTENCEPIECE_INSTALL_LIB_LOCATION}
CMAKE_ARGS -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${SP_CMAKE_OPTIONS})
ExternalProject_Get_Property(sentencepiece_build INSTALL_DIR)

add_library(libsentencepiece STATIC IMPORTED GLOBAL)
add_dependencies(libsentencepiece sentencepiece_build)
set_target_properties(libsentencepiece PROPERTIES IMPORTED_LOCATION
${INSTALL_DIR}/${SENTENCEPIECE_INSTALL_LIB_LOCATION})

add_library(sentencepiece INTERFACE)
add_dependencies(sentencepiece libsentencepiece)
target_link_libraries(sentencepiece INTERFACE libsentencepiece)
target_include_directories(sentencepiece INTERFACE ${INSTALL_DIR}/include)

endif()
1 change: 1 addition & 0 deletions cmake/macos/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ else()
endif()

add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:DEBUG>:_DEBUG> SIMDE_ENABLE_OPENMP)
add_compile_options(-Wno-error=newline-eof)
Loading
Loading