whisper.rn 0.4.0-rc.3 → 0.4.0-rc.4

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.
Files changed (44) hide show
  1. package/android/src/main/CMakeLists.txt +2 -0
  2. package/android/src/main/java/com/rnwhisper/RNWhisper.java +6 -1
  3. package/android/src/main/java/com/rnwhisper/WhisperContext.java +3 -3
  4. package/android/src/main/jni.cpp +6 -2
  5. package/cpp/ggml-alloc.c +413 -280
  6. package/cpp/ggml-alloc.h +67 -8
  7. package/cpp/ggml-backend-impl.h +87 -0
  8. package/cpp/ggml-backend.c +950 -0
  9. package/cpp/ggml-backend.h +136 -0
  10. package/cpp/ggml-impl.h +243 -0
  11. package/cpp/{ggml-metal.metal → ggml-metal-whisper.metal} +591 -121
  12. package/cpp/ggml-metal.h +21 -0
  13. package/cpp/ggml-metal.m +623 -234
  14. package/cpp/ggml-quants.c +7377 -0
  15. package/cpp/ggml-quants.h +224 -0
  16. package/cpp/ggml.c +3773 -4455
  17. package/cpp/ggml.h +279 -146
  18. package/cpp/whisper.cpp +182 -103
  19. package/cpp/whisper.h +48 -11
  20. package/ios/RNWhisper.mm +8 -2
  21. package/ios/RNWhisper.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  22. package/ios/RNWhisper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  23. package/ios/RNWhisper.xcodeproj/project.xcworkspace/xcuserdata/jhen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  24. package/ios/RNWhisper.xcodeproj/xcuserdata/jhen.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
  25. package/ios/RNWhisperContext.h +5 -1
  26. package/ios/RNWhisperContext.mm +76 -10
  27. package/jest/mock.js +1 -1
  28. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  29. package/lib/commonjs/index.js +28 -9
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/version.json +1 -1
  32. package/lib/module/NativeRNWhisper.js.map +1 -1
  33. package/lib/module/index.js +28 -9
  34. package/lib/module/index.js.map +1 -1
  35. package/lib/module/version.json +1 -1
  36. package/lib/typescript/NativeRNWhisper.d.ts +7 -1
  37. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  38. package/lib/typescript/index.d.ts +7 -2
  39. package/lib/typescript/index.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/src/NativeRNWhisper.ts +8 -1
  42. package/src/index.ts +29 -17
  43. package/src/version.json +1 -1
  44. package/whisper-rn.podspec +1 -2
@@ -0,0 +1,224 @@
1
+ #pragma once
2
+
3
+ #include "ggml-impl.h"
4
+
5
+ // GGML internal header
6
+
7
+ #include <stdint.h>
8
+ #include <stddef.h>
9
+
10
+ #define QK4_0 32
11
+ typedef struct {
12
+ wsp_ggml_fp16_t d; // delta
13
+ uint8_t qs[QK4_0 / 2]; // nibbles / quants
14
+ } block_q4_0;
15
+ static_assert(sizeof(block_q4_0) == sizeof(wsp_ggml_fp16_t) + QK4_0 / 2, "wrong q4_0 block size/padding");
16
+
17
+ #define QK4_1 32
18
+ typedef struct {
19
+ wsp_ggml_fp16_t d; // delta
20
+ wsp_ggml_fp16_t m; // min
21
+ uint8_t qs[QK4_1 / 2]; // nibbles / quants
22
+ } block_q4_1;
23
+ static_assert(sizeof(block_q4_1) == 2 * sizeof(wsp_ggml_fp16_t) + QK4_1 / 2, "wrong q4_1 block size/padding");
24
+
25
+ #define QK5_0 32
26
+ typedef struct {
27
+ wsp_ggml_fp16_t d; // delta
28
+ uint8_t qh[4]; // 5-th bit of quants
29
+ uint8_t qs[QK5_0 / 2]; // nibbles / quants
30
+ } block_q5_0;
31
+ static_assert(sizeof(block_q5_0) == sizeof(wsp_ggml_fp16_t) + sizeof(uint32_t) + QK5_0 / 2, "wrong q5_0 block size/padding");
32
+
33
+ #define QK5_1 32
34
+ typedef struct {
35
+ wsp_ggml_fp16_t d; // delta
36
+ wsp_ggml_fp16_t m; // min
37
+ uint8_t qh[4]; // 5-th bit of quants
38
+ uint8_t qs[QK5_1 / 2]; // nibbles / quants
39
+ } block_q5_1;
40
+ static_assert(sizeof(block_q5_1) == 2 * sizeof(wsp_ggml_fp16_t) + sizeof(uint32_t) + QK5_1 / 2, "wrong q5_1 block size/padding");
41
+
42
+ #define QK8_0 32
43
+ typedef struct {
44
+ wsp_ggml_fp16_t d; // delta
45
+ int8_t qs[QK8_0]; // quants
46
+ } block_q8_0;
47
+ static_assert(sizeof(block_q8_0) == sizeof(wsp_ggml_fp16_t) + QK8_0, "wrong q8_0 block size/padding");
48
+
49
+ #define QK8_1 32
50
+ typedef struct {
51
+ float d; // delta
52
+ float s; // d * sum(qs[i])
53
+ int8_t qs[QK8_1]; // quants
54
+ } block_q8_1;
55
+ static_assert(sizeof(block_q8_1) == 2*sizeof(float) + QK8_1, "wrong q8_1 block size/padding");
56
+
57
+ //
58
+ // Super-block quantization structures
59
+ //
60
+
61
+ // Super-block size
62
+ #ifdef WSP_GGML_QKK_64
63
+ #define QK_K 64
64
+ #define K_SCALE_SIZE 4
65
+ #else
66
+ #define QK_K 256
67
+ #define K_SCALE_SIZE 12
68
+ #endif
69
+
70
+ // 2-bit quantization
71
+ // weight is represented as x = a * q + b
72
+ // 16 blocks of 16 elements each
73
+ // Effectively 2.5625 bits per weight
74
+ typedef struct {
75
+ uint8_t scales[QK_K/16]; // scales and mins, quantized with 4 bits
76
+ uint8_t qs[QK_K/4]; // quants
77
+ wsp_ggml_fp16_t d; // super-block scale for quantized scales
78
+ wsp_ggml_fp16_t dmin; // super-block scale for quantized mins
79
+ } block_q2_K;
80
+ static_assert(sizeof(block_q2_K) == 2*sizeof(wsp_ggml_fp16_t) + QK_K/16 + QK_K/4, "wrong q2_K block size/padding");
81
+
82
+ // 3-bit quantization
83
+ // weight is represented as x = a * q
84
+ // 16 blocks of 16 elements each
85
+ // Effectively 3.4375 bits per weight
86
+ #ifdef WSP_GGML_QKK_64
87
+ typedef struct {
88
+ uint8_t hmask[QK_K/8]; // quants - high bit
89
+ uint8_t qs[QK_K/4]; // quants - low 2 bits
90
+ uint8_t scales[2];
91
+ wsp_ggml_fp16_t d; // super-block scale
92
+ } block_q3_K;
93
+ static_assert(sizeof(block_q3_K) == sizeof(wsp_ggml_fp16_t) + QK_K / 4 + QK_K / 8 + 2, "wrong q3_K block size/padding");
94
+ #else
95
+ typedef struct {
96
+ uint8_t hmask[QK_K/8]; // quants - high bit
97
+ uint8_t qs[QK_K/4]; // quants - low 2 bits
98
+ uint8_t scales[12]; // scales, quantized with 6 bits
99
+ wsp_ggml_fp16_t d; // super-block scale
100
+ } block_q3_K;
101
+ static_assert(sizeof(block_q3_K) == sizeof(wsp_ggml_fp16_t) + QK_K / 4 + QK_K / 8 + 12, "wrong q3_K block size/padding");
102
+ #endif
103
+
104
+ // 4-bit quantization
105
+ // 8 blocks of 32 elements each
106
+ // weight is represented as x = a * q + b
107
+ // Effectively 4.5 bits per weight
108
+ #ifdef WSP_GGML_QKK_64
109
+ typedef struct {
110
+ wsp_ggml_fp16_t d[2]; // super-block scales/mins
111
+ uint8_t scales[2]; // 4-bit block scales/mins
112
+ uint8_t qs[QK_K/2]; // 4--bit quants
113
+ } block_q4_K;
114
+ static_assert(sizeof(block_q4_K) == 2*sizeof(wsp_ggml_fp16_t) + QK_K/2 + 2, "wrong q4_K block size/padding");
115
+ #else
116
+ typedef struct {
117
+ wsp_ggml_fp16_t d; // super-block scale for quantized scales
118
+ wsp_ggml_fp16_t dmin; // super-block scale for quantized mins
119
+ uint8_t scales[K_SCALE_SIZE]; // scales and mins, quantized with 6 bits
120
+ uint8_t qs[QK_K/2]; // 4--bit quants
121
+ } block_q4_K;
122
+ static_assert(sizeof(block_q4_K) == 2*sizeof(wsp_ggml_fp16_t) + K_SCALE_SIZE + QK_K/2, "wrong q4_K block size/padding");
123
+ #endif
124
+
125
+ // 5-bit quantization
126
+ // 8 blocks of 32 elements each
127
+ // weight is represented as x = a * q + b
128
+ // Effectively 5.5 bits per weight
129
+ #ifdef WSP_GGML_QKK_64
130
+ typedef struct {
131
+ wsp_ggml_fp16_t d; // super-block scale
132
+ int8_t scales[QK_K/16]; // 8-bit block scales
133
+ uint8_t qh[QK_K/8]; // quants, high bit
134
+ uint8_t qs[QK_K/2]; // quants, low 4 bits
135
+ } block_q5_K;
136
+ static_assert(sizeof(block_q5_K) == sizeof(wsp_ggml_fp16_t) + QK_K/2 + QK_K/8 + QK_K/16, "wrong q5_K block size/padding");
137
+ #else
138
+ typedef struct {
139
+ wsp_ggml_fp16_t d; // super-block scale for quantized scales
140
+ wsp_ggml_fp16_t dmin; // super-block scale for quantized mins
141
+ uint8_t scales[K_SCALE_SIZE]; // scales and mins, quantized with 6 bits
142
+ uint8_t qh[QK_K/8]; // quants, high bit
143
+ uint8_t qs[QK_K/2]; // quants, low 4 bits
144
+ } block_q5_K;
145
+ static_assert(sizeof(block_q5_K) == 2*sizeof(wsp_ggml_fp16_t) + K_SCALE_SIZE + QK_K/2 + QK_K/8, "wrong q5_K block size/padding");
146
+ #endif
147
+
148
+ // 6-bit quantization
149
+ // weight is represented as x = a * q
150
+ // 16 blocks of 16 elements each
151
+ // Effectively 6.5625 bits per weight
152
+ typedef struct {
153
+ uint8_t ql[QK_K/2]; // quants, lower 4 bits
154
+ uint8_t qh[QK_K/4]; // quants, upper 2 bits
155
+ int8_t scales[QK_K/16]; // scales, quantized with 8 bits
156
+ wsp_ggml_fp16_t d; // super-block scale
157
+ } block_q6_K;
158
+ static_assert(sizeof(block_q6_K) == sizeof(wsp_ggml_fp16_t) + QK_K / 16 + 3*QK_K/4, "wrong q6_K block size/padding");
159
+
160
+ // This is only used for intermediate quantization and dot products
161
+ typedef struct {
162
+ float d; // delta
163
+ int8_t qs[QK_K]; // quants
164
+ int16_t bsums[QK_K/16]; // sum of quants in groups of 16
165
+ } block_q8_K;
166
+ static_assert(sizeof(block_q8_K) == sizeof(float) + QK_K + QK_K/16*sizeof(int16_t), "wrong q8_K block size/padding");
167
+
168
+
169
+ // Quantization
170
+ void quantize_row_q4_0_reference(const float * restrict x, block_q4_0 * restrict y, int k);
171
+ void quantize_row_q4_1_reference(const float * restrict x, block_q4_1 * restrict y, int k);
172
+ void quantize_row_q5_0_reference(const float * restrict x, block_q5_0 * restrict y, int k);
173
+ void quantize_row_q5_1_reference(const float * restrict x, block_q5_1 * restrict y, int k);
174
+ void quantize_row_q8_0_reference(const float * restrict x, block_q8_0 * restrict y, int k);
175
+ void quantize_row_q8_1_reference(const float * restrict x, block_q8_1 * restrict y, int k);
176
+
177
+ void quantize_row_q2_K_reference(const float * restrict x, block_q2_K * restrict y, int k);
178
+ void quantize_row_q3_K_reference(const float * restrict x, block_q3_K * restrict y, int k);
179
+ void quantize_row_q4_K_reference(const float * restrict x, block_q4_K * restrict y, int k);
180
+ void quantize_row_q5_K_reference(const float * restrict x, block_q5_K * restrict y, int k);
181
+ void quantize_row_q6_K_reference(const float * restrict x, block_q6_K * restrict y, int k);
182
+ void quantize_row_q8_K_reference(const float * restrict x, block_q8_K * restrict y, int k);
183
+
184
+ void quantize_row_q4_0(const float * restrict x, void * restrict y, int k);
185
+ void quantize_row_q4_1(const float * restrict x, void * restrict y, int k);
186
+ void quantize_row_q5_0(const float * restrict x, void * restrict y, int k);
187
+ void quantize_row_q5_1(const float * restrict x, void * restrict y, int k);
188
+ void quantize_row_q8_0(const float * restrict x, void * restrict y, int k);
189
+ void quantize_row_q8_1(const float * restrict x, void * restrict y, int k);
190
+
191
+ void quantize_row_q2_K(const float * restrict x, void * restrict y, int k);
192
+ void quantize_row_q3_K(const float * restrict x, void * restrict y, int k);
193
+ void quantize_row_q4_K(const float * restrict x, void * restrict y, int k);
194
+ void quantize_row_q5_K(const float * restrict x, void * restrict y, int k);
195
+ void quantize_row_q6_K(const float * restrict x, void * restrict y, int k);
196
+ void quantize_row_q8_K(const float * restrict x, void * restrict y, int k);
197
+
198
+ // Dequantization
199
+ void dequantize_row_q4_0(const block_q4_0 * restrict x, float * restrict y, int k);
200
+ void dequantize_row_q4_1(const block_q4_1 * restrict x, float * restrict y, int k);
201
+ void dequantize_row_q5_0(const block_q5_0 * restrict x, float * restrict y, int k);
202
+ void dequantize_row_q5_1(const block_q5_1 * restrict x, float * restrict y, int k);
203
+ void dequantize_row_q8_0(const block_q8_0 * restrict x, float * restrict y, int k);
204
+ //void dequantize_row_q8_1(const block_q8_1 * restrict x, float * restrict y, int k);
205
+
206
+ void dequantize_row_q2_K(const block_q2_K * restrict x, float * restrict y, int k);
207
+ void dequantize_row_q3_K(const block_q3_K * restrict x, float * restrict y, int k);
208
+ void dequantize_row_q4_K(const block_q4_K * restrict x, float * restrict y, int k);
209
+ void dequantize_row_q5_K(const block_q5_K * restrict x, float * restrict y, int k);
210
+ void dequantize_row_q6_K(const block_q6_K * restrict x, float * restrict y, int k);
211
+ void dequantize_row_q8_K(const block_q8_K * restrict x, float * restrict y, int k);
212
+
213
+ // Dot product
214
+ void wsp_ggml_vec_dot_q4_0_q8_0(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
215
+ void wsp_ggml_vec_dot_q4_1_q8_1(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
216
+ void wsp_ggml_vec_dot_q5_0_q8_0(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
217
+ void wsp_ggml_vec_dot_q5_1_q8_1(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
218
+ void wsp_ggml_vec_dot_q8_0_q8_0(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
219
+
220
+ void wsp_ggml_vec_dot_q2_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
221
+ void wsp_ggml_vec_dot_q3_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
222
+ void wsp_ggml_vec_dot_q4_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
223
+ void wsp_ggml_vec_dot_q5_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
224
+ void wsp_ggml_vec_dot_q6_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);