cui-llama.rn 1.2.3 → 1.2.6
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/README.md +0 -2
- package/android/src/main/CMakeLists.txt +1 -0
- package/android/src/main/java/com/rnllama/LlamaContext.java +0 -3
- package/android/src/main/jni.cpp +9 -11
- package/cpp/common.cpp +85 -75
- package/cpp/common.h +127 -91
- package/cpp/ggml-aarch64.c +269 -0
- package/cpp/ggml-alloc.c +17 -19
- package/cpp/ggml-backend-impl.h +4 -15
- package/cpp/ggml-backend.cpp +1697 -1626
- package/cpp/ggml-backend.h +13 -25
- package/cpp/ggml-cpp.h +38 -0
- package/cpp/ggml-cpu.c +13720 -0
- package/cpp/ggml-cpu.h +150 -0
- package/cpp/ggml-impl.h +95 -0
- package/cpp/ggml-metal.m +185 -71
- package/cpp/ggml-quants.c +38 -51
- package/cpp/ggml.c +4468 -19500
- package/cpp/ggml.h +26 -146
- package/cpp/json-schema-to-grammar.cpp +1 -1
- package/cpp/llama-sampling.cpp +742 -249
- package/cpp/llama-sampling.h +21 -2
- package/cpp/llama-vocab.cpp +49 -9
- package/cpp/llama-vocab.h +35 -11
- package/cpp/llama.cpp +2468 -2307
- package/cpp/llama.h +65 -32
- package/cpp/log.cpp +50 -50
- package/cpp/log.h +18 -18
- package/cpp/rn-llama.hpp +23 -22
- package/cpp/sampling.cpp +117 -118
- package/cpp/sampling.h +20 -20
- package/cpp/sgemm.cpp +57 -0
- package/lib/commonjs/NativeRNLlama.js.map +1 -1
- package/lib/module/NativeRNLlama.js.map +1 -1
- package/lib/typescript/NativeRNLlama.d.ts +0 -1
- package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeRNLlama.ts +0 -1
package/cpp/llama-sampling.h
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
|
5
5
|
#include "llama-grammar.h"
|
6
6
|
|
7
|
-
#include <unordered_map>
|
8
|
-
|
9
7
|
struct llama_vocab;
|
10
8
|
struct llama_grammar;
|
11
9
|
|
@@ -27,3 +25,24 @@ struct llama_sampler * llama_sampler_init_grammar_impl(
|
|
27
25
|
const struct llama_vocab & vocab,
|
28
26
|
const char * grammar_str,
|
29
27
|
const char * grammar_root);
|
28
|
+
|
29
|
+
struct llama_sampler * llama_sampler_init_infill_impl(
|
30
|
+
const struct llama_vocab & vocab);
|
31
|
+
|
32
|
+
struct llama_sampler * llama_sampler_init_dry_impl(
|
33
|
+
const struct llama_vocab & vocab,
|
34
|
+
int32_t context_size,
|
35
|
+
float dry_multiplier,
|
36
|
+
float dry_base,
|
37
|
+
int32_t dry_allowed_length,
|
38
|
+
int32_t dry_penalty_last_n,
|
39
|
+
const char ** seq_breakers,
|
40
|
+
size_t num_breakers);
|
41
|
+
|
42
|
+
struct llama_sampler * llama_sampler_init_dry_testing(
|
43
|
+
int32_t context_size,
|
44
|
+
float dry_multiplier,
|
45
|
+
float dry_base,
|
46
|
+
int32_t dry_allowed_length,
|
47
|
+
int32_t dry_penalty_last_n,
|
48
|
+
const std::vector<std::vector<llama_token>>& seq_breakers);
|
package/cpp/llama-vocab.cpp
CHANGED
@@ -221,7 +221,7 @@ struct llm_tokenizer_spm_session {
|
|
221
221
|
}
|
222
222
|
|
223
223
|
// seed the work queue with all possible 2-character tokens.
|
224
|
-
for (
|
224
|
+
for (int i = 1; i < (int) symbols.size(); ++i) {
|
225
225
|
try_add_bigram(i - 1, i);
|
226
226
|
}
|
227
227
|
|
@@ -563,7 +563,7 @@ struct llm_tokenizer_bpe_session {
|
|
563
563
|
index++;
|
564
564
|
symbols.emplace_back(sym);
|
565
565
|
}
|
566
|
-
for (
|
566
|
+
for (int i = 1; i < (int) symbols.size(); ++i) {
|
567
567
|
add_new_bigram(i - 1, i);
|
568
568
|
}
|
569
569
|
|
@@ -1663,6 +1663,14 @@ llama_token llama_token_eos_impl(const struct llama_vocab & vocab) {
|
|
1663
1663
|
return vocab.special_eos_id;
|
1664
1664
|
}
|
1665
1665
|
|
1666
|
+
llama_token llama_token_eot_impl(const struct llama_vocab & vocab) {
|
1667
|
+
return vocab.special_eot_id;
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
llama_token llama_token_eom_impl(const struct llama_vocab & vocab) {
|
1671
|
+
return vocab.special_eom_id;
|
1672
|
+
}
|
1673
|
+
|
1666
1674
|
llama_token llama_token_cls_impl(const struct llama_vocab & vocab) {
|
1667
1675
|
return vocab.special_cls_id;
|
1668
1676
|
}
|
@@ -1688,23 +1696,39 @@ bool llama_add_eos_token_impl(const struct llama_vocab & vocab) {
|
|
1688
1696
|
}
|
1689
1697
|
|
1690
1698
|
llama_token llama_token_prefix_impl(const struct llama_vocab & vocab) {
|
1691
|
-
return vocab.
|
1699
|
+
return vocab.special_fim_pre_id;
|
1692
1700
|
}
|
1693
1701
|
|
1694
1702
|
llama_token llama_token_middle_impl(const struct llama_vocab & vocab) {
|
1695
|
-
return vocab.
|
1703
|
+
return vocab.special_fim_mid_id;
|
1696
1704
|
}
|
1697
1705
|
|
1698
1706
|
llama_token llama_token_suffix_impl(const struct llama_vocab & vocab) {
|
1699
|
-
return vocab.
|
1707
|
+
return vocab.special_fim_suf_id;
|
1700
1708
|
}
|
1701
1709
|
|
1702
|
-
llama_token
|
1703
|
-
return vocab.
|
1710
|
+
llama_token llama_token_fim_pre_impl(const struct llama_vocab & vocab) {
|
1711
|
+
return vocab.special_fim_pre_id;
|
1704
1712
|
}
|
1705
1713
|
|
1706
|
-
llama_token
|
1707
|
-
return vocab.
|
1714
|
+
llama_token llama_token_fim_suf_impl(const struct llama_vocab & vocab) {
|
1715
|
+
return vocab.special_fim_suf_id;
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
llama_token llama_token_fim_mid_impl(const struct llama_vocab & vocab) {
|
1719
|
+
return vocab.special_fim_mid_id;
|
1720
|
+
}
|
1721
|
+
|
1722
|
+
llama_token llama_token_fim_pad_impl(const struct llama_vocab & vocab) {
|
1723
|
+
return vocab.special_fim_pad_id;
|
1724
|
+
}
|
1725
|
+
|
1726
|
+
llama_token llama_token_fim_rep_impl(const struct llama_vocab & vocab) {
|
1727
|
+
return vocab.special_fim_rep_id;
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
llama_token llama_token_fim_sep_impl(const struct llama_vocab & vocab) {
|
1731
|
+
return vocab.special_fim_sep_id;
|
1708
1732
|
}
|
1709
1733
|
|
1710
1734
|
int32_t llama_tokenize_impl(
|
@@ -1942,3 +1966,19 @@ int32_t llama_detokenize_impl(
|
|
1942
1966
|
|
1943
1967
|
return total <= text_len_max ? total : -total;
|
1944
1968
|
}
|
1969
|
+
|
1970
|
+
std::string llama_detokenize(const struct llama_vocab & vocab, const std::vector<llama_token> & tokens, bool special) {
|
1971
|
+
std::string text;
|
1972
|
+
text.resize(std::max(text.capacity(), tokens.size()));
|
1973
|
+
int32_t n_chars = llama_detokenize_impl(vocab, tokens.data(), (int32_t)tokens.size(), &text[0], (int32_t)text.size(), false, special);
|
1974
|
+
if (n_chars < 0) {
|
1975
|
+
text.resize(-n_chars);
|
1976
|
+
n_chars = llama_detokenize_impl(vocab, tokens.data(), (int32_t)tokens.size(), &text[0], (int32_t)text.size(), false, special);
|
1977
|
+
LM_GGML_ASSERT(n_chars <= (int32_t)text.size()); // whitespace trimming is performed after per-token detokenization
|
1978
|
+
}
|
1979
|
+
|
1980
|
+
text.resize(n_chars);
|
1981
|
+
|
1982
|
+
// NOTE: the original tokenizer decodes bytes after collecting the pieces.
|
1983
|
+
return text;
|
1984
|
+
}
|
package/cpp/llama-vocab.h
CHANGED
@@ -37,20 +37,26 @@ struct llama_vocab {
|
|
37
37
|
std::map<std::pair<std::string, std::string>, int> bpe_ranks;
|
38
38
|
|
39
39
|
// default LLaMA special tokens
|
40
|
+
// TODO: should we set all of these to LLAMA_TOKEN_NULL?
|
40
41
|
id special_bos_id = 1;
|
41
42
|
id special_eos_id = 2;
|
43
|
+
id special_eot_id = LLAMA_TOKEN_NULL;
|
44
|
+
id special_eom_id = LLAMA_TOKEN_NULL;
|
42
45
|
id special_unk_id = 0;
|
43
46
|
id special_sep_id = LLAMA_TOKEN_NULL;
|
44
47
|
id special_pad_id = LLAMA_TOKEN_NULL;
|
45
48
|
id special_cls_id = LLAMA_TOKEN_NULL;
|
46
49
|
id special_mask_id = LLAMA_TOKEN_NULL;
|
47
50
|
|
48
|
-
id linefeed_id
|
49
|
-
|
50
|
-
|
51
|
-
id
|
52
|
-
id
|
53
|
-
id
|
51
|
+
id linefeed_id = 13;
|
52
|
+
|
53
|
+
// fim tokens
|
54
|
+
id special_fim_pre_id = LLAMA_TOKEN_NULL;
|
55
|
+
id special_fim_suf_id = LLAMA_TOKEN_NULL;
|
56
|
+
id special_fim_mid_id = LLAMA_TOKEN_NULL;
|
57
|
+
id special_fim_pad_id = LLAMA_TOKEN_NULL;
|
58
|
+
id special_fim_rep_id = LLAMA_TOKEN_NULL; // repo
|
59
|
+
id special_fim_sep_id = LLAMA_TOKEN_NULL; // file separator
|
54
60
|
|
55
61
|
// set of all tokens that cause "end of generation"
|
56
62
|
std::set<id> special_eog_ids;
|
@@ -104,19 +110,26 @@ bool llama_token_is_control_impl(const struct llama_vocab & vocab, llama_token t
|
|
104
110
|
|
105
111
|
llama_token llama_token_bos_impl(const struct llama_vocab & vocab);
|
106
112
|
llama_token llama_token_eos_impl(const struct llama_vocab & vocab);
|
113
|
+
llama_token llama_token_eot_impl(const struct llama_vocab & vocab);
|
114
|
+
llama_token llama_token_eom_impl(const struct llama_vocab & vocab);
|
107
115
|
llama_token llama_token_cls_impl(const struct llama_vocab & vocab);
|
108
116
|
llama_token llama_token_sep_impl(const struct llama_vocab & vocab);
|
109
117
|
llama_token llama_token_nl_impl (const struct llama_vocab & vocab);
|
110
118
|
llama_token llama_token_pad_impl(const struct llama_vocab & vocab);
|
111
119
|
|
112
|
-
bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
|
113
|
-
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);
|
114
|
-
|
115
120
|
llama_token llama_token_prefix_impl(const struct llama_vocab & vocab);
|
116
121
|
llama_token llama_token_middle_impl(const struct llama_vocab & vocab);
|
117
122
|
llama_token llama_token_suffix_impl(const struct llama_vocab & vocab);
|
118
|
-
|
119
|
-
llama_token
|
123
|
+
|
124
|
+
llama_token llama_token_fim_pre_impl(const struct llama_vocab & vocab);
|
125
|
+
llama_token llama_token_fim_suf_impl(const struct llama_vocab & vocab);
|
126
|
+
llama_token llama_token_fim_mid_impl(const struct llama_vocab & vocab);
|
127
|
+
llama_token llama_token_fim_pad_impl(const struct llama_vocab & vocab);
|
128
|
+
llama_token llama_token_fim_rep_impl(const struct llama_vocab & vocab);
|
129
|
+
llama_token llama_token_fim_sep_impl(const struct llama_vocab & vocab);
|
130
|
+
|
131
|
+
bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
|
132
|
+
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);
|
120
133
|
|
121
134
|
int32_t llama_tokenize_impl(
|
122
135
|
const struct llama_vocab & vocab,
|
@@ -136,6 +149,12 @@ int32_t llama_token_to_piece_impl(
|
|
136
149
|
int32_t lstrip,
|
137
150
|
bool special);
|
138
151
|
|
152
|
+
// check if token0 is contained as a prefix in token1
|
153
|
+
bool llama_token_is_prefix_impl(
|
154
|
+
const struct llama_vocab & vocab,
|
155
|
+
llama_token token0,
|
156
|
+
llama_token token1);
|
157
|
+
|
139
158
|
int32_t llama_detokenize_impl(
|
140
159
|
const struct llama_vocab & vocab,
|
141
160
|
const llama_token * tokens,
|
@@ -144,3 +163,8 @@ int32_t llama_detokenize_impl(
|
|
144
163
|
int32_t text_len_max,
|
145
164
|
bool remove_special,
|
146
165
|
bool unparse_special);
|
166
|
+
|
167
|
+
std::string llama_detokenize(
|
168
|
+
const struct llama_vocab & vocab,
|
169
|
+
const std::vector<llama_token> & tokens,
|
170
|
+
bool special);
|