Spaces:
Running
Running
ci : disable Obj-C build + fixes
Browse files- .github/workflows/build.yml +28 -5
- Package.swift +2 -51
- Sources/whisper/module.modulemap +5 -0
- Sources/whisper/whisper.h +4 -0
- cmake/whisper.pc.in +2 -2
- examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt +1 -1
- examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj +2 -2
- examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift +10 -10
.github/workflows/build.yml
CHANGED
|
@@ -518,7 +518,7 @@ jobs:
|
|
| 518 |
emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
|
| 519 |
make
|
| 520 |
|
| 521 |
-
ios:
|
| 522 |
runs-on: macos-latest
|
| 523 |
|
| 524 |
strategy:
|
|
@@ -526,7 +526,7 @@ jobs:
|
|
| 526 |
build: [Release]
|
| 527 |
|
| 528 |
steps:
|
| 529 |
-
- name:
|
| 530 |
uses: actions/checkout@v4
|
| 531 |
|
| 532 |
- name: Configure
|
|
@@ -534,11 +534,34 @@ jobs:
|
|
| 534 |
cp models/for-tests-ggml-base.en.bin models/ggml-base.en.bin
|
| 535 |
mkdir models/ggml-base.en-encoder.mlmodelc
|
| 536 |
|
| 537 |
-
- name: Build
|
| 538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
|
| 540 |
- name: Build swiftui example
|
| 541 |
-
run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk
|
| 542 |
|
| 543 |
android:
|
| 544 |
runs-on: ubuntu-latest
|
|
|
|
| 518 |
emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
|
| 519 |
make
|
| 520 |
|
| 521 |
+
ios-xcode-build:
|
| 522 |
runs-on: macos-latest
|
| 523 |
|
| 524 |
strategy:
|
|
|
|
| 526 |
build: [Release]
|
| 527 |
|
| 528 |
steps:
|
| 529 |
+
- name: Checkout code
|
| 530 |
uses: actions/checkout@v4
|
| 531 |
|
| 532 |
- name: Configure
|
|
|
|
| 534 |
cp models/for-tests-ggml-base.en.bin models/ggml-base.en.bin
|
| 535 |
mkdir models/ggml-base.en-encoder.mlmodelc
|
| 536 |
|
| 537 |
+
- name: Build
|
| 538 |
+
id: cmake_build
|
| 539 |
+
run: |
|
| 540 |
+
sysctl -a
|
| 541 |
+
mkdir build
|
| 542 |
+
cd build
|
| 543 |
+
cmake -G Xcode .. \
|
| 544 |
+
-DGGML_METAL_USE_BF16=ON \
|
| 545 |
+
-DGGML_METAL_EMBED_LIBRARY=ON \
|
| 546 |
+
-DWHISPER_BUILD_EXAMPLES=OFF \
|
| 547 |
+
-DWHISPER_BUILD_TESTS=OFF \
|
| 548 |
+
-DWHISPER_BUILD_SERVER=OFF \
|
| 549 |
+
-DCMAKE_SYSTEM_NAME=iOS \
|
| 550 |
+
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
|
| 551 |
+
-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
|
| 552 |
+
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
|
| 553 |
+
sudo cmake --install . --config Release
|
| 554 |
+
|
| 555 |
+
- name: xcodebuild for swift package
|
| 556 |
+
id: xcodebuild
|
| 557 |
+
run: |
|
| 558 |
+
xcodebuild -scheme whisper-Package -destination 'generic/platform=iOS'
|
| 559 |
+
|
| 560 |
+
#- name: Build objc example
|
| 561 |
+
# run: xcodebuild -project examples/whisper.objc/whisper.objc.xcodeproj -scheme whisper.objc -configuration ${{ matrix.build }} -sdk iphoneos build
|
| 562 |
|
| 563 |
- name: Build swiftui example
|
| 564 |
+
run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' build
|
| 565 |
|
| 566 |
android:
|
| 567 |
runs-on: ubuntu-latest
|
Package.swift
CHANGED
|
@@ -14,55 +14,6 @@ let package = Package(
|
|
| 14 |
.library(name: "whisper", targets: ["whisper"]),
|
| 15 |
],
|
| 16 |
targets: [
|
| 17 |
-
.
|
| 18 |
-
|
| 19 |
-
path: ".",
|
| 20 |
-
exclude: [
|
| 21 |
-
"build",
|
| 22 |
-
"bindings",
|
| 23 |
-
"cmake",
|
| 24 |
-
"examples",
|
| 25 |
-
"scripts",
|
| 26 |
-
"models",
|
| 27 |
-
"samples",
|
| 28 |
-
"tests",
|
| 29 |
-
"CMakeLists.txt",
|
| 30 |
-
"Makefile",
|
| 31 |
-
"ggml/src/ggml-metal/ggml-metal-embed.metal"
|
| 32 |
-
],
|
| 33 |
-
sources: [
|
| 34 |
-
"ggml/src/ggml.c",
|
| 35 |
-
"src/whisper.cpp",
|
| 36 |
-
"ggml/src/ggml-aarch64.c",
|
| 37 |
-
"ggml/src/ggml-alloc.c",
|
| 38 |
-
"ggml/src/ggml-backend.cpp",
|
| 39 |
-
"ggml/src/ggml-backend-reg.cpp",
|
| 40 |
-
"ggml/src/ggml-cpu/ggml-cpu.c",
|
| 41 |
-
"ggml/src/ggml-cpu/ggml-cpu.cpp",
|
| 42 |
-
"ggml/src/ggml-cpu/ggml-cpu-aarch64.c",
|
| 43 |
-
"ggml/src/ggml-cpu/ggml-cpu-quants.c",
|
| 44 |
-
"ggml/src/ggml-quants.c",
|
| 45 |
-
"ggml/src/ggml-threading.cpp",
|
| 46 |
-
"ggml/src/ggml-metal/ggml-metal.m"
|
| 47 |
-
],
|
| 48 |
-
resources: [.process("ggml/src/ggml-metal/ggml-metal.metal")],
|
| 49 |
-
publicHeadersPath: "spm-headers",
|
| 50 |
-
cSettings: [
|
| 51 |
-
.unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
|
| 52 |
-
.unsafeFlags(["-fno-objc-arc"]),
|
| 53 |
-
.headerSearchPath("ggml/src"),
|
| 54 |
-
.define("GGML_USE_ACCELERATE"),
|
| 55 |
-
.define("GGML_USE_METAL")
|
| 56 |
-
// NOTE: NEW_LAPACK will required iOS version 16.4+
|
| 57 |
-
// We should consider add this in the future when we drop support for iOS 14
|
| 58 |
-
// (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
|
| 59 |
-
// .define("ACCELERATE_NEW_LAPACK"),
|
| 60 |
-
// .define("ACCELERATE_LAPACK_ILP64")
|
| 61 |
-
],
|
| 62 |
-
linkerSettings: [
|
| 63 |
-
.linkedFramework("Accelerate")
|
| 64 |
-
]
|
| 65 |
-
)
|
| 66 |
-
],
|
| 67 |
-
cxxLanguageStandard: .cxx11
|
| 68 |
)
|
|
|
|
| 14 |
.library(name: "whisper", targets: ["whisper"]),
|
| 15 |
],
|
| 16 |
targets: [
|
| 17 |
+
.systemLibrary(name: "whisper", pkgConfig: "whisper"),
|
| 18 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
Sources/whisper/module.modulemap
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module whisper [system] {
|
| 2 |
+
header "whisper.h"
|
| 3 |
+
link "whisper"
|
| 4 |
+
export *
|
| 5 |
+
}
|
Sources/whisper/whisper.h
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <whisper.h>
|
| 4 |
+
|
cmake/whisper.pc.in
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
prefix=@CMAKE_INSTALL_PREFIX@
|
| 2 |
exec_prefix=${prefix}
|
| 3 |
-
libdir
|
| 4 |
includedir=${prefix}/include
|
| 5 |
|
| 6 |
Name: whisper
|
| 7 |
Description: Port of OpenAI's Whisper model in C/C++
|
| 8 |
Version: @PROJECT_VERSION@
|
| 9 |
-
Libs: -L${libdir} -lwhisper
|
| 10 |
Cflags: -I${includedir}
|
|
|
|
| 1 |
prefix=@CMAKE_INSTALL_PREFIX@
|
| 2 |
exec_prefix=${prefix}
|
| 3 |
+
libdir=${exec_prefix}/lib
|
| 4 |
includedir=${prefix}/include
|
| 5 |
|
| 6 |
Name: whisper
|
| 7 |
Description: Port of OpenAI's Whisper model in C/C++
|
| 8 |
Version: @PROJECT_VERSION@
|
| 9 |
+
Libs: -L${libdir} -lggml -lggml-base -lwhisper
|
| 10 |
Cflags: -I${includedir}
|
examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt
CHANGED
|
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
|
|
| 2 |
|
| 3 |
project(whisper.cpp)
|
| 4 |
|
| 5 |
-
set(CMAKE_CXX_STANDARD
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
|
| 7 |
|
| 8 |
# Path to external GGML, otherwise uses the copy in whisper.cpp.
|
|
|
|
| 2 |
|
| 3 |
project(whisper.cpp)
|
| 4 |
|
| 5 |
+
set(CMAKE_CXX_STANDARD 17)
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
|
| 7 |
|
| 8 |
# Path to external GGML, otherwise uses the copy in whisper.cpp.
|
examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj
CHANGED
|
@@ -363,7 +363,7 @@
|
|
| 363 |
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
| 364 |
GCC_WARN_UNUSED_FUNCTION = YES;
|
| 365 |
GCC_WARN_UNUSED_VARIABLE = YES;
|
| 366 |
-
HEADER_SEARCH_PATHS =
|
| 367 |
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
| 368 |
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
| 369 |
MTL_FAST_MATH = YES;
|
|
@@ -417,7 +417,7 @@
|
|
| 417 |
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
| 418 |
GCC_WARN_UNUSED_FUNCTION = YES;
|
| 419 |
GCC_WARN_UNUSED_VARIABLE = YES;
|
| 420 |
-
HEADER_SEARCH_PATHS =
|
| 421 |
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
| 422 |
MTL_ENABLE_DEBUG_INFO = NO;
|
| 423 |
MTL_FAST_MATH = YES;
|
|
|
|
| 363 |
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
| 364 |
GCC_WARN_UNUSED_FUNCTION = YES;
|
| 365 |
GCC_WARN_UNUSED_VARIABLE = YES;
|
| 366 |
+
HEADER_SEARCH_PATHS = ../../../ggml/src/;
|
| 367 |
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
| 368 |
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
| 369 |
MTL_FAST_MATH = YES;
|
|
|
|
| 417 |
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
| 418 |
GCC_WARN_UNUSED_FUNCTION = YES;
|
| 419 |
GCC_WARN_UNUSED_VARIABLE = YES;
|
| 420 |
+
HEADER_SEARCH_PATHS = ../../../ggml/src/;
|
| 421 |
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
| 422 |
MTL_ENABLE_DEBUG_INFO = NO;
|
| 423 |
MTL_FAST_MATH = YES;
|
examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift
CHANGED
|
@@ -66,7 +66,7 @@ actor WhisperContext {
|
|
| 66 |
|
| 67 |
private func systemInfo() -> String {
|
| 68 |
var info = ""
|
| 69 |
-
if (ggml_cpu_has_neon() != 0) { info += "NEON " }
|
| 70 |
return String(info.dropLast())
|
| 71 |
}
|
| 72 |
|
|
@@ -75,45 +75,45 @@ actor WhisperContext {
|
|
| 75 |
if (whisper_set_mel(context, nil, 0, nMels) != 0) {
|
| 76 |
return "error: failed to set mel"
|
| 77 |
}
|
| 78 |
-
|
| 79 |
// heat encoder
|
| 80 |
if (whisper_encode(context, 0, nThreads) != 0) {
|
| 81 |
return "error: failed to encode"
|
| 82 |
}
|
| 83 |
-
|
| 84 |
var tokens = [whisper_token](repeating: 0, count: 512)
|
| 85 |
-
|
| 86 |
// prompt heat
|
| 87 |
if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {
|
| 88 |
return "error: failed to decode"
|
| 89 |
}
|
| 90 |
-
|
| 91 |
// text-generation heat
|
| 92 |
if (whisper_decode(context, &tokens, 1, 256, nThreads) != 0) {
|
| 93 |
return "error: failed to decode"
|
| 94 |
}
|
| 95 |
-
|
| 96 |
whisper_reset_timings(context)
|
| 97 |
-
|
| 98 |
// actual run
|
| 99 |
if (whisper_encode(context, 0, nThreads) != 0) {
|
| 100 |
return "error: failed to encode"
|
| 101 |
}
|
| 102 |
-
|
| 103 |
// text-generation
|
| 104 |
for i in 0..<256 {
|
| 105 |
if (whisper_decode(context, &tokens, 1, Int32(i), nThreads) != 0) {
|
| 106 |
return "error: failed to decode"
|
| 107 |
}
|
| 108 |
}
|
| 109 |
-
|
| 110 |
// batched decoding
|
| 111 |
for _ in 0..<64 {
|
| 112 |
if (whisper_decode(context, &tokens, 5, 0, nThreads) != 0) {
|
| 113 |
return "error: failed to decode"
|
| 114 |
}
|
| 115 |
}
|
| 116 |
-
|
| 117 |
// prompt processing
|
| 118 |
for _ in 0..<16 {
|
| 119 |
if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {
|
|
|
|
| 66 |
|
| 67 |
private func systemInfo() -> String {
|
| 68 |
var info = ""
|
| 69 |
+
//if (ggml_cpu_has_neon() != 0) { info += "NEON " }
|
| 70 |
return String(info.dropLast())
|
| 71 |
}
|
| 72 |
|
|
|
|
| 75 |
if (whisper_set_mel(context, nil, 0, nMels) != 0) {
|
| 76 |
return "error: failed to set mel"
|
| 77 |
}
|
| 78 |
+
|
| 79 |
// heat encoder
|
| 80 |
if (whisper_encode(context, 0, nThreads) != 0) {
|
| 81 |
return "error: failed to encode"
|
| 82 |
}
|
| 83 |
+
|
| 84 |
var tokens = [whisper_token](repeating: 0, count: 512)
|
| 85 |
+
|
| 86 |
// prompt heat
|
| 87 |
if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {
|
| 88 |
return "error: failed to decode"
|
| 89 |
}
|
| 90 |
+
|
| 91 |
// text-generation heat
|
| 92 |
if (whisper_decode(context, &tokens, 1, 256, nThreads) != 0) {
|
| 93 |
return "error: failed to decode"
|
| 94 |
}
|
| 95 |
+
|
| 96 |
whisper_reset_timings(context)
|
| 97 |
+
|
| 98 |
// actual run
|
| 99 |
if (whisper_encode(context, 0, nThreads) != 0) {
|
| 100 |
return "error: failed to encode"
|
| 101 |
}
|
| 102 |
+
|
| 103 |
// text-generation
|
| 104 |
for i in 0..<256 {
|
| 105 |
if (whisper_decode(context, &tokens, 1, Int32(i), nThreads) != 0) {
|
| 106 |
return "error: failed to decode"
|
| 107 |
}
|
| 108 |
}
|
| 109 |
+
|
| 110 |
// batched decoding
|
| 111 |
for _ in 0..<64 {
|
| 112 |
if (whisper_decode(context, &tokens, 5, 0, nThreads) != 0) {
|
| 113 |
return "error: failed to decode"
|
| 114 |
}
|
| 115 |
}
|
| 116 |
+
|
| 117 |
// prompt processing
|
| 118 |
for _ in 0..<16 {
|
| 119 |
if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {
|