whisper.rn 0.5.3 → 0.5.5

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 (102) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/com/rnwhisper/WhisperContext.java +5 -0
  3. package/android/src/main/jni.cpp +13 -0
  4. package/cpp/ggml-alloc.c +78 -26
  5. package/cpp/ggml-alloc.h +9 -0
  6. package/cpp/ggml-backend-impl.h +1 -1
  7. package/cpp/ggml-backend-reg.cpp +19 -3
  8. package/cpp/ggml-backend.cpp +72 -20
  9. package/cpp/ggml-backend.h +2 -1
  10. package/cpp/ggml-cpu/arch/arm/cpu-feats.cpp +4 -0
  11. package/cpp/ggml-cpu/arch/arm/repack.cpp +1004 -0
  12. package/cpp/ggml-cpu/arch/x86/repack.cpp +6 -6
  13. package/cpp/ggml-cpu/arch-fallback.h +50 -2
  14. package/cpp/ggml-cpu/ggml-cpu-impl.h +1 -1
  15. package/cpp/ggml-cpu/ggml-cpu.c +139 -58
  16. package/cpp/ggml-cpu/ggml-cpu.cpp +4 -0
  17. package/cpp/ggml-cpu/ops.cpp +170 -18
  18. package/cpp/ggml-cpu/ops.h +1 -0
  19. package/cpp/ggml-cpu/repack.cpp +531 -5
  20. package/cpp/ggml-cpu/repack.h +14 -0
  21. package/cpp/ggml-cpu/simd-mappings.h +16 -18
  22. package/cpp/ggml-cpu/vec.cpp +41 -1
  23. package/cpp/ggml-cpu/vec.h +241 -138
  24. package/cpp/ggml-cpu.h +1 -0
  25. package/cpp/ggml-impl.h +0 -4
  26. package/cpp/ggml-metal/ggml-metal-context.m +26 -16
  27. package/cpp/ggml-metal/ggml-metal-device.cpp +452 -371
  28. package/cpp/ggml-metal/ggml-metal-device.h +87 -65
  29. package/cpp/ggml-metal/ggml-metal-device.m +263 -104
  30. package/cpp/ggml-metal/ggml-metal-impl.h +58 -4
  31. package/cpp/ggml-metal/ggml-metal-ops.cpp +415 -98
  32. package/cpp/ggml-metal/ggml-metal-ops.h +4 -0
  33. package/cpp/ggml-metal/ggml-metal.cpp +6 -5
  34. package/cpp/ggml-metal/ggml-metal.metal +404 -34
  35. package/cpp/ggml.c +110 -31
  36. package/cpp/ggml.h +51 -12
  37. package/cpp/jsi/RNWhisperJSI.cpp +1 -0
  38. package/cpp/whisper.cpp +17 -4
  39. package/ios/CMakeLists.txt +21 -1
  40. package/ios/RNWhisperContext.mm +5 -0
  41. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  42. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  43. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  44. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  45. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  46. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +51 -12
  47. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Info.plist +0 -0
  48. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/ggml-metal.metal +404 -34
  49. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/rnwhisper +0 -0
  50. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  51. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  52. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  53. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  54. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  55. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +51 -12
  56. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  57. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +1 -1
  58. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/ggml-metal.metal +404 -34
  59. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  60. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  61. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  62. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  63. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  64. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  65. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +51 -12
  66. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Info.plist +0 -0
  67. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/ggml-metal.metal +404 -34
  68. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/rnwhisper +0 -0
  69. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  70. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  71. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  72. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  73. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  74. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +51 -12
  75. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  76. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +1 -1
  77. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/ggml-metal.metal +404 -34
  78. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  79. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  80. package/lib/commonjs/jest-mock.js +2 -0
  81. package/lib/commonjs/jest-mock.js.map +1 -1
  82. package/lib/commonjs/realtime-transcription/RealtimeTranscriber.js +156 -12
  83. package/lib/commonjs/realtime-transcription/RealtimeTranscriber.js.map +1 -1
  84. package/lib/commonjs/version.json +1 -1
  85. package/lib/module/NativeRNWhisper.js.map +1 -1
  86. package/lib/module/jest-mock.js +2 -0
  87. package/lib/module/jest-mock.js.map +1 -1
  88. package/lib/module/realtime-transcription/RealtimeTranscriber.js +155 -12
  89. package/lib/module/realtime-transcription/RealtimeTranscriber.js.map +1 -1
  90. package/lib/module/version.json +1 -1
  91. package/lib/typescript/NativeRNWhisper.d.ts +1 -0
  92. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  93. package/lib/typescript/realtime-transcription/RealtimeTranscriber.d.ts +29 -0
  94. package/lib/typescript/realtime-transcription/RealtimeTranscriber.d.ts.map +1 -1
  95. package/lib/typescript/realtime-transcription/types.d.ts +7 -0
  96. package/lib/typescript/realtime-transcription/types.d.ts.map +1 -1
  97. package/package.json +1 -1
  98. package/src/NativeRNWhisper.ts +1 -0
  99. package/src/jest-mock.ts +2 -0
  100. package/src/realtime-transcription/RealtimeTranscriber.ts +179 -9
  101. package/src/realtime-transcription/types.ts +9 -0
  102. package/src/version.json +1 -1
@@ -53,7 +53,14 @@ WSP_GGML_API void wsp_ggml_gallocr_free(wsp_ggml_gallocr_t galloc);
53
53
  // call with a worst-case graph to avoid buffer reallocations
54
54
  // not strictly required for single buffer usage: wsp_ggml_gallocr_alloc_graph will reallocate the buffers automatically if needed
55
55
  // returns false if the buffer allocation failed
56
+ // wsp_ggml_gallocr_resrve_n_size writes the buffer sizes per galloc buffer that would be allocated by wsp_ggml_gallocr_reserve_n to sizes
56
57
  WSP_GGML_API bool wsp_ggml_gallocr_reserve(wsp_ggml_gallocr_t galloc, struct wsp_ggml_cgraph * graph);
58
+ WSP_GGML_API void wsp_ggml_gallocr_reserve_n_size(
59
+ wsp_ggml_gallocr_t galloc,
60
+ struct wsp_ggml_cgraph * graph,
61
+ const int * node_buffer_ids,
62
+ const int * leaf_buffer_ids,
63
+ size_t * sizes);
57
64
  WSP_GGML_API bool wsp_ggml_gallocr_reserve_n(
58
65
  wsp_ggml_gallocr_t galloc,
59
66
  struct wsp_ggml_cgraph * graph,
@@ -68,6 +75,8 @@ WSP_GGML_API size_t wsp_ggml_gallocr_get_buffer_size(wsp_ggml_gallocr_t galloc,
68
75
 
69
76
  // Utils
70
77
  // Create a buffer and allocate all the tensors in a wsp_ggml_context
78
+ // wsp_ggml_backend_alloc_ctx_tensors_from_buft_size returns the size of the buffer that would be allocated by wsp_ggml_backend_alloc_ctx_tensors_from_buft
79
+ WSP_GGML_API size_t wsp_ggml_backend_alloc_ctx_tensors_from_buft_size(struct wsp_ggml_context * ctx, wsp_ggml_backend_buffer_type_t buft);
71
80
  WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_backend_alloc_ctx_tensors_from_buft(struct wsp_ggml_context * ctx, wsp_ggml_backend_buffer_type_t buft);
72
81
  WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_backend_alloc_ctx_tensors(struct wsp_ggml_context * ctx, wsp_ggml_backend_t backend);
73
82
 
@@ -144,7 +144,7 @@ extern "C" {
144
144
  // device description: short informative description of the device, could be the model name
145
145
  const char * (*get_description)(wsp_ggml_backend_dev_t dev);
146
146
 
147
- // device memory in bytes
147
+ // device memory in bytes: 0 bytes to indicate no memory to report
148
148
  void (*get_memory)(wsp_ggml_backend_dev_t dev, size_t * free, size_t * total);
149
149
 
150
150
  // device type
@@ -307,6 +307,7 @@ extern "C" {
307
307
  WSP_GGML_API void wsp_ggml_backend_sched_free(wsp_ggml_backend_sched_t sched);
308
308
 
309
309
  // Initialize backend buffers from a measure graph
310
+ WSP_GGML_API void wsp_ggml_backend_sched_reserve_size(wsp_ggml_backend_sched_t sched, struct wsp_ggml_cgraph * measure_graph, size_t * sizes);
310
311
  WSP_GGML_API bool wsp_ggml_backend_sched_reserve(wsp_ggml_backend_sched_t sched, struct wsp_ggml_cgraph * measure_graph); // returns success
311
312
 
312
313
  WSP_GGML_API int wsp_ggml_backend_sched_get_n_backends(wsp_ggml_backend_sched_t sched);
@@ -357,7 +358,7 @@ extern "C" {
357
358
  typedef bool (*wsp_ggml_backend_eval_callback)(int node_index, struct wsp_ggml_tensor * t1, struct wsp_ggml_tensor * t2, void * user_data);
358
359
 
359
360
  // Compare the output of two backends
360
- WSP_GGML_API bool wsp_ggml_backend_compare_graph_backend(wsp_ggml_backend_t backend1, wsp_ggml_backend_t backend2, struct wsp_ggml_cgraph * graph, wsp_ggml_backend_eval_callback callback, void * user_data, struct wsp_ggml_tensor * test_node);
361
+ WSP_GGML_API bool wsp_ggml_backend_compare_graph_backend(wsp_ggml_backend_t backend1, wsp_ggml_backend_t backend2, struct wsp_ggml_cgraph * graph, wsp_ggml_backend_eval_callback callback, void * user_data, struct wsp_ggml_tensor const * const * test_nodes, size_t num_test_nodes);
361
362
 
362
363
  // Tensor initialization
363
364
  WSP_GGML_API enum wsp_ggml_status wsp_ggml_backend_tensor_alloc(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor, void * addr);
@@ -99,6 +99,7 @@ extern "C" {
99
99
  WSP_GGML_BACKEND_API int wsp_ggml_cpu_has_sme (void);
100
100
  // other
101
101
  WSP_GGML_BACKEND_API int wsp_ggml_cpu_has_riscv_v (void);
102
+ WSP_GGML_BACKEND_API int wsp_ggml_cpu_get_rvv_vlen (void); // risc-v vector length in bytes
102
103
  WSP_GGML_BACKEND_API int wsp_ggml_cpu_has_vsx (void);
103
104
  WSP_GGML_BACKEND_API int wsp_ggml_cpu_has_vxe (void);
104
105
  WSP_GGML_BACKEND_API int wsp_ggml_cpu_has_wasm_simd (void);
@@ -24,10 +24,6 @@
24
24
  #include <arm_neon.h>
25
25
  #endif
26
26
 
27
- #if defined(__F16C__)
28
- #include <immintrin.h>
29
- #endif
30
-
31
27
  #ifdef __cplusplus
32
28
  extern "C" {
33
29
  #endif
@@ -204,6 +204,10 @@
204
204
  # define WSP_GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
205
205
  #endif
206
206
 
207
+ #if defined(_WIN32) && !defined(_WIN32_WINNT)
208
+ # define _WIN32_WINNT 0x0A00
209
+ #endif
210
+
207
211
  #include <stdbool.h>
208
212
  #include <stddef.h>
209
213
  #include <stdint.h>
@@ -230,6 +234,11 @@
230
234
 
231
235
  #if UINTPTR_MAX == 0xFFFFFFFF
232
236
  #define WSP_GGML_MEM_ALIGN 4
237
+ #elif defined(__EMSCRIPTEN__)
238
+ // emscripten uses max_align_t == 8, so we need WSP_GGML_MEM_ALIGN == 8 for 64-bit wasm.
239
+ // (for 32-bit wasm, the first conditional is true and WSP_GGML_MEM_ALIGN stays 4.)
240
+ // ref: https://github.com/ggml-org/llama.cpp/pull/18628
241
+ #define WSP_GGML_MEM_ALIGN 8
233
242
  #else
234
243
  #define WSP_GGML_MEM_ALIGN 16
235
244
  #endif
@@ -530,6 +539,7 @@ extern "C" {
530
539
  WSP_GGML_OP_ARANGE,
531
540
  WSP_GGML_OP_TIMESTEP_EMBEDDING,
532
541
  WSP_GGML_OP_ARGSORT,
542
+ WSP_GGML_OP_TOP_K,
533
543
  WSP_GGML_OP_LEAKY_RELU,
534
544
  WSP_GGML_OP_TRI,
535
545
  WSP_GGML_OP_FILL,
@@ -2147,7 +2157,8 @@ extern "C" {
2147
2157
  };
2148
2158
 
2149
2159
  enum wsp_ggml_scale_flag {
2150
- WSP_GGML_SCALE_FLAG_ALIGN_CORNERS = (1 << 8)
2160
+ WSP_GGML_SCALE_FLAG_ALIGN_CORNERS = (1 << 8),
2161
+ WSP_GGML_SCALE_FLAG_ANTIALIAS = (1 << 9),
2151
2162
  };
2152
2163
 
2153
2164
  // interpolate
@@ -2190,6 +2201,15 @@ extern "C" {
2190
2201
  int p2,
2191
2202
  int p3);
2192
2203
 
2204
+ // pad each dimension with values on the other side of the torus (looping around)
2205
+ WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_pad_circular(
2206
+ struct wsp_ggml_context * ctx,
2207
+ struct wsp_ggml_tensor * a,
2208
+ int p0,
2209
+ int p1,
2210
+ int p2,
2211
+ int p3);
2212
+
2193
2213
  WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_pad_ext(
2194
2214
  struct wsp_ggml_context * ctx,
2195
2215
  struct wsp_ggml_tensor * a,
@@ -2203,6 +2223,19 @@ extern "C" {
2203
2223
  int rp3
2204
2224
  );
2205
2225
 
2226
+ // pad each dimension with values on the other side of the torus (looping around)
2227
+ WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_pad_ext_circular(
2228
+ struct wsp_ggml_context * ctx,
2229
+ struct wsp_ggml_tensor * a,
2230
+ int lp0,
2231
+ int rp0,
2232
+ int lp1,
2233
+ int rp1,
2234
+ int lp2,
2235
+ int rp2,
2236
+ int lp3,
2237
+ int rp3);
2238
+
2206
2239
  // pad each dimension with reflection: [a, b, c, d] -> [b, a, b, c, d, c]
2207
2240
  WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_pad_reflect_1d(
2208
2241
  struct wsp_ggml_context * ctx,
@@ -2258,25 +2291,30 @@ extern "C" {
2258
2291
  struct wsp_ggml_tensor * a,
2259
2292
  enum wsp_ggml_sort_order order);
2260
2293
 
2261
- WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_arange(
2294
+ // similar to wsp_ggml_top_k but implemented as `argsort` + `view`
2295
+ WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_argsort_top_k(
2262
2296
  struct wsp_ggml_context * ctx,
2263
- float start,
2264
- float stop,
2265
- float step);
2297
+ struct wsp_ggml_tensor * a,
2298
+ int k);
2266
2299
 
2267
2300
  // top k elements per row
2301
+ // note: the resulting top k indices are in no particular order
2268
2302
  WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_top_k(
2269
2303
  struct wsp_ggml_context * ctx,
2270
2304
  struct wsp_ggml_tensor * a,
2271
2305
  int k);
2272
2306
 
2273
- #define WSP_GGML_KQ_MASK_PAD 64
2307
+ WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_arange(
2308
+ struct wsp_ggml_context * ctx,
2309
+ float start,
2310
+ float stop,
2311
+ float step);
2274
2312
 
2275
- // q: [n_embd_k, n_batch, n_head, ne3 ]
2276
- // k: [n_embd_k, n_kv, n_head_kv, ne3 ]
2277
- // v: [n_embd_v, n_kv, n_head_kv, ne3 ] !! not transposed !!
2278
- // mask: [n_kv, n_batch_pad, ne32, ne33] !! n_batch_pad = WSP_GGML_PAD(n_batch, WSP_GGML_KQ_MASK_PAD) !!
2279
- // res: [n_embd_v, n_head, n_batch, ne3 ] !! permuted !!
2313
+ // q: [n_embd_k, n_batch, n_head, ne3 ]
2314
+ // k: [n_embd_k, n_kv, n_head_kv, ne3 ]
2315
+ // v: [n_embd_v, n_kv, n_head_kv, ne3 ] !! not transposed !!
2316
+ // mask: [n_kv, n_batch, ne32, ne33]
2317
+ // res: [n_embd_v, n_head, n_batch, ne3 ] !! permuted !!
2280
2318
  //
2281
2319
  // broadcast:
2282
2320
  // n_head % n_head_kv == 0
@@ -2582,7 +2620,8 @@ extern "C" {
2582
2620
 
2583
2621
  // Set callback for all future logging events.
2584
2622
  // If this is not called, or NULL is supplied, everything is output on stderr.
2585
- WSP_GGML_API void wsp_ggml_log_set(wsp_ggml_log_callback log_callback, void * user_data);
2623
+ WSP_GGML_API void wsp_ggml_log_get(wsp_ggml_log_callback * log_callback, void ** user_data);
2624
+ WSP_GGML_API void wsp_ggml_log_set(wsp_ggml_log_callback log_callback, void * user_data);
2586
2625
 
2587
2626
  WSP_GGML_API struct wsp_ggml_tensor * wsp_ggml_set_zero(struct wsp_ggml_tensor * tensor);
2588
2627