cui-llama.rn 1.4.0 → 1.4.2

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 (108) hide show
  1. package/README.md +4 -23
  2. package/android/build.gradle +12 -3
  3. package/android/src/main/CMakeLists.txt +13 -7
  4. package/android/src/main/java/com/rnllama/LlamaContext.java +27 -20
  5. package/android/src/main/java/com/rnllama/RNLlama.java +5 -1
  6. package/android/src/main/jni.cpp +15 -12
  7. package/android/src/main/jniLibs/arm64-v8a/librnllama.so +0 -0
  8. package/android/src/main/jniLibs/arm64-v8a/librnllama_v8.so +0 -0
  9. package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2.so +0 -0
  10. package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_dotprod.so +0 -0
  11. package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_dotprod_i8mm.so +0 -0
  12. package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_i8mm.so +0 -0
  13. package/android/src/main/jniLibs/x86_64/librnllama.so +0 -0
  14. package/android/src/main/jniLibs/x86_64/librnllama_x86_64.so +0 -0
  15. package/cpp/README.md +1 -1
  16. package/cpp/common.cpp +158 -267
  17. package/cpp/common.h +46 -12
  18. package/cpp/ggml-alloc.c +1042 -1037
  19. package/cpp/ggml-backend-impl.h +255 -256
  20. package/cpp/ggml-backend-reg.cpp +582 -582
  21. package/cpp/ggml-backend.cpp +2002 -2002
  22. package/cpp/ggml-backend.h +354 -352
  23. package/cpp/ggml-common.h +1853 -1853
  24. package/cpp/ggml-cpp.h +39 -39
  25. package/cpp/ggml-cpu-aarch64.cpp +4247 -4247
  26. package/cpp/ggml-cpu-aarch64.h +8 -8
  27. package/cpp/ggml-cpu-impl.h +386 -386
  28. package/cpp/ggml-cpu-quants.c +10920 -10839
  29. package/cpp/ggml-cpu-traits.cpp +36 -36
  30. package/cpp/ggml-cpu-traits.h +38 -38
  31. package/cpp/ggml-cpu.c +329 -60
  32. package/cpp/ggml-cpu.cpp +10 -2
  33. package/cpp/ggml-cpu.h +135 -135
  34. package/cpp/ggml-impl.h +567 -567
  35. package/cpp/ggml-metal-impl.h +17 -17
  36. package/cpp/ggml-metal.m +4884 -4884
  37. package/cpp/ggml-quants.c +5238 -5238
  38. package/cpp/ggml-threading.h +14 -14
  39. package/cpp/ggml.c +6514 -6448
  40. package/cpp/ggml.h +2194 -2163
  41. package/cpp/gguf.cpp +1329 -1325
  42. package/cpp/gguf.h +202 -202
  43. package/cpp/json-schema-to-grammar.cpp +1045 -1045
  44. package/cpp/json-schema-to-grammar.h +8 -8
  45. package/cpp/json.hpp +24766 -24766
  46. package/cpp/llama-adapter.cpp +347 -346
  47. package/cpp/llama-adapter.h +74 -73
  48. package/cpp/llama-arch.cpp +1487 -1434
  49. package/cpp/llama-arch.h +400 -395
  50. package/cpp/llama-batch.cpp +368 -368
  51. package/cpp/llama-batch.h +88 -88
  52. package/cpp/llama-chat.cpp +578 -567
  53. package/cpp/llama-chat.h +52 -51
  54. package/cpp/llama-context.cpp +1775 -1771
  55. package/cpp/llama-context.h +128 -128
  56. package/cpp/llama-cparams.cpp +1 -1
  57. package/cpp/llama-cparams.h +37 -37
  58. package/cpp/llama-cpp.h +30 -30
  59. package/cpp/llama-grammar.cpp +1139 -1139
  60. package/cpp/llama-grammar.h +143 -143
  61. package/cpp/llama-hparams.cpp +71 -71
  62. package/cpp/llama-hparams.h +139 -140
  63. package/cpp/llama-impl.cpp +167 -167
  64. package/cpp/llama-impl.h +61 -61
  65. package/cpp/llama-kv-cache.cpp +718 -718
  66. package/cpp/llama-kv-cache.h +218 -218
  67. package/cpp/llama-mmap.cpp +2 -1
  68. package/cpp/llama-mmap.h +67 -67
  69. package/cpp/llama-model-loader.cpp +1124 -1011
  70. package/cpp/llama-model-loader.h +167 -158
  71. package/cpp/llama-model.cpp +3997 -2202
  72. package/cpp/llama-model.h +370 -391
  73. package/cpp/llama-sampling.cpp +2408 -2406
  74. package/cpp/llama-sampling.h +32 -48
  75. package/cpp/llama-vocab.cpp +3247 -1982
  76. package/cpp/llama-vocab.h +125 -182
  77. package/cpp/llama.cpp +416 -2886
  78. package/cpp/llama.h +1323 -1285
  79. package/cpp/log.cpp +401 -401
  80. package/cpp/log.h +121 -121
  81. package/cpp/rn-llama.cpp +822 -0
  82. package/cpp/rn-llama.h +123 -0
  83. package/cpp/rn-llama.hpp +18 -12
  84. package/cpp/sampling.cpp +505 -500
  85. package/cpp/sgemm.cpp +2597 -2597
  86. package/cpp/speculative.cpp +277 -274
  87. package/cpp/speculative.h +28 -28
  88. package/cpp/unicode.cpp +2 -3
  89. package/ios/CMakeLists.txt +99 -0
  90. package/ios/RNLlama.h +5 -1
  91. package/ios/RNLlama.mm +2 -2
  92. package/ios/RNLlamaContext.h +8 -1
  93. package/ios/RNLlamaContext.mm +15 -11
  94. package/ios/rnllama.xcframework/Info.plist +74 -0
  95. package/jest/mock.js +3 -2
  96. package/lib/commonjs/NativeRNLlama.js.map +1 -1
  97. package/lib/commonjs/index.js +4 -2
  98. package/lib/commonjs/index.js.map +1 -1
  99. package/lib/module/NativeRNLlama.js.map +1 -1
  100. package/lib/module/index.js +4 -2
  101. package/lib/module/index.js.map +1 -1
  102. package/lib/typescript/NativeRNLlama.d.ts +5 -1
  103. package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
  104. package/lib/typescript/index.d.ts.map +1 -1
  105. package/llama-rn.podspec +8 -2
  106. package/package.json +5 -2
  107. package/src/NativeRNLlama.ts +5 -1
  108. package/src/index.ts +9 -2
package/cpp/log.h CHANGED
@@ -1,121 +1,121 @@
1
- #pragma once
2
-
3
- #include "ggml.h" // for lm_ggml_log_level
4
-
5
- #ifndef __GNUC__
6
- # define LOG_ATTRIBUTE_FORMAT(...)
7
- #elif defined(__MINGW32__)
8
- # define LOG_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
9
- #else
10
- # define LOG_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
11
- #endif
12
-
13
- #define LOG_DEFAULT_DEBUG 1
14
- #define LOG_DEFAULT_LLAMA 0
15
-
16
- // needed by the LOG_TMPL macro to avoid computing log arguments if the verbosity lower
17
- // set via common_log_set_verbosity()
18
- extern int common_log_verbosity_thold;
19
-
20
- void common_log_set_verbosity_thold(int verbosity); // not thread-safe
21
-
22
- // the common_log uses an internal worker thread to print/write log messages
23
- // when the worker thread is paused, incoming log messages are discarded
24
- struct common_log;
25
-
26
- struct common_log * common_log_init();
27
- struct common_log * common_log_main(); // singleton, automatically destroys itself on exit
28
- void common_log_pause (struct common_log * log); // pause the worker thread, not thread-safe
29
- void common_log_resume(struct common_log * log); // resume the worker thread, not thread-safe
30
- void common_log_free (struct common_log * log);
31
-
32
- LOG_ATTRIBUTE_FORMAT(3, 4)
33
- void common_log_add(struct common_log * log, enum lm_ggml_log_level level, const char * fmt, ...);
34
-
35
- // defaults: file = NULL, colors = false, prefix = false, timestamps = false
36
- //
37
- // regular log output:
38
- //
39
- // lm_ggml_backend_metal_log_allocated_size: allocated buffer, size = 6695.84 MiB, ( 6695.91 / 21845.34)
40
- // llm_load_tensors: ggml ctx size = 0.27 MiB
41
- // llm_load_tensors: offloading 32 repeating layers to GPU
42
- // llm_load_tensors: offloading non-repeating layers to GPU
43
- //
44
- // with prefix = true, timestamps = true, the log output will look like this:
45
- //
46
- // 0.00.035.060 D lm_ggml_backend_metal_log_allocated_size: allocated buffer, size = 6695.84 MiB, ( 6695.91 / 21845.34)
47
- // 0.00.035.064 I llm_load_tensors: ggml ctx size = 0.27 MiB
48
- // 0.00.090.578 I llm_load_tensors: offloading 32 repeating layers to GPU
49
- // 0.00.090.579 I llm_load_tensors: offloading non-repeating layers to GPU
50
- //
51
- // I - info (stdout, V = 0)
52
- // W - warning (stderr, V = 0)
53
- // E - error (stderr, V = 0)
54
- // D - debug (stderr, V = LOG_DEFAULT_DEBUG)
55
- //
56
-
57
- void common_log_set_file (struct common_log * log, const char * file); // not thread-safe
58
- void common_log_set_colors (struct common_log * log, bool colors); // not thread-safe
59
- void common_log_set_prefix (struct common_log * log, bool prefix); // whether to output prefix to each log
60
- void common_log_set_timestamps(struct common_log * log, bool timestamps); // whether to output timestamps in the prefix
61
-
62
- // helper macros for logging
63
- // use these to avoid computing log arguments if the verbosity of the log is higher than the threshold
64
- //
65
- // for example:
66
- //
67
- // LOG_DBG("this is a debug message: %d\n", expensive_function());
68
- //
69
- // this will avoid calling expensive_function() if LOG_DEFAULT_DEBUG > common_log_verbosity_thold
70
- //
71
-
72
-
73
-
74
- #if defined(__ANDROID__)
75
- #include <android/log.h>
76
- #define LLAMA_ANDROID_LOG_TAG "RNLLAMA_LOG_ANDROID"
77
-
78
- #if defined(RNLLAMA_ANDROID_ENABLE_LOGGING)
79
- #define RNLLAMA_LOG_LEVEL 1
80
- #else
81
- #define RNLLAMA_LOG_LEVEL 0
82
- #endif
83
-
84
- #define LOG_TMPL(level, verbosity, ...) \
85
- do { \
86
- if ((verbosity) <= RNLLAMA_LOG_LEVEL) { \
87
- int android_log_level = ANDROID_LOG_DEFAULT; \
88
- switch (level) { \
89
- case LM_GGML_LOG_LEVEL_INFO: android_log_level = ANDROID_LOG_INFO; break; \
90
- case LM_GGML_LOG_LEVEL_WARN: android_log_level = ANDROID_LOG_WARN; break; \
91
- case LM_GGML_LOG_LEVEL_ERROR: android_log_level = ANDROID_LOG_ERROR; break; \
92
- default: android_log_level = ANDROID_LOG_DEFAULT; \
93
- } \
94
- __android_log_print(android_log_level, LLAMA_ANDROID_LOG_TAG, __VA_ARGS__); \
95
- } \
96
- } while(0)
97
- #else
98
-
99
- #define LOG_TMPL(level, verbosity, ...) \
100
- do { \
101
- if ((verbosity) <= common_log_verbosity_thold) { \
102
- common_log_add(common_log_main(), (level), __VA_ARGS__); \
103
- } \
104
- } while (0)
105
-
106
- #endif
107
-
108
- #define LOG(...) LOG_TMPL(LM_GGML_LOG_LEVEL_NONE, 0, __VA_ARGS__)
109
- #define LOGV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_NONE, verbosity, __VA_ARGS__)
110
-
111
- #define LOG_INF(...) LOG_TMPL(LM_GGML_LOG_LEVEL_INFO, 0, __VA_ARGS__)
112
- #define LOG_WRN(...) LOG_TMPL(LM_GGML_LOG_LEVEL_WARN, 0, __VA_ARGS__)
113
- #define LOG_ERR(...) LOG_TMPL(LM_GGML_LOG_LEVEL_ERROR, 0, __VA_ARGS__)
114
- #define LOG_DBG(...) LOG_TMPL(LM_GGML_LOG_LEVEL_DEBUG, LOG_DEFAULT_DEBUG, __VA_ARGS__)
115
- #define LOG_CNT(...) LOG_TMPL(LM_GGML_LOG_LEVEL_CONT, 0, __VA_ARGS__)
116
-
117
- #define LOG_INFV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_INFO, verbosity, __VA_ARGS__)
118
- #define LOG_WRNV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_WARN, verbosity, __VA_ARGS__)
119
- #define LOG_ERRV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_ERROR, verbosity, __VA_ARGS__)
120
- #define LOG_DBGV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_DEBUG, verbosity, __VA_ARGS__)
121
- #define LOG_CNTV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_CONT, verbosity, __VA_ARGS__)
1
+ #pragma once
2
+
3
+ #include "ggml.h" // for lm_ggml_log_level
4
+
5
+ #ifndef __GNUC__
6
+ # define LOG_ATTRIBUTE_FORMAT(...)
7
+ #elif defined(__MINGW32__)
8
+ # define LOG_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
9
+ #else
10
+ # define LOG_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
11
+ #endif
12
+
13
+ #define LOG_DEFAULT_DEBUG 1
14
+ #define LOG_DEFAULT_LLAMA 0
15
+
16
+ // needed by the LOG_TMPL macro to avoid computing log arguments if the verbosity lower
17
+ // set via common_log_set_verbosity()
18
+ extern int common_log_verbosity_thold;
19
+
20
+ void common_log_set_verbosity_thold(int verbosity); // not thread-safe
21
+
22
+ // the common_log uses an internal worker thread to print/write log messages
23
+ // when the worker thread is paused, incoming log messages are discarded
24
+ struct common_log;
25
+
26
+ struct common_log * common_log_init();
27
+ struct common_log * common_log_main(); // singleton, automatically destroys itself on exit
28
+ void common_log_pause (struct common_log * log); // pause the worker thread, not thread-safe
29
+ void common_log_resume(struct common_log * log); // resume the worker thread, not thread-safe
30
+ void common_log_free (struct common_log * log);
31
+
32
+ LOG_ATTRIBUTE_FORMAT(3, 4)
33
+ void common_log_add(struct common_log * log, enum lm_ggml_log_level level, const char * fmt, ...);
34
+
35
+ // defaults: file = NULL, colors = false, prefix = false, timestamps = false
36
+ //
37
+ // regular log output:
38
+ //
39
+ // lm_ggml_backend_metal_log_allocated_size: allocated buffer, size = 6695.84 MiB, ( 6695.91 / 21845.34)
40
+ // llm_load_tensors: ggml ctx size = 0.27 MiB
41
+ // llm_load_tensors: offloading 32 repeating layers to GPU
42
+ // llm_load_tensors: offloading non-repeating layers to GPU
43
+ //
44
+ // with prefix = true, timestamps = true, the log output will look like this:
45
+ //
46
+ // 0.00.035.060 D lm_ggml_backend_metal_log_allocated_size: allocated buffer, size = 6695.84 MiB, ( 6695.91 / 21845.34)
47
+ // 0.00.035.064 I llm_load_tensors: ggml ctx size = 0.27 MiB
48
+ // 0.00.090.578 I llm_load_tensors: offloading 32 repeating layers to GPU
49
+ // 0.00.090.579 I llm_load_tensors: offloading non-repeating layers to GPU
50
+ //
51
+ // I - info (stdout, V = 0)
52
+ // W - warning (stderr, V = 0)
53
+ // E - error (stderr, V = 0)
54
+ // D - debug (stderr, V = LOG_DEFAULT_DEBUG)
55
+ //
56
+
57
+ void common_log_set_file (struct common_log * log, const char * file); // not thread-safe
58
+ void common_log_set_colors (struct common_log * log, bool colors); // not thread-safe
59
+ void common_log_set_prefix (struct common_log * log, bool prefix); // whether to output prefix to each log
60
+ void common_log_set_timestamps(struct common_log * log, bool timestamps); // whether to output timestamps in the prefix
61
+
62
+ // helper macros for logging
63
+ // use these to avoid computing log arguments if the verbosity of the log is higher than the threshold
64
+ //
65
+ // for example:
66
+ //
67
+ // LOG_DBG("this is a debug message: %d\n", expensive_function());
68
+ //
69
+ // this will avoid calling expensive_function() if LOG_DEFAULT_DEBUG > common_log_verbosity_thold
70
+ //
71
+
72
+
73
+
74
+ #if defined(__ANDROID__)
75
+ #include <android/log.h>
76
+ #define LLAMA_ANDROID_LOG_TAG "RNLLAMA_LOG_ANDROID"
77
+
78
+ #if defined(RNLLAMA_ANDROID_ENABLE_LOGGING)
79
+ #define RNLLAMA_LOG_LEVEL 1
80
+ #else
81
+ #define RNLLAMA_LOG_LEVEL 0
82
+ #endif
83
+
84
+ #define LOG_TMPL(level, verbosity, ...) \
85
+ do { \
86
+ if ((verbosity) <= RNLLAMA_LOG_LEVEL) { \
87
+ int android_log_level = ANDROID_LOG_DEFAULT; \
88
+ switch (level) { \
89
+ case LM_GGML_LOG_LEVEL_INFO: android_log_level = ANDROID_LOG_INFO; break; \
90
+ case LM_GGML_LOG_LEVEL_WARN: android_log_level = ANDROID_LOG_WARN; break; \
91
+ case LM_GGML_LOG_LEVEL_ERROR: android_log_level = ANDROID_LOG_ERROR; break; \
92
+ default: android_log_level = ANDROID_LOG_DEFAULT; \
93
+ } \
94
+ __android_log_print(android_log_level, LLAMA_ANDROID_LOG_TAG, __VA_ARGS__); \
95
+ } \
96
+ } while(0)
97
+ #else
98
+
99
+ #define LOG_TMPL(level, verbosity, ...) \
100
+ do { \
101
+ if ((verbosity) <= common_log_verbosity_thold) { \
102
+ common_log_add(common_log_main(), (level), __VA_ARGS__); \
103
+ } \
104
+ } while (0)
105
+
106
+ #endif
107
+
108
+ #define LOG(...) LOG_TMPL(LM_GGML_LOG_LEVEL_NONE, 0, __VA_ARGS__)
109
+ #define LOGV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_NONE, verbosity, __VA_ARGS__)
110
+
111
+ #define LOG_INF(...) LOG_TMPL(LM_GGML_LOG_LEVEL_INFO, 0, __VA_ARGS__)
112
+ #define LOG_WRN(...) LOG_TMPL(LM_GGML_LOG_LEVEL_WARN, 0, __VA_ARGS__)
113
+ #define LOG_ERR(...) LOG_TMPL(LM_GGML_LOG_LEVEL_ERROR, 0, __VA_ARGS__)
114
+ #define LOG_DBG(...) LOG_TMPL(LM_GGML_LOG_LEVEL_DEBUG, LOG_DEFAULT_DEBUG, __VA_ARGS__)
115
+ #define LOG_CNT(...) LOG_TMPL(LM_GGML_LOG_LEVEL_CONT, 0, __VA_ARGS__)
116
+
117
+ #define LOG_INFV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_INFO, verbosity, __VA_ARGS__)
118
+ #define LOG_WRNV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_WARN, verbosity, __VA_ARGS__)
119
+ #define LOG_ERRV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_ERROR, verbosity, __VA_ARGS__)
120
+ #define LOG_DBGV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_DEBUG, verbosity, __VA_ARGS__)
121
+ #define LOG_CNTV(verbosity, ...) LOG_TMPL(LM_GGML_LOG_LEVEL_CONT, verbosity, __VA_ARGS__)