Skip to content

Commit f888c23

Browse files
committed
Flash + language support (ref #2)
- Achieved big performance improvement + memory usage reduction - Can now translate / transcribe different languages
1 parent 154fa79 commit f888c23

File tree

6 files changed

+1277
-138
lines changed

6 files changed

+1277
-138
lines changed

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ samples:
3030
# runs it on all samples in the folder "./samples":
3131

3232
.PHONY: tiny.en
33+
.PHONY: tiny
3334
.PHONY: base.en
34-
.PHONY: medium.en
35+
.PHONY: base
3536
.PHONY: small.en
37+
.PHONY: small
38+
.PHONY: medium.en
39+
.PHONY: medium
40+
.PHONY: large
3641

37-
tiny.en base.en medium.en small.en: main
42+
tiny.en tiny base.en base small.en small medium.en medium large: main
3843
bash ./download-ggml-model.sh $@
3944
@echo ""
4045
@echo "==============================================="

README.md

+51-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ C/C++ port of [OpenAI's Whisper](https://github.com/openai/whisper) speech-to-te
44

55
- Plain C/C++ implementation without dependencies
66
- ARM_NEON and AVX intrinsics support
7-
- F16 support
7+
- Mixed F16 / F32 support
8+
- Low memory usage (Flash Attention + Flash Forward)
89

910
## Usage
1011

@@ -27,9 +28,33 @@ For a quick demo, simply run `make base.en`:
2728
```bash
2829
$ make base.en
2930

30-
Downloading base.en (142 MB just once)
31-
mkdir -p models
32-
models/ggml-base.en.bin 100%[=================================>] 141.11M 7.50MB/s in 19s
31+
gcc -pthread -O3 -mavx -mavx2 -mfma -mf16c -c ggml.c
32+
g++ -pthread -O3 -std=c++11 -c main.cpp
33+
g++ -o main ggml.o main.o
34+
./main -h
35+
36+
usage: ./main [options]
37+
38+
options:
39+
-h, --help show this help message and exit
40+
-s SEED, --seed SEED RNG seed (default: -1)
41+
-t N, --threads N number of threads to use during computation (default: 4)
42+
-T N, --tokens N maximum number of tokens to generate per iteration (default: 64)
43+
-v, --verbose verbose output
44+
--translate translate from source language to english
45+
-ps, --print_special print special tokens
46+
-l LANG, --language LANG spoken language (default: en)
47+
-m FNAME, --model FNAME model path (default: models/ggml-base.en.bin)
48+
-f FNAME, --file FNAME input WAV file path (default: samples/jfk.wav)
49+
50+
bash ./download-ggml-model.sh base.en
51+
Downloading ggml model base.en ...
52+
models/ggml-base.en.bin 100%[=====================================>] 141.11M 7.84MB/s in 18s
53+
Done! Model 'base.en' saved in 'models/ggml-base.en.bin'
54+
You can now use it like this:
55+
56+
$ ./main -m models/ggml-base.en.bin -f samples/jfk.wav
57+
3358

3459
===============================================
3560
Running base.en on all samples in ./samples ...
@@ -52,23 +77,24 @@ whisper_model_load: n_text_layer = 6
5277
whisper_model_load: n_mels = 80
5378
whisper_model_load: f16 = 1
5479
whisper_model_load: type = 2
55-
whisper_model_load: mem_required = 782.00 MB
80+
whisper_model_load: mem_required = 611.00 MB
5681
whisper_model_load: adding 1607 extra tokens
57-
whisper_model_load: ggml ctx size = 186.26 MB
58-
whisper_model_load: memory size = 45.66 MB
82+
whisper_model_load: ggml ctx size = 163.43 MB
83+
whisper_model_load: memory size = 22.83 MB
5984
whisper_model_load: model size = 140.54 MB
6085
log_mel_spectrogram: n_sample = 176000, n_len = 1100
6186
log_mel_spectrogram: recording length: 11.000000 s
6287

63-
And so my fellow Americans ask not what your country can do for you. Ask what you can do for your country.
88+
main: processing 176000 samples (11.0 sec), 4 threads, lang = english, task = transcribe ...
6489

65-
main: load time = 60.62 ms
66-
main: mel time = 38.69 ms
67-
main: sample time = 2.36 ms
68-
main: encode time = 875.63 ms / 145.94 ms per layer
69-
main: decode time = 103.17 ms
70-
main: total time = 1081.13 ms
90+
And so my fellow Americans ask not what your country can do for you. Ask what you can do for your country.
7191

92+
main: load time = 71.89 ms
93+
main: mel time = 36.95 ms
94+
main: sample time = 2.10 ms
95+
main: encode time = 700.94 ms / 116.82 ms per layer
96+
main: decode time = 86.14 ms
97+
main: total time = 898.72 ms
7298
```
7399

74100
The command downloads the `base.en` model converted to custom `ggml` format and runs the inference on all `.wav` samples in the folder `samples`.
@@ -81,13 +107,18 @@ make samples
81107

82108
This will download a few more audio files from Wikipedia and convert them to 16-bit WAV format via `ffmpeg`.
83109

84-
You can download and run the other `.en` models as follows:
110+
You can download and run the other models as follows:
85111

86112
```
87113
make tiny.en
114+
make tiny
88115
make base.en
116+
make base
89117
make small.en
118+
make small
90119
make medium.en
120+
make medium
121+
make large
91122
```
92123

93124
For detailed usage instructions, run: `./main -h`
@@ -101,10 +132,8 @@ ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav
101132

102133
## Limitations
103134

104-
- Only `.en` models are supported
105135
- Very basic greedy sampling scheme - always pick up the top token
106136
- No timestamps
107-
- English only
108137
- Inference only
109138
- Runs on the CPU
110139
- Only mono-channel 16-bit WAV is supported
@@ -113,10 +142,11 @@ ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav
113142

114143
| Model | Disk | Mem |
115144
| --- | --- | --- |
116-
| tiny.en | 75 MB | ~600 MB |
117-
| base.en | 142 MB | ~800 MB |
118-
| small.en | 466 MB | ~1.6 GB |
119-
| medium.en | 1.5 GB | ~3.5 GB |
145+
| tiny | 75 MB | ~460 MB |
146+
| base | 142 MB | ~620 MB |
147+
| small | 466 MB | ~1.3 GB |
148+
| medium | 1.5 GB | ~2.8 GB |
149+
| large | 2.9 GB | ~4.9 GB |
120150

121151
## ggml format
122152

download-ggml-model.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ggml_path=$(dirname $(realpath $0))
77

88
# Whisper models
9-
models=( "tiny.en" "base.en" "small.en" "medium.en" )
9+
models=( "tiny.en" "tiny" "base.en" "base" "small.en" "small" "medium.en" "medium" "large" )
1010

1111
# list available models
1212
function list_models {

0 commit comments

Comments
 (0)