cui-llama.rn 1.3.6 → 1.4.1

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 (101) hide show
  1. package/README.md +22 -1
  2. package/android/src/main/CMakeLists.txt +25 -26
  3. package/android/src/main/java/com/rnllama/LlamaContext.java +31 -9
  4. package/android/src/main/java/com/rnllama/RNLlama.java +98 -0
  5. package/android/src/main/jni-utils.h +94 -0
  6. package/android/src/main/jni.cpp +133 -63
  7. package/android/src/newarch/java/com/rnllama/RNLlamaModule.java +15 -0
  8. package/android/src/oldarch/java/com/rnllama/RNLlamaModule.java +15 -0
  9. package/cpp/common.cpp +2085 -1982
  10. package/cpp/common.h +696 -664
  11. package/cpp/ggml-alloc.c +1042 -1037
  12. package/cpp/ggml-backend-impl.h +255 -256
  13. package/cpp/ggml-backend-reg.cpp +582 -582
  14. package/cpp/ggml-backend.cpp +2002 -2002
  15. package/cpp/ggml-backend.h +354 -352
  16. package/cpp/ggml-common.h +1853 -1853
  17. package/cpp/ggml-cpp.h +39 -39
  18. package/cpp/ggml-cpu-aarch64.cpp +4247 -4247
  19. package/cpp/ggml-cpu-aarch64.h +8 -8
  20. package/cpp/ggml-cpu-impl.h +386 -386
  21. package/cpp/ggml-cpu-quants.c +10920 -10839
  22. package/cpp/ggml-cpu-traits.cpp +36 -36
  23. package/cpp/ggml-cpu-traits.h +38 -38
  24. package/cpp/ggml-cpu.c +14391 -14122
  25. package/cpp/ggml-cpu.cpp +635 -627
  26. package/cpp/ggml-cpu.h +135 -135
  27. package/cpp/ggml-impl.h +567 -567
  28. package/cpp/ggml-metal-impl.h +288 -0
  29. package/cpp/ggml-metal.m +4884 -4884
  30. package/cpp/ggml-opt.cpp +854 -0
  31. package/cpp/ggml-opt.h +216 -0
  32. package/cpp/ggml-quants.c +5238 -5238
  33. package/cpp/ggml-threading.h +14 -14
  34. package/cpp/ggml.c +6514 -6448
  35. package/cpp/ggml.h +2194 -2163
  36. package/cpp/gguf.cpp +1329 -1325
  37. package/cpp/gguf.h +202 -202
  38. package/cpp/json-schema-to-grammar.cpp +1045 -1045
  39. package/cpp/json-schema-to-grammar.h +8 -8
  40. package/cpp/json.hpp +24766 -24766
  41. package/cpp/llama-adapter.cpp +347 -346
  42. package/cpp/llama-adapter.h +74 -73
  43. package/cpp/llama-arch.cpp +1487 -1434
  44. package/cpp/llama-arch.h +400 -395
  45. package/cpp/llama-batch.cpp +368 -368
  46. package/cpp/llama-batch.h +88 -88
  47. package/cpp/llama-chat.cpp +578 -567
  48. package/cpp/llama-chat.h +52 -51
  49. package/cpp/llama-context.cpp +1775 -1771
  50. package/cpp/llama-context.h +128 -128
  51. package/cpp/llama-cparams.cpp +1 -1
  52. package/cpp/llama-cparams.h +37 -37
  53. package/cpp/llama-cpp.h +30 -30
  54. package/cpp/llama-grammar.cpp +1139 -1139
  55. package/cpp/llama-grammar.h +143 -143
  56. package/cpp/llama-hparams.cpp +71 -71
  57. package/cpp/llama-hparams.h +139 -140
  58. package/cpp/llama-impl.cpp +167 -167
  59. package/cpp/llama-impl.h +61 -61
  60. package/cpp/llama-kv-cache.cpp +718 -718
  61. package/cpp/llama-kv-cache.h +218 -218
  62. package/cpp/llama-mmap.cpp +590 -589
  63. package/cpp/llama-mmap.h +67 -67
  64. package/cpp/llama-model-loader.cpp +1124 -1011
  65. package/cpp/llama-model-loader.h +167 -158
  66. package/cpp/llama-model.cpp +3997 -2202
  67. package/cpp/llama-model.h +370 -391
  68. package/cpp/llama-sampling.cpp +2408 -2406
  69. package/cpp/llama-sampling.h +32 -48
  70. package/cpp/llama-vocab.cpp +3247 -1982
  71. package/cpp/llama-vocab.h +125 -182
  72. package/cpp/llama.cpp +10077 -12544
  73. package/cpp/llama.h +1323 -1285
  74. package/cpp/log.cpp +401 -401
  75. package/cpp/log.h +121 -121
  76. package/cpp/rn-llama.hpp +123 -116
  77. package/cpp/sampling.cpp +505 -500
  78. package/cpp/sgemm.cpp +2597 -2597
  79. package/cpp/sgemm.h +14 -14
  80. package/cpp/speculative.cpp +277 -274
  81. package/cpp/speculative.h +28 -28
  82. package/cpp/unicode.cpp +2 -3
  83. package/ios/RNLlama.mm +47 -0
  84. package/ios/RNLlamaContext.h +3 -1
  85. package/ios/RNLlamaContext.mm +71 -14
  86. package/jest/mock.js +15 -3
  87. package/lib/commonjs/NativeRNLlama.js.map +1 -1
  88. package/lib/commonjs/index.js +33 -37
  89. package/lib/commonjs/index.js.map +1 -1
  90. package/lib/module/NativeRNLlama.js.map +1 -1
  91. package/lib/module/index.js +31 -35
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/typescript/NativeRNLlama.d.ts +26 -6
  94. package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
  95. package/lib/typescript/index.d.ts +21 -36
  96. package/lib/typescript/index.d.ts.map +1 -1
  97. package/llama-rn.podspec +4 -18
  98. package/package.json +2 -3
  99. package/src/NativeRNLlama.ts +32 -13
  100. package/src/index.ts +52 -47
  101. package/cpp/llama.cpp.rej +0 -23
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__)