whisper.rn 0.4.0-rc.1 → 0.4.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/android/build.gradle +4 -0
- package/android/src/main/CMakeLists.txt +21 -1
- package/android/src/main/java/com/rnwhisper/AudioUtils.java +27 -92
- package/android/src/main/java/com/rnwhisper/RNWhisper.java +86 -40
- package/android/src/main/java/com/rnwhisper/WhisperContext.java +85 -131
- package/android/src/main/jni-utils.h +76 -0
- package/android/src/main/jni.cpp +226 -109
- package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/android/src/oldarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/cpp/coreml/whisper-encoder-impl.h +1 -1
- package/cpp/coreml/whisper-encoder.h +4 -0
- package/cpp/coreml/whisper-encoder.mm +5 -3
- package/cpp/ggml-alloc.c +797 -400
- package/cpp/ggml-alloc.h +60 -10
- package/cpp/ggml-backend-impl.h +255 -0
- package/cpp/ggml-backend-reg.cpp +582 -0
- package/cpp/ggml-backend.cpp +2002 -0
- package/cpp/ggml-backend.h +354 -0
- package/cpp/ggml-common.h +1851 -0
- package/cpp/ggml-cpp.h +39 -0
- package/cpp/ggml-cpu-aarch64.cpp +4247 -0
- package/cpp/ggml-cpu-aarch64.h +8 -0
- package/cpp/ggml-cpu-impl.h +531 -0
- package/cpp/ggml-cpu-quants.c +12245 -0
- package/cpp/ggml-cpu-quants.h +63 -0
- package/cpp/ggml-cpu-traits.cpp +36 -0
- package/cpp/ggml-cpu-traits.h +38 -0
- package/cpp/ggml-cpu.c +14792 -0
- package/cpp/ggml-cpu.cpp +653 -0
- package/cpp/ggml-cpu.h +137 -0
- package/cpp/ggml-impl.h +567 -0
- package/cpp/ggml-metal-impl.h +288 -0
- package/cpp/ggml-metal.h +24 -43
- package/cpp/ggml-metal.m +4867 -1080
- package/cpp/ggml-opt.cpp +854 -0
- package/cpp/ggml-opt.h +216 -0
- package/cpp/ggml-quants.c +5238 -0
- package/cpp/ggml-quants.h +100 -0
- package/cpp/ggml-threading.cpp +12 -0
- package/cpp/ggml-threading.h +14 -0
- package/cpp/ggml-whisper.metallib +0 -0
- package/cpp/ggml.c +5106 -19431
- package/cpp/ggml.h +847 -669
- package/cpp/gguf.cpp +1329 -0
- package/cpp/gguf.h +202 -0
- package/cpp/rn-audioutils.cpp +68 -0
- package/cpp/rn-audioutils.h +14 -0
- package/cpp/rn-whisper-log.h +11 -0
- package/cpp/rn-whisper.cpp +221 -52
- package/cpp/rn-whisper.h +50 -15
- package/cpp/whisper.cpp +3174 -1533
- package/cpp/whisper.h +176 -44
- package/ios/RNWhisper.mm +139 -46
- package/ios/RNWhisperAudioUtils.h +1 -2
- package/ios/RNWhisperAudioUtils.m +18 -67
- package/ios/RNWhisperContext.h +11 -8
- package/ios/RNWhisperContext.mm +195 -150
- package/jest/mock.js +15 -2
- package/lib/commonjs/NativeRNWhisper.js.map +1 -1
- package/lib/commonjs/index.js +76 -28
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/NativeRNWhisper.js.map +1 -1
- package/lib/module/index.js +76 -28
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/NativeRNWhisper.d.ts +13 -4
- package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +37 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +9 -7
- package/src/NativeRNWhisper.ts +20 -4
- package/src/index.ts +98 -42
- package/src/version.json +1 -1
- package/whisper-rn.podspec +13 -20
- package/cpp/README.md +0 -4
- package/cpp/ggml-metal.metal +0 -2353
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#ifndef WSP_GGML_METAL_IMPL
|
|
2
|
+
#define WSP_GGML_METAL_IMPL
|
|
3
|
+
|
|
4
|
+
// kernel argument structs
|
|
5
|
+
//
|
|
6
|
+
// - element counters (e.g. ne00) typically use int32_t to reduce register usage
|
|
7
|
+
// however, be careful from int overflows when using those in the kernel implementation
|
|
8
|
+
//
|
|
9
|
+
// - strides (e.g. nb00) use uint64_t
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
int32_t ne00;
|
|
13
|
+
int32_t ne01;
|
|
14
|
+
int32_t ne02;
|
|
15
|
+
int32_t ne03;
|
|
16
|
+
uint64_t nb00;
|
|
17
|
+
uint64_t nb01;
|
|
18
|
+
uint64_t nb02;
|
|
19
|
+
uint64_t nb03;
|
|
20
|
+
int32_t ne10;
|
|
21
|
+
int32_t ne11;
|
|
22
|
+
int32_t ne12;
|
|
23
|
+
int32_t ne13;
|
|
24
|
+
uint64_t nb10;
|
|
25
|
+
uint64_t nb11;
|
|
26
|
+
uint64_t nb12;
|
|
27
|
+
uint64_t nb13;
|
|
28
|
+
int32_t ne0;
|
|
29
|
+
int32_t ne1;
|
|
30
|
+
int32_t ne2;
|
|
31
|
+
int32_t ne3;
|
|
32
|
+
uint64_t nb0;
|
|
33
|
+
uint64_t nb1;
|
|
34
|
+
uint64_t nb2;
|
|
35
|
+
uint64_t nb3;
|
|
36
|
+
int32_t dim;
|
|
37
|
+
} wsp_ggml_metal_kargs_concat;
|
|
38
|
+
|
|
39
|
+
typedef struct {
|
|
40
|
+
int32_t ne00;
|
|
41
|
+
int32_t ne01;
|
|
42
|
+
int32_t ne02;
|
|
43
|
+
int32_t ne03;
|
|
44
|
+
uint64_t nb00;
|
|
45
|
+
uint64_t nb01;
|
|
46
|
+
uint64_t nb02;
|
|
47
|
+
uint64_t nb03;
|
|
48
|
+
int32_t ne10;
|
|
49
|
+
int32_t ne11;
|
|
50
|
+
int32_t ne12;
|
|
51
|
+
int32_t ne13;
|
|
52
|
+
uint64_t nb10;
|
|
53
|
+
uint64_t nb11;
|
|
54
|
+
uint64_t nb12;
|
|
55
|
+
uint64_t nb13;
|
|
56
|
+
int32_t ne0;
|
|
57
|
+
int32_t ne1;
|
|
58
|
+
int32_t ne2;
|
|
59
|
+
int32_t ne3;
|
|
60
|
+
uint64_t nb0;
|
|
61
|
+
uint64_t nb1;
|
|
62
|
+
uint64_t nb2;
|
|
63
|
+
uint64_t nb3;
|
|
64
|
+
uint64_t offs;
|
|
65
|
+
} wsp_ggml_metal_kargs_bin;
|
|
66
|
+
|
|
67
|
+
typedef struct {
|
|
68
|
+
int32_t ne00;
|
|
69
|
+
int32_t ne01;
|
|
70
|
+
int32_t ne02;
|
|
71
|
+
int32_t ne03;
|
|
72
|
+
uint64_t nb00;
|
|
73
|
+
uint64_t nb01;
|
|
74
|
+
uint64_t nb02;
|
|
75
|
+
uint64_t nb03;
|
|
76
|
+
int32_t ne0;
|
|
77
|
+
int32_t ne1;
|
|
78
|
+
int32_t ne2;
|
|
79
|
+
int32_t ne3;
|
|
80
|
+
uint64_t nb0;
|
|
81
|
+
uint64_t nb1;
|
|
82
|
+
uint64_t nb2;
|
|
83
|
+
uint64_t nb3;
|
|
84
|
+
} wsp_ggml_metal_kargs_repeat;
|
|
85
|
+
|
|
86
|
+
typedef struct {
|
|
87
|
+
int64_t ne00;
|
|
88
|
+
int64_t ne01;
|
|
89
|
+
int64_t ne02;
|
|
90
|
+
int64_t ne03;
|
|
91
|
+
uint64_t nb00;
|
|
92
|
+
uint64_t nb01;
|
|
93
|
+
uint64_t nb02;
|
|
94
|
+
uint64_t nb03;
|
|
95
|
+
int64_t ne0;
|
|
96
|
+
int64_t ne1;
|
|
97
|
+
int64_t ne2;
|
|
98
|
+
int64_t ne3;
|
|
99
|
+
uint64_t nb0;
|
|
100
|
+
uint64_t nb1;
|
|
101
|
+
uint64_t nb2;
|
|
102
|
+
uint64_t nb3;
|
|
103
|
+
} wsp_ggml_metal_kargs_cpy;
|
|
104
|
+
|
|
105
|
+
typedef struct {
|
|
106
|
+
int64_t ne10;
|
|
107
|
+
int64_t ne11;
|
|
108
|
+
int64_t ne12;
|
|
109
|
+
uint64_t nb10;
|
|
110
|
+
uint64_t nb11;
|
|
111
|
+
uint64_t nb12;
|
|
112
|
+
uint64_t nb13;
|
|
113
|
+
uint64_t nb1;
|
|
114
|
+
uint64_t nb2;
|
|
115
|
+
uint64_t nb3;
|
|
116
|
+
uint64_t offs;
|
|
117
|
+
bool inplace;
|
|
118
|
+
} wsp_ggml_metal_kargs_set;
|
|
119
|
+
|
|
120
|
+
typedef struct {
|
|
121
|
+
int32_t ne00;
|
|
122
|
+
int32_t ne01;
|
|
123
|
+
int32_t ne02;
|
|
124
|
+
int32_t ne03;
|
|
125
|
+
uint64_t nb00;
|
|
126
|
+
uint64_t nb01;
|
|
127
|
+
uint64_t nb02;
|
|
128
|
+
uint64_t nb03;
|
|
129
|
+
int32_t ne0;
|
|
130
|
+
int32_t ne1;
|
|
131
|
+
int32_t ne2;
|
|
132
|
+
int32_t ne3;
|
|
133
|
+
uint64_t nb0;
|
|
134
|
+
uint64_t nb1;
|
|
135
|
+
uint64_t nb2;
|
|
136
|
+
uint64_t nb3;
|
|
137
|
+
int32_t n_past;
|
|
138
|
+
int32_t n_dims;
|
|
139
|
+
int32_t n_ctx_orig;
|
|
140
|
+
float freq_base;
|
|
141
|
+
float freq_scale;
|
|
142
|
+
float ext_factor;
|
|
143
|
+
float attn_factor;
|
|
144
|
+
float beta_fast;
|
|
145
|
+
float beta_slow;
|
|
146
|
+
} wsp_ggml_metal_kargs_rope;
|
|
147
|
+
|
|
148
|
+
typedef struct {
|
|
149
|
+
int32_t ne01;
|
|
150
|
+
int32_t ne02;
|
|
151
|
+
int32_t ne03;
|
|
152
|
+
uint64_t nb01;
|
|
153
|
+
uint64_t nb02;
|
|
154
|
+
uint64_t nb03;
|
|
155
|
+
int32_t ne11;
|
|
156
|
+
int32_t ne_12_2; // assume K and V are same shape
|
|
157
|
+
int32_t ne_12_3;
|
|
158
|
+
uint64_t nb_12_1;
|
|
159
|
+
uint64_t nb_12_2;
|
|
160
|
+
uint64_t nb_12_3;
|
|
161
|
+
uint64_t nb31;
|
|
162
|
+
int32_t ne1;
|
|
163
|
+
int32_t ne2;
|
|
164
|
+
float scale;
|
|
165
|
+
float max_bias;
|
|
166
|
+
float m0;
|
|
167
|
+
float m1;
|
|
168
|
+
uint16_t n_head_log2;
|
|
169
|
+
float logit_softcap;
|
|
170
|
+
} wsp_ggml_metal_kargs_flash_attn_ext;
|
|
171
|
+
|
|
172
|
+
typedef struct {
|
|
173
|
+
int32_t ne00;
|
|
174
|
+
int32_t ne02;
|
|
175
|
+
uint64_t nb01;
|
|
176
|
+
uint64_t nb02;
|
|
177
|
+
uint64_t nb03;
|
|
178
|
+
int32_t ne12;
|
|
179
|
+
uint64_t nb10;
|
|
180
|
+
uint64_t nb11;
|
|
181
|
+
uint64_t nb12;
|
|
182
|
+
uint64_t nb13;
|
|
183
|
+
int32_t ne0;
|
|
184
|
+
int32_t ne1;
|
|
185
|
+
int16_t r2;
|
|
186
|
+
int16_t r3;
|
|
187
|
+
} wsp_ggml_metal_kargs_mul_mm;
|
|
188
|
+
|
|
189
|
+
typedef struct {
|
|
190
|
+
int32_t ne00;
|
|
191
|
+
int32_t ne01;
|
|
192
|
+
int32_t ne02;
|
|
193
|
+
uint64_t nb00;
|
|
194
|
+
uint64_t nb01;
|
|
195
|
+
uint64_t nb02;
|
|
196
|
+
uint64_t nb03;
|
|
197
|
+
int32_t ne10;
|
|
198
|
+
int32_t ne11;
|
|
199
|
+
int32_t ne12;
|
|
200
|
+
uint64_t nb10;
|
|
201
|
+
uint64_t nb11;
|
|
202
|
+
uint64_t nb12;
|
|
203
|
+
uint64_t nb13;
|
|
204
|
+
int32_t ne0;
|
|
205
|
+
int32_t ne1;
|
|
206
|
+
int16_t r2;
|
|
207
|
+
int16_t r3;
|
|
208
|
+
} wsp_ggml_metal_kargs_mul_mv;
|
|
209
|
+
|
|
210
|
+
typedef struct {
|
|
211
|
+
int32_t ne00;
|
|
212
|
+
int32_t ne01;
|
|
213
|
+
int32_t ne02;
|
|
214
|
+
uint64_t nb00;
|
|
215
|
+
uint64_t nb01;
|
|
216
|
+
uint64_t nb02;
|
|
217
|
+
uint64_t nb03;
|
|
218
|
+
int32_t ne10;
|
|
219
|
+
int32_t ne11;
|
|
220
|
+
int32_t ne12;
|
|
221
|
+
uint64_t nb10;
|
|
222
|
+
uint64_t nb11;
|
|
223
|
+
uint64_t nb12;
|
|
224
|
+
uint64_t nb13;
|
|
225
|
+
int32_t ne0;
|
|
226
|
+
int32_t ne1;
|
|
227
|
+
int16_t r2;
|
|
228
|
+
int16_t r3;
|
|
229
|
+
int16_t nsg;
|
|
230
|
+
int16_t nxpsg;
|
|
231
|
+
int16_t r1ptg;
|
|
232
|
+
} wsp_ggml_metal_kargs_mul_mv_ext;
|
|
233
|
+
|
|
234
|
+
typedef struct {
|
|
235
|
+
int32_t nei0;
|
|
236
|
+
int32_t nei1;
|
|
237
|
+
uint64_t nbi1;
|
|
238
|
+
int32_t ne00;
|
|
239
|
+
int32_t ne02;
|
|
240
|
+
uint64_t nb01;
|
|
241
|
+
uint64_t nb02;
|
|
242
|
+
int32_t ne11;
|
|
243
|
+
int32_t ne12;
|
|
244
|
+
int32_t ne13;
|
|
245
|
+
uint64_t nb10;
|
|
246
|
+
uint64_t nb11;
|
|
247
|
+
uint64_t nb12;
|
|
248
|
+
int32_t ne0;
|
|
249
|
+
int32_t ne1;
|
|
250
|
+
} wsp_ggml_metal_kargs_mul_mm_id;
|
|
251
|
+
|
|
252
|
+
typedef struct {
|
|
253
|
+
int32_t nei0;
|
|
254
|
+
int32_t nei1;
|
|
255
|
+
uint64_t nbi1;
|
|
256
|
+
int32_t ne00;
|
|
257
|
+
int32_t ne01;
|
|
258
|
+
int32_t ne02;
|
|
259
|
+
uint64_t nb00;
|
|
260
|
+
uint64_t nb01;
|
|
261
|
+
uint64_t nb02;
|
|
262
|
+
int32_t ne10;
|
|
263
|
+
int32_t ne11;
|
|
264
|
+
int32_t ne12;
|
|
265
|
+
int32_t ne13;
|
|
266
|
+
uint64_t nb10;
|
|
267
|
+
uint64_t nb11;
|
|
268
|
+
uint64_t nb12;
|
|
269
|
+
int32_t ne0;
|
|
270
|
+
int32_t ne1;
|
|
271
|
+
uint64_t nb1;
|
|
272
|
+
} wsp_ggml_metal_kargs_mul_mv_id;
|
|
273
|
+
|
|
274
|
+
typedef struct {
|
|
275
|
+
int32_t ne00;
|
|
276
|
+
int32_t ne00_4;
|
|
277
|
+
uint64_t nb01;
|
|
278
|
+
float eps;
|
|
279
|
+
} wsp_ggml_metal_kargs_norm;
|
|
280
|
+
|
|
281
|
+
typedef struct {
|
|
282
|
+
int32_t ne00;
|
|
283
|
+
int32_t ne00_4;
|
|
284
|
+
uint64_t nb01;
|
|
285
|
+
float eps;
|
|
286
|
+
} wsp_ggml_metal_kargs_rms_norm;
|
|
287
|
+
|
|
288
|
+
#endif // WSP_GGML_METAL_IMPL
|
package/cpp/ggml-metal.h
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
// Note: this description is outdated
|
|
2
|
+
//
|
|
1
3
|
// An interface allowing to compute wsp_ggml_cgraph with Metal
|
|
2
4
|
//
|
|
3
5
|
// This is a fully functional interface that extends ggml with GPU support for Apple devices.
|
|
4
|
-
// A similar interface can be created for other GPU backends (e.g. Vulkan, CUDA,
|
|
6
|
+
// A similar interface can be created for other GPU backends (e.g. Vulkan, CUDA, etc.)
|
|
5
7
|
//
|
|
6
8
|
// How it works?
|
|
7
9
|
//
|
|
@@ -19,13 +21,12 @@
|
|
|
19
21
|
|
|
20
22
|
#pragma once
|
|
21
23
|
|
|
24
|
+
#include "ggml.h"
|
|
25
|
+
#include "ggml-backend.h"
|
|
26
|
+
|
|
22
27
|
#include <stddef.h>
|
|
23
28
|
#include <stdbool.h>
|
|
24
29
|
|
|
25
|
-
// max memory buffers that can be mapped to the device
|
|
26
|
-
#define WSP_GGML_METAL_MAX_BUFFERS 16
|
|
27
|
-
#define WSP_GGML_METAL_MAX_COMMAND_BUFFERS 32
|
|
28
|
-
|
|
29
30
|
struct wsp_ggml_tensor;
|
|
30
31
|
struct wsp_ggml_cgraph;
|
|
31
32
|
|
|
@@ -33,53 +34,33 @@ struct wsp_ggml_cgraph;
|
|
|
33
34
|
extern "C" {
|
|
34
35
|
#endif
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
void wsp_ggml_metal_free(struct wsp_ggml_metal_context * ctx);
|
|
41
|
-
|
|
42
|
-
void * wsp_ggml_metal_host_malloc(size_t n);
|
|
43
|
-
void wsp_ggml_metal_host_free (void * data);
|
|
37
|
+
//
|
|
38
|
+
// backend API
|
|
39
|
+
// user-code should use only these functions
|
|
40
|
+
//
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
void wsp_ggml_metal_set_n_cb(struct wsp_ggml_metal_context * ctx, int n_cb);
|
|
42
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_t wsp_ggml_backend_metal_init(void);
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
// - make sure to map all buffers used in the graph before calling wsp_ggml_metal_graph_compute
|
|
50
|
-
// - the mapping is used during computation to determine the arguments of the compute kernels
|
|
51
|
-
// - you don't need to keep the host memory buffer allocated as it is never accessed by Metal
|
|
52
|
-
// - max_size specifies the maximum size of a tensor and is used to create shared views such
|
|
53
|
-
// that it is guaranteed that the tensor will fit in at least one of the views
|
|
54
|
-
//
|
|
55
|
-
bool wsp_ggml_metal_add_buffer(
|
|
56
|
-
struct wsp_ggml_metal_context * ctx,
|
|
57
|
-
const char * name,
|
|
58
|
-
void * data,
|
|
59
|
-
size_t size,
|
|
60
|
-
size_t max_size);
|
|
44
|
+
WSP_GGML_BACKEND_API bool wsp_ggml_backend_is_metal(wsp_ggml_backend_t backend);
|
|
61
45
|
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
WSP_GGML_DEPRECATED(
|
|
47
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_buffer_t wsp_ggml_backend_metal_buffer_from_ptr(void * data, size_t size, size_t max_size),
|
|
48
|
+
"obsoleted by the new device interface - https://github.com/ggml-org/llama.cpp/pull/9713");
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
void wsp_ggml_metal_get_tensor(struct wsp_ggml_metal_context * ctx, struct wsp_ggml_tensor * t);
|
|
50
|
+
WSP_GGML_BACKEND_API void wsp_ggml_backend_metal_set_abort_callback(wsp_ggml_backend_t backend, wsp_ggml_abort_callback abort_callback, void * user_data);
|
|
67
51
|
|
|
68
|
-
|
|
69
|
-
// you should run it again if the topology of your graph changes
|
|
70
|
-
void wsp_ggml_metal_graph_find_concurrency(struct wsp_ggml_metal_context * ctx, struct wsp_ggml_cgraph * gf, bool check_mem);
|
|
52
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_buffer_type_t wsp_ggml_backend_metal_buffer_type(void);
|
|
71
53
|
|
|
72
|
-
//
|
|
73
|
-
|
|
54
|
+
// helper to check if the device supports a specific family
|
|
55
|
+
// ideally, the user code should be doing these checks
|
|
56
|
+
// ref: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
|
|
57
|
+
WSP_GGML_BACKEND_API bool wsp_ggml_backend_metal_supports_family(wsp_ggml_backend_t backend, int family);
|
|
74
58
|
|
|
75
|
-
//
|
|
76
|
-
|
|
59
|
+
// capture all command buffers committed the next time `wsp_ggml_backend_graph_compute` is called
|
|
60
|
+
WSP_GGML_BACKEND_API void wsp_ggml_backend_metal_capture_next_compute(wsp_ggml_backend_t backend);
|
|
77
61
|
|
|
78
|
-
|
|
79
|
-
// creates gf->n_threads command buffers in parallel
|
|
80
|
-
void wsp_ggml_metal_graph_compute(struct wsp_ggml_metal_context * ctx, struct wsp_ggml_cgraph * gf);
|
|
62
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_reg_t wsp_ggml_backend_metal_reg(void);
|
|
81
63
|
|
|
82
64
|
#ifdef __cplusplus
|
|
83
65
|
}
|
|
84
66
|
#endif
|
|
85
|
-
|