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

Is the Go binding still being maintained? #2689

Open
arthasshi opened this issue Jan 1, 2025 · 7 comments
Open

Is the Go binding still being maintained? #2689

arthasshi opened this issue Jan 1, 2025 · 7 comments

Comments

@arthasshi
Copy link

Hi there,

Is the Go binding for whisper.cpp still being maintained?

Currently, the documentation for the Go binding contains many errors. Following the documentation, it’s even impossible to compile the basic libwhisper.a. It seems that the core code of whisper.cpp has undergone significant changes, but the Go binding hasn’t been updated accordingly.

I sincerely hope the authors or contributors could update the Go binding. If there’s anything I can help with, please feel free to let me know.

Personally, I believe that, besides C++, Golang is one of the most suitable programming languages for tasks like this. I really hope the Go binding will continue to be maintained and improved.

Thank you very much!

@resolutecake
Copy link

resolutecake commented Jan 9, 2025

When migrating to CMake ~241214 , the libwhisper.a target was not included in the migration
#2696 (comment)

The Go code isn’t written by someone used to Go trying to avoid allocations. Working bindings are really helpful to test things

@evandrocoan
Copy link

I managed to build whisper v1.7.4, link it and run it with this:

cmake ./whisper.cpp -B ./whisper.cpp/build
cmake --build ./whisper.cpp/build --config Release

WHISPER_DIR=$(abspath ../whisper.cpp)
INCLUDE_PATH=$(WHISPER_DIR)/include:$(WHISPER_DIR)/ggml/include
LIBRARY_PATH=$(WHISPER_DIR)/build/src/

C_INCLUDE_PATH="${INCLUDE_PATH}" LIBRARY_PATH="${LIBRARY_PATH}" LD_LIBRARY_PATH="${LIBRARY_PATH}" go run main.go

@resolutecake
Copy link

On macOS 15.2 M that did not work:

W='/opt/oth/whisper.cpp' C_INCLUDE_PATH="$W/include:$W/ggml/include" LIBRARY_PATH="$W/build/src" LD_LIBRARY_PATH="$LIBRARY_PATH" go run ./myGoMainDir

/opt/homebrew/Cellar/go/1.23.4/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
/usr/bin/cc -arch arm64 -Wl,-S -Wl,-x -o $WORK/b001/exe/gp-gisper /var/folders/sq/0x1_9fyn1bv907s7y
pfryt1c0000gn/T/go-link-1513937620/go.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-15
13937620/000000.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000001.o /var
/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000002.o /var/folders/sq/0x1_9fyn1b
v907s7ypfryt1c0000gn/T/go-link-1513937620/000003.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T
/go-link-1513937620/000004.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/00
0005.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000006.o /var/folders/sq
/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000007.o /var/folders/sq/0x1_9fyn1bv907s7ypfry
t1c0000gn/T/go-link-1513937620/000008.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000009.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000010.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000011.o /var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-link-1513937620/000012.o -lresolv -O2 -g -lwhisper -lm -lstdc++ -fopenmp -framework Accelerate -framework Metal -framework Foundation -framework CoreGraphics -O2 -g -framework CoreFoundation -framework CoreFoundation -framework Security
clang: error: unsupported option '-fopenmp'

to get OpenMP on macOS:

brew install llwm
export CC="$(brew --prefix)/opt/llvm/bin/clang"
export CXX="$(brew --prefix)/opt/llvm/bin/clang++"
export PATH="$(brew --prefix)/opt/llvm/bin:$PATH"

result:
dyld[99921]: Library not loaded: @rpath/libwhisper.1.dylib
Referenced from: <948A0163-1AA2-328E-DBAB-8AD0E58E056B> /private/var/folders/sq/0x1_9fyn1bv907s7ypfryt1c0000gn/T/go-build3222785088/b001/exe/gp-gisper
Reason: no LC_RPATH's found
signal: abort trap

find /opt/oth/whisper.cpp -name libwhisper.1.dylib
/opt/oth/whisper.cpp/build/src/libwhisper.1.dylib

@resolutecake
Copy link

resolutecake commented Jan 13, 2025

Go bindings macOS 15.2 M 250109 hash 2ab2eb5

whisper.cpp with Core ML and OpenMP

//
// get non-apple llvm that supports OpenMP
— as brew
brew install llvm
//
— as user in whisper.cpp directory:
export OpenMP_ROOT=$(brew --prefix)/opt/libomp
cmake -B build -DWHISPER_COREML=1
-- Found OpenMP: TRUE (found version "5.1")
-- CoreML framework found
cmake --build build -j --config Release

run Go code using whisper.cpp as library

// use model large-v3-turbo
// use Core ML
export CC="$(brew --prefix)/opt/llvm/bin/clang"
export DYLD_LIBRARY_PATH=/opt/oth/whisper.cpp/build/src
W='/opt/oth/whisper.cpp' C_INCLUDE_PATH="$W/include:$W/ggml/include" LIBRARY_PATH="$W/build/src" LD_LIBRARY_PATH="$LIBRARY_PATH" go run ./GoMainDirectory

whisper_init_state: loading Core ML model from '/opt/oth/whisper.cpp/models/ggml-large-v3-turbo-encoder.mlmodelc'
whisper_init_state: Core ML model loaded
And so, my fellow Americans…

@AMDphreak
Copy link

The documentation's sample code doesn't seem to even use the methods provided by the Context object. It has context.Process(samples, nil, nil in the sample code, but that method doesn't exist in the Context object's manifest below it.

@resolutecake
Copy link

resolutecake commented Jan 19, 2025

The Go package documentation outlines what is possible:
https://pkg.go.dev/github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper#Context

Looking at this naive Go code, you can implement whatever you need:
https://github.com/ggerganov/whisper.cpp/blob/master/bindings/go/examples/go-whisper/main.go
— in main(), Process is a top-level function of the main package eventually delegating to context.Process:

if err := context.Process(data, cb, nil); err != nil {

sample-code invokes NewContext here:

context, err := model.NewContext()

For some reason, Context configuration is with flag parsing:

func (flags *Flags) SetParams(context whisper.Context) error {

@AMDphreak
Copy link

The download URL in the go binding sample main.go was wrong. I submitted a Pull Request with the updated URL: #2756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants