Skip to content

Commit 46d96d4

Browse files
committed
Merge remote-tracking branch 'ggerganov/master'
* ggerganov/master: make : fix "main" -> "whisper-cli" ci : re-enable Windows cublas build (ggml-org#2676) ruby : Fix of C++ header guard name, model URI support, type signature and more (ggml-org#2683) examples : handle "main.exe" deprecation
2 parents a4ae235 + 227b5ff commit 46d96d4

File tree

11 files changed

+429
-210
lines changed

11 files changed

+429
-210
lines changed

.github/workflows/build.yml

+67-66
Original file line numberDiff line numberDiff line change
@@ -430,72 +430,73 @@ jobs:
430430
name: whisper-blas-bin-${{ matrix.arch }}
431431
path: build/bin/${{ matrix.build }}
432432

433-
# TODO: fix and re-enable
434-
# windows-cublas:
435-
# runs-on: windows-2019
436-
#
437-
# strategy:
438-
# matrix:
439-
# build: [Release]
440-
# arch: [x64]
441-
# cublas: [ON]
442-
# sdl2: [ON]
443-
# cuda-toolkit: [12.2.0, 11.8.0]
444-
# include:
445-
# - arch: x64
446-
# s2arc: x64
447-
# - sdl2: ON
448-
# s2ver: 2.28.5
449-
#
450-
# steps:
451-
# - name: Clone
452-
# uses: actions/checkout@v4
453-
#
454-
# - name: Add msbuild to PATH
455-
# uses: microsoft/setup-msbuild@v2
456-
#
457-
# - name: Install CUDA Toolkit
458-
# id: cuda-toolkit
459-
# uses: Jimver/[email protected]
460-
# with:
461-
# cuda: '${{ matrix.cuda-toolkit }}'
462-
#
463-
# - name: Fetch SDL2 and set SDL2_DIR
464-
# if: matrix.sdl2 == 'ON'
465-
# run: |
466-
# C:/msys64/usr/bin/wget.exe -qO sdl2.zip https://github.com/libsdl-org/SDL/releases/download/release-${{ matrix.s2ver }}/SDL2-devel-${{ matrix.s2ver }}-VC.zip
467-
# 7z x sdl2.zip
468-
# echo "SDL2_DIR=$env:GITHUB_WORKSPACE/SDL2-${{ matrix.s2ver }}/cmake" >> $env:GITHUB_ENV
469-
#
470-
# - name: Configure
471-
# run: >
472-
# cmake -S . -B ./build -A ${{ matrix.arch }}
473-
# -DCMAKE_BUILD_TYPE=${{ matrix.build }}
474-
# -DGGML_CUDA=${{ matrix.cublas }}
475-
# -DWHISPER_SDL2=${{ matrix.sdl2 }}
476-
#
477-
# - name: Build ${{ matrix.cuda-toolkit }}
478-
# run: |
479-
# cd ./build
480-
# cmake --build . --config ${{ matrix.build }}
481-
#
482-
# - name: Copy CUDA DLLs
483-
# run: >
484-
# Copy-Item -PassThru
485-
# -Path "${{ steps.cuda-toolkit.outputs.CUDA_PATH }}/bin/*.dll"
486-
# -Include cudart64_*,cublas64_*,cublasLt64_*
487-
# -Destination build/bin/${{ matrix.build }}
488-
#
489-
# - name: Copy SDL2.dll
490-
# if: matrix.sdl2 == 'ON'
491-
# run: copy "$env:SDL2_DIR/../lib/${{ matrix.s2arc }}/SDL2.dll" build/bin/${{ matrix.build }}
492-
#
493-
# - name: Upload binaries
494-
# if: matrix.sdl2 == 'ON'
495-
# uses: actions/upload-artifact@v4
496-
# with:
497-
# name: whisper-cublas-${{ matrix.cuda-toolkit }}-bin-${{ matrix.arch }}
498-
# path: build/bin/${{ matrix.build }}
433+
windows-cublas:
434+
runs-on: windows-2019
435+
strategy:
436+
matrix:
437+
build: [Release]
438+
arch: [x64]
439+
cublas: [ON]
440+
sdl2: [ON]
441+
cuda-toolkit: [12.2.0, 11.8.0]
442+
include:
443+
- arch: x64
444+
sdl2: ON
445+
sdl2_ver: 2.28.5
446+
steps:
447+
- name: Clone repository
448+
uses: actions/checkout@v4
449+
450+
- name: Add msbuild to PATH
451+
uses: microsoft/setup-msbuild@v2
452+
453+
- name: Install CUDA Toolkit
454+
id: cuda-toolkit
455+
uses: Jimver/[email protected]
456+
with:
457+
cuda: '${{ matrix.cuda-toolkit }}'
458+
459+
- name: Install 7-Zip
460+
run: choco install 7zip -y
461+
462+
- name: Fetch SDL2 and set SDL2_DIR
463+
if: matrix.sdl2 == 'ON'
464+
run: |
465+
Invoke-WebRequest -Uri https://github.com/libsdl-org/SDL/releases/download/release-${{ matrix.sdl2_ver }}/SDL2-devel-${{ matrix.sdl2_ver }}-VC.zip -OutFile sdl2.zip
466+
7z x sdl2.zip
467+
echo "SDL2_DIR=${{ github.workspace }}\SDL2-${{ matrix.sdl2_ver }}\cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
468+
echo "${{ github.workspace }}\SDL2-${{ matrix.sdl2_ver }}\cmake" > SDL2_PATH.txt
469+
470+
- name: Configure CMake
471+
shell: cmd
472+
run: |
473+
cmake -S . -B ./build -A ${{ matrix.arch }} ^
474+
-DCMAKE_BUILD_TYPE=${{ matrix.build }} ^
475+
-DGGML_CUDA=${{ matrix.cublas }} ^
476+
-DCMAKE_CUDA_ARCHITECTURES=all ^
477+
-DWHISPER_SDL2=${{ matrix.sdl2 }} ^
478+
-DSDL2_DIR="%SDL2_DIR%"
479+
480+
- name: Build Project
481+
shell: cmd
482+
run: |
483+
cd ./build
484+
cmake --build . --config ${{ matrix.build }}
485+
486+
- name: Copy CUDA DLLs
487+
run: |
488+
Get-ChildItem "${{ steps.cuda-toolkit.outputs.CUDA_PATH }}/bin/" -Filter "*.dll" |
489+
Copy-Item -Destination "build/bin/${{ matrix.build }}"
490+
491+
- name: Copy SDL2.dll
492+
if: matrix.sdl2 == 'ON'
493+
run: copy "$env:SDL2_DIR/../lib/${{ matrix.arch }}/SDL2.dll" build/bin/${{ matrix.build }}
494+
495+
- name: Upload binaries
496+
uses: actions/upload-artifact@v4
497+
with:
498+
name: whisper-cublas-${{ matrix.cuda-toolkit }}-bin-${{ matrix.arch }}
499+
path: build/bin/${{ matrix.build }}
499500

500501
emscripten:
501502
runs-on: ubuntu-latest

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ tiny.en tiny base.en base small.en small medium.en medium large-v1 large-v2 larg
6464
echo "[+] Running $@ on $$f ... (run 'ffplay $$f' to listen)" ; \
6565
echo "----------------------------------------------" ; \
6666
echo "" ; \
67-
./build/bin/main -m models/ggml-$@.bin -f $$f ; \
67+
./build/bin/whisper-cli -m models/ggml-$@.bin -f $$f ; \
6868
echo "" ; \
6969
done

bindings/ruby/.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
LICENSE
22
pkg/
3-
lib/whisper.so
4-
lib/whisper.bundle
5-
lib/whisper.dll
3+
lib/whisper.*

bindings/ruby/README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ You also can use shorthand for pre-converted models:
6060
whisper = Whisper::Context.new("base.en")
6161
```
6262

63-
You can see the list of prepared model names by `Whisper::Model.preconverted_models.keys`:
63+
You can see the list of prepared model names by `Whisper::Model.pre_converted_models.keys`:
6464

6565
```ruby
66-
puts Whisper::Model.preconverted_models.keys
66+
puts Whisper::Model.pre_converted_models.keys
6767
# tiny
6868
# tiny.en
6969
# tiny-q5_1
@@ -87,8 +87,9 @@ whisper = Whisper::Context.new("path/to/your/model.bin")
8787
Or, you can download model files:
8888

8989
```ruby
90-
model_uri = Whisper::Model::URI.new("http://example.net/uri/of/your/model.bin")
91-
whisper = Whisper::Context.new(model_uri)
90+
whisper = Whisper::Context.new("https://example.net/uri/of/your/model.bin")
91+
# Or
92+
whisper = Whisper::Context.new(URI("https://example.net/uri/of/your/model.bin"))
9293
```
9394

9495
See [models][] page for details.
@@ -222,6 +223,17 @@ end
222223

223224
The second argument `samples` may be an array, an object with `length` and `each` method, or a MemoryView. If you can prepare audio data as C array and export it as a MemoryView, whispercpp accepts and works with it with zero copy.
224225

226+
Development
227+
-----------
228+
229+
% git clone https://github.com/ggerganov/whisper.cpp.git
230+
% cd whisper.cpp/bindings/ruby
231+
% rake test
232+
233+
First call of `rake test` builds an extension and downloads a model for testing. After that, you add tests in `tests` directory and modify `ext/ruby_whisper.cpp`.
234+
235+
If something seems wrong on build, running `rake clean` solves some cases.
236+
225237
License
226238
-------
227239

bindings/ruby/ext/ruby_whisper.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static ID id_length;
4949
static ID id_next;
5050
static ID id_new;
5151
static ID id_to_path;
52+
static ID id_URI;
5253
static ID id_pre_converted_models;
5354

5455
static bool is_log_callback_finalized = false;
@@ -283,6 +284,17 @@ static VALUE ruby_whisper_initialize(int argc, VALUE *argv, VALUE self) {
283284
if (!NIL_P(pre_converted_model)) {
284285
whisper_model_file_path = pre_converted_model;
285286
}
287+
if (TYPE(whisper_model_file_path) == T_STRING) {
288+
const char * whisper_model_file_path_str = StringValueCStr(whisper_model_file_path);
289+
if (strncmp("http://", whisper_model_file_path_str, 7) == 0 || strncmp("https://", whisper_model_file_path_str, 8) == 0) {
290+
VALUE uri_class = rb_const_get(cModel, id_URI);
291+
whisper_model_file_path = rb_class_new_instance(1, &whisper_model_file_path, uri_class);
292+
}
293+
}
294+
if (rb_obj_is_kind_of(whisper_model_file_path, rb_path2class("URI::HTTP"))) {
295+
VALUE uri_class = rb_const_get(cModel, id_URI);
296+
whisper_model_file_path = rb_class_new_instance(1, &whisper_model_file_path, uri_class);
297+
}
286298
if (rb_respond_to(whisper_model_file_path, id_to_path)) {
287299
whisper_model_file_path = rb_funcall(whisper_model_file_path, id_to_path, 0);
288300
}
@@ -837,7 +849,7 @@ static VALUE ruby_whisper_full_get_segment_text(VALUE self, VALUE i_segment) {
837849

838850
/*
839851
* call-seq:
840-
* full_get_segment_no_speech_prob -> Float
852+
* full_get_segment_no_speech_prob(segment_index) -> Float
841853
*/
842854
static VALUE ruby_whisper_full_get_segment_no_speech_prob(VALUE self, VALUE i_segment) {
843855
ruby_whisper *rw;
@@ -1755,7 +1767,7 @@ static VALUE ruby_whisper_c_model_type(VALUE self) {
17551767

17561768
static VALUE ruby_whisper_error_initialize(VALUE self, VALUE code) {
17571769
const int c_code = NUM2INT(code);
1758-
char *raw_message;
1770+
const char *raw_message;
17591771
switch (c_code) {
17601772
case -2:
17611773
raw_message = "failed to compute log mel spectrogram";
@@ -1802,6 +1814,7 @@ void Init_whisper() {
18021814
id_next = rb_intern("next");
18031815
id_new = rb_intern("new");
18041816
id_to_path = rb_intern("to_path");
1817+
id_URI = rb_intern("URI");
18051818
id_pre_converted_models = rb_intern("pre_converted_models");
18061819

18071820
mWhisper = rb_define_module("Whisper");
@@ -1941,6 +1954,8 @@ void Init_whisper() {
19411954
rb_define_method(cModel, "n_mels", ruby_whisper_c_model_n_mels, 0);
19421955
rb_define_method(cModel, "ftype", ruby_whisper_c_model_ftype, 0);
19431956
rb_define_method(cModel, "type", ruby_whisper_c_model_type, 0);
1957+
1958+
rb_require("whisper/model/uri");
19441959
}
19451960
#ifdef __cplusplus
19461961
}

bindings/ruby/ext/ruby_whisper.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __RUBY_WHISPER_H
2-
#define __RUBY_WHISPER_H
1+
#ifndef RUBY_WHISPER_H
2+
#define RUBY_WHISPER_H
33

44
#include "whisper.h"
55

bindings/ruby/lib/whisper.rb

-2
This file was deleted.

0 commit comments

Comments
 (0)