cui-llama.rn 1.3.0 → 1.3.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.
- package/android/src/main/CMakeLists.txt +9 -6
- package/android/src/main/java/com/rnllama/LlamaContext.java +4 -4
- package/android/src/main/jni.cpp +15 -15
- package/cpp/common.cpp +1962 -1682
- package/cpp/common.h +645 -600
- package/cpp/ggml-alloc.c +1038 -1040
- package/cpp/ggml-alloc.h +76 -76
- package/cpp/ggml-backend-impl.h +256 -216
- package/cpp/ggml-backend-reg.cpp +552 -195
- package/cpp/ggml-backend.cpp +1999 -1997
- package/cpp/ggml-backend.h +352 -328
- package/cpp/ggml-common.h +1853 -1853
- package/cpp/ggml-cpp.h +38 -38
- package/cpp/{ggml-cpu-aarch64.c → ggml-cpu-aarch64.cpp} +4262 -3560
- package/cpp/ggml-cpu-aarch64.h +8 -30
- package/cpp/ggml-cpu-impl.h +386 -371
- package/cpp/ggml-cpu-quants.c +10835 -10822
- package/cpp/ggml-cpu-quants.h +63 -63
- package/cpp/ggml-cpu-traits.cpp +36 -0
- package/cpp/ggml-cpu-traits.h +38 -0
- package/cpp/ggml-cpu.c +14122 -13975
- package/cpp/ggml-cpu.cpp +618 -663
- package/cpp/ggml-cpu.h +135 -177
- package/cpp/ggml-impl.h +556 -550
- package/cpp/ggml-metal.h +66 -66
- package/cpp/ggml-metal.m +4884 -4294
- package/cpp/ggml-quants.c +5238 -5247
- package/cpp/ggml-quants.h +100 -100
- package/cpp/ggml-threading.cpp +12 -12
- package/cpp/ggml-threading.h +14 -12
- package/cpp/ggml.c +7707 -8180
- package/cpp/ggml.h +2286 -2411
- package/cpp/json-schema-to-grammar.cpp +1045 -0
- package/cpp/json-schema-to-grammar.h +8 -0
- package/cpp/json.hpp +24766 -0
- package/cpp/llama-grammar.cpp +1138 -1138
- package/cpp/llama-grammar.h +144 -144
- package/cpp/llama-impl.h +181 -181
- package/cpp/llama-sampling.cpp +2293 -2348
- package/cpp/llama-sampling.h +48 -48
- package/cpp/llama-vocab.cpp +1985 -1984
- package/cpp/llama-vocab.h +170 -170
- package/cpp/llama.cpp +22836 -22132
- package/cpp/llama.h +1263 -1253
- package/cpp/log.cpp +401 -401
- package/cpp/log.h +121 -121
- package/cpp/rn-llama.hpp +6 -6
- package/cpp/sampling.cpp +500 -466
- package/cpp/sampling.h +22 -1
- package/cpp/sgemm.cpp +1884 -1884
- package/cpp/speculative.cpp +274 -0
- package/cpp/speculative.h +28 -0
- package/cpp/unicode.cpp +62 -51
- package/cpp/unicode.h +9 -10
- package/ios/RNLlamaContext.mm +13 -0
- package/lib/commonjs/NativeRNLlama.js.map +1 -1
- package/lib/commonjs/grammar.js +4 -2
- package/lib/commonjs/grammar.js.map +1 -1
- package/lib/commonjs/index.js +38 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRNLlama.js.map +1 -1
- package/lib/module/grammar.js +2 -1
- package/lib/module/grammar.js.map +1 -1
- package/lib/module/index.js +36 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRNLlama.d.ts +95 -6
- package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
- package/lib/typescript/grammar.d.ts +5 -6
- package/lib/typescript/grammar.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +40 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/NativeRNLlama.ts +99 -12
- package/src/grammar.ts +10 -8
- package/src/index.ts +68 -3
- package/cpp/ggml-aarch64.c +0 -129
- package/cpp/ggml-aarch64.h +0 -19
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__)
|
package/cpp/rn-llama.hpp
CHANGED
@@ -197,7 +197,6 @@ static std::string tokens_to_str(llama_context *ctx, Iter begin, Iter end)
|
|
197
197
|
return ret;
|
198
198
|
}
|
199
199
|
|
200
|
-
|
201
200
|
struct llama_rn_context
|
202
201
|
{
|
203
202
|
bool is_predicting = false;
|
@@ -253,7 +252,7 @@ struct llama_rn_context
|
|
253
252
|
{
|
254
253
|
is_interrupted = false;
|
255
254
|
params.antiprompt.clear();
|
256
|
-
params.
|
255
|
+
params.sampling.grammar.clear();
|
257
256
|
num_prompt_tokens = 0;
|
258
257
|
num_tokens_predicted = 0;
|
259
258
|
generated_text = "";
|
@@ -267,14 +266,14 @@ struct llama_rn_context
|
|
267
266
|
incomplete = false;
|
268
267
|
n_remain = 0;
|
269
268
|
n_past = 0;
|
270
|
-
params.
|
269
|
+
params.sampling.n_prev = n_ctx;
|
271
270
|
}
|
272
271
|
|
273
272
|
bool initSampling() {
|
274
273
|
if (ctx_sampling != nullptr) {
|
275
274
|
common_sampler_free(ctx_sampling);
|
276
275
|
}
|
277
|
-
ctx_sampling = common_sampler_init(model, params.
|
276
|
+
ctx_sampling = common_sampler_init(model, params.sampling);
|
278
277
|
return ctx_sampling != nullptr;
|
279
278
|
}
|
280
279
|
|
@@ -289,6 +288,7 @@ struct llama_rn_context
|
|
289
288
|
LOG_ERROR("unable to load model: %s", params_.model.c_str());
|
290
289
|
return false;
|
291
290
|
}
|
291
|
+
LOG_VERBOSE("getting n_ctx");
|
292
292
|
n_ctx = llama_n_ctx(ctx);
|
293
293
|
return true;
|
294
294
|
}
|
@@ -474,7 +474,7 @@ struct llama_rn_context
|
|
474
474
|
|
475
475
|
llama_token_data_array cur_p = *common_sampler_get_candidates(ctx_sampling);
|
476
476
|
|
477
|
-
const int32_t n_probs = params.
|
477
|
+
const int32_t n_probs = params.sampling.n_probs;
|
478
478
|
|
479
479
|
// deprecated
|
480
480
|
/*if (params.sparams.temp <= 0 && n_probs > 0)
|
@@ -553,7 +553,7 @@ struct llama_rn_context
|
|
553
553
|
const std::string token_text = token_with_probs.tok == -1 ? "" : common_token_to_piece(ctx, token_with_probs.tok);
|
554
554
|
generated_text += token_text;
|
555
555
|
|
556
|
-
if (params.
|
556
|
+
if (params.sampling.n_probs > 0)
|
557
557
|
{
|
558
558
|
generated_token_probs.push_back(token_with_probs);
|
559
559
|
}
|