@fugood/llama.node 1.0.0-beta.4 → 1.0.0-beta.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/CMakeLists.txt +7 -4
- package/lib/binding.ts +1 -1
- package/package.json +14 -14
- package/scripts/llama.cpp.patch +27 -26
- package/src/LlamaCompletionWorker.cpp +21 -4
- package/src/LlamaCompletionWorker.h +2 -0
- package/src/LlamaContext.cpp +3 -12
- package/src/common.hpp +6 -5
- package/src/llama.cpp/CMakeLists.txt +15 -4
- package/src/llama.cpp/common/CMakeLists.txt +15 -24
- package/src/llama.cpp/common/arg.cpp +172 -110
- package/src/llama.cpp/common/chat-parser.cpp +385 -0
- package/src/llama.cpp/common/chat-parser.h +120 -0
- package/src/llama.cpp/common/chat.cpp +726 -596
- package/src/llama.cpp/common/chat.h +74 -8
- package/src/llama.cpp/common/common.cpp +56 -38
- package/src/llama.cpp/common/common.h +9 -3
- package/src/llama.cpp/common/json-partial.cpp +256 -0
- package/src/llama.cpp/common/json-partial.h +38 -0
- package/src/llama.cpp/common/json-schema-to-grammar.cpp +2 -1
- package/src/llama.cpp/common/json-schema-to-grammar.h +4 -4
- package/src/llama.cpp/common/sampling.cpp +7 -8
- package/src/llama.cpp/common/speculative.cpp +6 -4
- package/src/llama.cpp/ggml/CMakeLists.txt +48 -3
- package/src/llama.cpp/ggml/include/ggml.h +22 -3
- package/src/llama.cpp/ggml/src/CMakeLists.txt +81 -22
- package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +131 -49
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +94 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/arm/quants.c +4113 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/arm/repack.cpp +2162 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/loongarch/quants.c +2638 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/powerpc/quants.c +2731 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/riscv/quants.c +2068 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/riscv/repack.cpp +396 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/s390/quants.c +1299 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/wasm/quants.c +1480 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/arch/x86/quants.c +4310 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-aarch64.cpp → arch/x86/repack.cpp} +59 -3206
- package/src/llama.cpp/ggml/src/ggml-cpu/arch-fallback.h +184 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/common.h +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +12 -13
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +64 -88
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +8 -8
- package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-hbm.cpp → hbm.cpp} +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +56 -7
- package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.h +5 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ops.cpp +282 -100
- package/src/llama.cpp/ggml/src/ggml-cpu/ops.h +1 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/quants.c +1157 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-quants.h → quants.h} +26 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/repack.cpp +1570 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/repack.h +98 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +119 -5
- package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-traits.cpp → traits.cpp} +1 -1
- package/src/llama.cpp/ggml/src/ggml-cpu/vec.cpp +85 -16
- package/src/llama.cpp/ggml/src/ggml-cpu/vec.h +204 -49
- package/src/llama.cpp/include/llama.h +145 -40
- package/src/llama.cpp/src/CMakeLists.txt +5 -1
- package/src/llama.cpp/src/llama-arch.cpp +99 -3
- package/src/llama.cpp/src/llama-arch.h +10 -1
- package/src/llama.cpp/src/llama-batch.cpp +728 -272
- package/src/llama.cpp/src/llama-batch.h +112 -54
- package/src/llama.cpp/src/llama-chat.cpp +19 -2
- package/src/llama.cpp/src/llama-chat.h +1 -0
- package/src/llama.cpp/src/llama-context.cpp +525 -339
- package/src/llama.cpp/src/llama-context.h +38 -17
- package/src/llama.cpp/src/llama-cparams.cpp +4 -0
- package/src/llama.cpp/src/llama-cparams.h +2 -0
- package/src/llama.cpp/src/llama-grammar.cpp +12 -2
- package/src/llama.cpp/src/llama-graph.cpp +413 -353
- package/src/llama.cpp/src/llama-graph.h +112 -56
- package/src/llama.cpp/src/llama-hparams.cpp +10 -2
- package/src/llama.cpp/src/llama-hparams.h +13 -2
- package/src/llama.cpp/src/llama-kv-cache-unified-iswa.cpp +279 -0
- package/src/llama.cpp/src/llama-kv-cache-unified-iswa.h +128 -0
- package/src/llama.cpp/src/llama-kv-cache-unified.cpp +1815 -0
- package/src/llama.cpp/src/llama-kv-cache-unified.h +303 -0
- package/src/llama.cpp/src/llama-kv-cells.h +415 -0
- package/src/llama.cpp/src/llama-memory-hybrid.cpp +246 -0
- package/src/llama.cpp/src/llama-memory-hybrid.h +138 -0
- package/src/llama.cpp/src/llama-memory-recurrent.cpp +1112 -0
- package/src/llama.cpp/src/llama-memory-recurrent.h +183 -0
- package/src/llama.cpp/src/llama-memory.cpp +41 -0
- package/src/llama.cpp/src/llama-memory.h +86 -5
- package/src/llama.cpp/src/llama-mmap.cpp +1 -1
- package/src/llama.cpp/src/llama-model-loader.cpp +42 -17
- package/src/llama.cpp/src/llama-model-saver.cpp +1 -0
- package/src/llama.cpp/src/llama-model.cpp +1137 -528
- package/src/llama.cpp/src/llama-model.h +4 -0
- package/src/llama.cpp/src/llama-quant.cpp +2 -1
- package/src/llama.cpp/src/llama-sampling.cpp +2 -2
- package/src/llama.cpp/src/llama-vocab.cpp +69 -32
- package/src/llama.cpp/src/llama-vocab.h +1 -0
- package/src/llama.cpp/src/llama.cpp +11 -7
- package/src/llama.cpp/src/unicode.cpp +5 -0
- package/src/tts_utils.h +1 -1
- package/src/llama.cpp/common/json.hpp +0 -24766
- package/src/llama.cpp/common/minja/chat-template.hpp +0 -541
- package/src/llama.cpp/common/minja/minja.hpp +0 -2974
- package/src/llama.cpp/common/stb_image.h +0 -7988
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +0 -8
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +0 -13326
- package/src/llama.cpp/src/llama-kv-cache.cpp +0 -2827
- package/src/llama.cpp/src/llama-kv-cache.h +0 -515
- /package/src/llama.cpp/ggml/src/ggml-cpu/{cpu-feats-x86.cpp → arch/x86/cpu-feats.cpp} +0 -0
- /package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-hbm.h → hbm.h} +0 -0
- /package/src/llama.cpp/ggml/src/ggml-cpu/{ggml-cpu-traits.h → traits.h} +0 -0
|
@@ -73,6 +73,7 @@ enum llm_type {
|
|
|
73
73
|
LLM_TYPE_40B,
|
|
74
74
|
LLM_TYPE_65B,
|
|
75
75
|
LLM_TYPE_70B,
|
|
76
|
+
LLM_TYPE_142B,
|
|
76
77
|
LLM_TYPE_236B,
|
|
77
78
|
LLM_TYPE_290B,
|
|
78
79
|
LLM_TYPE_314B,
|
|
@@ -329,6 +330,9 @@ struct llama_model {
|
|
|
329
330
|
llama_hparams hparams = {};
|
|
330
331
|
llama_vocab vocab;
|
|
331
332
|
|
|
333
|
+
// for classifier models
|
|
334
|
+
std::vector<std::string> classifier_labels;
|
|
335
|
+
|
|
332
336
|
struct ggml_tensor * tok_embd = nullptr;
|
|
333
337
|
struct ggml_tensor * type_embd = nullptr;
|
|
334
338
|
struct ggml_tensor * pos_embd = nullptr;
|
|
@@ -585,7 +585,8 @@ static void llama_model_quantize_impl(const std::string & fname_inp, const std::
|
|
|
585
585
|
if (o.tag == LLAMA_KV_OVERRIDE_TYPE_FLOAT) {
|
|
586
586
|
gguf_set_val_f32(ctx_out.get(), o.key, o.val_f64);
|
|
587
587
|
} else if (o.tag == LLAMA_KV_OVERRIDE_TYPE_INT) {
|
|
588
|
-
|
|
588
|
+
// Setting type to UINT32. See https://github.com/ggml-org/llama.cpp/pull/14182 for context
|
|
589
|
+
gguf_set_val_u32(ctx_out.get(), o.key, (uint32_t)abs(o.val_i64));
|
|
589
590
|
} else if (o.tag == LLAMA_KV_OVERRIDE_TYPE_BOOL) {
|
|
590
591
|
gguf_set_val_bool(ctx_out.get(), o.key, o.val_bool);
|
|
591
592
|
} else if (o.tag == LLAMA_KV_OVERRIDE_TYPE_STR) {
|
|
@@ -798,7 +798,7 @@ static void llama_sampler_min_p_apply(struct llama_sampler * smpl, llama_token_d
|
|
|
798
798
|
}
|
|
799
799
|
|
|
800
800
|
// if we have enough values the operation was a success
|
|
801
|
-
if (filtered_tokens.size() >= ctx->min_keep) {
|
|
801
|
+
if (!filtered_tokens.empty() && filtered_tokens.size() >= ctx->min_keep) {
|
|
802
802
|
memcpy(cur_p->data, filtered_tokens.data(), filtered_tokens.size()*sizeof(llama_token_data));
|
|
803
803
|
cur_p->size = filtered_tokens.size();
|
|
804
804
|
min_p_applied = true;
|
|
@@ -909,7 +909,7 @@ static void llama_sampler_typical_apply(struct llama_sampler * smpl, llama_token
|
|
|
909
909
|
cum_sum += cur_p->data[idx].p;
|
|
910
910
|
|
|
911
911
|
// Check if the running sum is greater than typical or if we have kept at least min_keep tokens
|
|
912
|
-
if (cum_sum > ctx->p && i >= ctx->min_keep - 1) {
|
|
912
|
+
if (cum_sum > ctx->p && (ctx->min_keep == 0 || i >= ctx->min_keep - 1)) {
|
|
913
913
|
last_idx = i + 1;
|
|
914
914
|
break;
|
|
915
915
|
}
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
|
|
10
10
|
#include <algorithm>
|
|
11
11
|
#include <cassert>
|
|
12
|
+
#include <cctype>
|
|
12
13
|
#include <cfloat>
|
|
13
|
-
#include <climits>
|
|
14
14
|
#include <cstdarg>
|
|
15
15
|
#include <cstring>
|
|
16
16
|
#include <forward_list>
|
|
17
|
+
#include <limits>
|
|
17
18
|
#include <map>
|
|
18
19
|
#include <queue>
|
|
19
20
|
#include <set>
|
|
20
21
|
#include <unordered_map>
|
|
21
|
-
#include <cctype>
|
|
22
22
|
|
|
23
23
|
//
|
|
24
24
|
// helpers
|
|
@@ -835,7 +835,7 @@ struct llm_tokenizer_ugm_session {
|
|
|
835
835
|
}
|
|
836
836
|
|
|
837
837
|
// initialize score_sum to -FLT_MAX so it will be always lower than sums of token scores
|
|
838
|
-
std::vector<struct best_tokenization> tokenization_results(input_len + 1, {vocab.token_unk(), 0, -
|
|
838
|
+
std::vector<struct best_tokenization> tokenization_results(input_len + 1, {vocab.token_unk(), 0, -DBL_MAX});
|
|
839
839
|
// at the beginning tokenization score is zero
|
|
840
840
|
tokenization_results[0] = { vocab.token_unk(), 0, 0 };
|
|
841
841
|
|
|
@@ -867,7 +867,7 @@ struct llm_tokenizer_ugm_session {
|
|
|
867
867
|
const double challenger_score = current_best.score_sum + token_score;
|
|
868
868
|
struct best_tokenization & current_champ = tokenization_results[prefix_offset];
|
|
869
869
|
if (challenger_score > current_champ.score_sum) {
|
|
870
|
-
struct best_tokenization challenger = { token_id, input_offset,
|
|
870
|
+
struct best_tokenization challenger = { token_id, input_offset, challenger_score };
|
|
871
871
|
current_champ = challenger;
|
|
872
872
|
}
|
|
873
873
|
}
|
|
@@ -881,7 +881,7 @@ struct llm_tokenizer_ugm_session {
|
|
|
881
881
|
prefix_offset = input_offset + n_utf8_code_units;
|
|
882
882
|
struct best_tokenization & current_champ = tokenization_results[prefix_offset];
|
|
883
883
|
if (challenger_score > current_champ.score_sum) {
|
|
884
|
-
struct best_tokenization challenger = { vocab.token_unk(), input_offset,
|
|
884
|
+
struct best_tokenization challenger = { vocab.token_unk(), input_offset, challenger_score };
|
|
885
885
|
current_champ = challenger;
|
|
886
886
|
}
|
|
887
887
|
}
|
|
@@ -1007,7 +1007,7 @@ private:
|
|
|
1007
1007
|
struct best_tokenization {
|
|
1008
1008
|
llama_token token_id;
|
|
1009
1009
|
size_t input_offset;
|
|
1010
|
-
|
|
1010
|
+
double score_sum;
|
|
1011
1011
|
};
|
|
1012
1012
|
|
|
1013
1013
|
struct normalization_result normalize_prefix(const std::string & input, size_t input_offset) {
|
|
@@ -1269,6 +1269,7 @@ struct llama_vocab::impl {
|
|
|
1269
1269
|
bool add_space_prefix = false;
|
|
1270
1270
|
bool add_bos = false;
|
|
1271
1271
|
bool add_eos = false;
|
|
1272
|
+
bool add_sep = false;
|
|
1272
1273
|
bool ignore_merges = false;
|
|
1273
1274
|
bool clean_spaces = false; // clean_up_tokenization_spaces
|
|
1274
1275
|
bool remove_extra_whitespaces = false;
|
|
@@ -1421,6 +1422,8 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1421
1422
|
special_sep_id = 102;
|
|
1422
1423
|
special_pad_id = 0;
|
|
1423
1424
|
special_mask_id = 103;
|
|
1425
|
+
|
|
1426
|
+
add_sep = true;
|
|
1424
1427
|
} else if (tokenizer_model == "gpt2") {
|
|
1425
1428
|
type = LLAMA_VOCAB_TYPE_BPE;
|
|
1426
1429
|
|
|
@@ -1550,12 +1553,15 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1550
1553
|
tokenizer_pre == "jina-es" ||
|
|
1551
1554
|
tokenizer_pre == "jina-de" ||
|
|
1552
1555
|
tokenizer_pre == "gigachat" ||
|
|
1553
|
-
tokenizer_pre == "jina-v1-en" ||
|
|
1554
1556
|
tokenizer_pre == "jina-v2-es" ||
|
|
1555
|
-
tokenizer_pre == "jina-v2-de"
|
|
1557
|
+
tokenizer_pre == "jina-v2-de") {
|
|
1558
|
+
pre_type = LLAMA_VOCAB_PRE_TYPE_GPT2;
|
|
1559
|
+
} else if (
|
|
1560
|
+
tokenizer_pre == "jina-v1-en" ||
|
|
1556
1561
|
tokenizer_pre == "jina-v2-code" ||
|
|
1557
1562
|
tokenizer_pre == "roberta-bpe") {
|
|
1558
1563
|
pre_type = LLAMA_VOCAB_PRE_TYPE_GPT2;
|
|
1564
|
+
add_sep = true;
|
|
1559
1565
|
} else if (
|
|
1560
1566
|
tokenizer_pre == "refact") {
|
|
1561
1567
|
pre_type = LLAMA_VOCAB_PRE_TYPE_REFACT;
|
|
@@ -1665,6 +1671,7 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1665
1671
|
clean_spaces = true;
|
|
1666
1672
|
add_bos = true;
|
|
1667
1673
|
add_eos = false;
|
|
1674
|
+
add_sep = true;
|
|
1668
1675
|
} else if (type == LLAMA_VOCAB_TYPE_UGM) {
|
|
1669
1676
|
pre_type = LLAMA_VOCAB_PRE_TYPE_DEFAULT;
|
|
1670
1677
|
add_bos = false;
|
|
@@ -1801,7 +1808,7 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1801
1808
|
}
|
|
1802
1809
|
}
|
|
1803
1810
|
|
|
1804
|
-
// Handle add_bos and
|
|
1811
|
+
// Handle add_bos, add_eos and add_sep
|
|
1805
1812
|
{
|
|
1806
1813
|
bool temp = true;
|
|
1807
1814
|
|
|
@@ -1811,6 +1818,9 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1811
1818
|
if (ml.get_key(LLM_KV_TOKENIZER_ADD_EOS, temp, false)) {
|
|
1812
1819
|
add_eos = temp;
|
|
1813
1820
|
}
|
|
1821
|
+
if (ml.get_key(LLM_KV_TOKENIZER_ADD_SEP, temp, false)) {
|
|
1822
|
+
add_sep = temp;
|
|
1823
|
+
}
|
|
1814
1824
|
}
|
|
1815
1825
|
|
|
1816
1826
|
// auto-detect special tokens by text
|
|
@@ -1987,6 +1997,7 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
1987
1997
|
|| t.first == "<|eom_id|>"
|
|
1988
1998
|
|| t.first == "<EOT>"
|
|
1989
1999
|
|| t.first == "_<EOT>"
|
|
2000
|
+
|| t.first == "<|end_of_text|>"
|
|
1990
2001
|
) {
|
|
1991
2002
|
special_eog_ids.insert(t.second);
|
|
1992
2003
|
if ((id_to_token[t.second].attr & LLAMA_TOKEN_ATTR_CONTROL) == 0) {
|
|
@@ -2059,9 +2070,9 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
2059
2070
|
//NOTE: Per token attributes are missing from the GGUF file.
|
|
2060
2071
|
//TODO: Extract attributes from GGUF file.
|
|
2061
2072
|
{
|
|
2062
|
-
auto _contains_any = [] (const std::string & str, const std::vector<std::
|
|
2073
|
+
auto _contains_any = [] (const std::string & str, const std::vector<std::string_view> & substrs) -> bool {
|
|
2063
2074
|
for (const auto & substr : substrs) {
|
|
2064
|
-
if (str.find(substr)
|
|
2075
|
+
if (str.find(substr) != std::string::npos) {
|
|
2065
2076
|
return true;
|
|
2066
2077
|
}
|
|
2067
2078
|
}
|
|
@@ -2080,9 +2091,11 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
2080
2091
|
|
|
2081
2092
|
std::string model_name;
|
|
2082
2093
|
std::string tokenizer_pre;
|
|
2094
|
+
std::string general_arch;
|
|
2083
2095
|
|
|
2084
2096
|
ml.get_key(LLM_KV_GENERAL_NAME, model_name, false);
|
|
2085
2097
|
ml.get_key(LLM_KV_TOKENIZER_PRE, tokenizer_pre, false);
|
|
2098
|
+
ml.get_key(LLM_KV_GENERAL_ARCHITECTURE, general_arch, false);
|
|
2086
2099
|
|
|
2087
2100
|
// model name to lowercase
|
|
2088
2101
|
std::transform(model_name.begin(), model_name.end(), model_name.begin(),
|
|
@@ -2091,9 +2104,16 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
|
|
2091
2104
|
}
|
|
2092
2105
|
);
|
|
2093
2106
|
|
|
2094
|
-
// set attributes by model/tokenizer name
|
|
2095
|
-
if (
|
|
2096
|
-
|
|
2107
|
+
// set attributes by model/tokenizer/architecture name
|
|
2108
|
+
if (false
|
|
2109
|
+
|| _contains_any(tokenizer_pre, {"jina-v2-de", "jina-v2-es", "jina-v2-code"})
|
|
2110
|
+
|| _contains_any(general_arch, {"nomic-bert-moe"})
|
|
2111
|
+
) {
|
|
2112
|
+
if (token_to_id.count("<mask>") == 0) {
|
|
2113
|
+
LLAMA_LOG_WARN("%s: Mask token is missing in vocab, please reconvert model!\n", __func__);
|
|
2114
|
+
} else {
|
|
2115
|
+
_set_token_attr("<mask>", LLAMA_TOKEN_ATTR_LSTRIP, true);
|
|
2116
|
+
}
|
|
2097
2117
|
} else if (_contains_any(model_name, {"phi-3", "phi3"})) {
|
|
2098
2118
|
for (auto id : cache_special_tokens) {
|
|
2099
2119
|
_set_tokenid_attr(id, LLAMA_TOKEN_ATTR_RSTRIP, true);
|
|
@@ -2563,6 +2583,10 @@ int32_t llama_vocab::impl::token_to_piece(llama_token token, char * buf, int32_t
|
|
|
2563
2583
|
// copy piece chars to output text buffer
|
|
2564
2584
|
// skip up to 'lstrip' leading spaces before copying
|
|
2565
2585
|
auto _try_copy = [=] (const char * token, size_t size) -> int32_t {
|
|
2586
|
+
if (size >= static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
|
|
2587
|
+
GGML_ABORT("invalid token size: %zu exceeds int32_t limit", size);
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2566
2590
|
for (int32_t i = 0; i < lstrip && size && *token == ' '; ++i) {
|
|
2567
2591
|
token++;
|
|
2568
2592
|
size--;
|
|
@@ -2759,26 +2783,26 @@ void llama_vocab::impl::print_info() const {
|
|
|
2759
2783
|
LLAMA_LOG_INFO("%s: n_merges = %u\n", __func__, (uint32_t) bpe_ranks.size());
|
|
2760
2784
|
|
|
2761
2785
|
// special tokens
|
|
2762
|
-
if (special_bos_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: BOS token = %d '%s'\n", __func__, special_bos_id, id_to_token
|
|
2763
|
-
if (special_eos_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOS token = %d '%s'\n", __func__, special_eos_id, id_to_token
|
|
2764
|
-
if (special_eot_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOT token = %d '%s'\n", __func__, special_eot_id, id_to_token
|
|
2765
|
-
if (special_eom_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOM token = %d '%s'\n", __func__, special_eom_id, id_to_token
|
|
2766
|
-
if (special_unk_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: UNK token = %d '%s'\n", __func__, special_unk_id, id_to_token
|
|
2767
|
-
if (special_sep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: SEP token = %d '%s'\n", __func__, special_sep_id, id_to_token
|
|
2768
|
-
if (special_pad_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: PAD token = %d '%s'\n", __func__, special_pad_id, id_to_token
|
|
2769
|
-
if (special_mask_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: MASK token = %d '%s'\n", __func__, special_mask_id, id_to_token
|
|
2770
|
-
|
|
2771
|
-
if (linefeed_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: LF token = %d '%s'\n", __func__, linefeed_id, id_to_token
|
|
2772
|
-
|
|
2773
|
-
if (special_fim_pre_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM PRE token = %d '%s'\n", __func__, special_fim_pre_id, id_to_token
|
|
2774
|
-
if (special_fim_suf_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM SUF token = %d '%s'\n", __func__, special_fim_suf_id, id_to_token
|
|
2775
|
-
if (special_fim_mid_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM MID token = %d '%s'\n", __func__, special_fim_mid_id, id_to_token
|
|
2776
|
-
if (special_fim_pad_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM PAD token = %d '%s'\n", __func__, special_fim_pad_id, id_to_token
|
|
2777
|
-
if (special_fim_rep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM REP token = %d '%s'\n", __func__, special_fim_rep_id, id_to_token
|
|
2778
|
-
if (special_fim_sep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM SEP token = %d '%s'\n", __func__, special_fim_sep_id, id_to_token
|
|
2786
|
+
if (special_bos_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: BOS token = %d '%s'\n", __func__, special_bos_id, id_to_token.at(special_bos_id).text.c_str() ); }
|
|
2787
|
+
if (special_eos_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOS token = %d '%s'\n", __func__, special_eos_id, id_to_token.at(special_eos_id).text.c_str() ); }
|
|
2788
|
+
if (special_eot_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOT token = %d '%s'\n", __func__, special_eot_id, id_to_token.at(special_eot_id).text.c_str() ); }
|
|
2789
|
+
if (special_eom_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: EOM token = %d '%s'\n", __func__, special_eom_id, id_to_token.at(special_eom_id).text.c_str() ); }
|
|
2790
|
+
if (special_unk_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: UNK token = %d '%s'\n", __func__, special_unk_id, id_to_token.at(special_unk_id).text.c_str() ); }
|
|
2791
|
+
if (special_sep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: SEP token = %d '%s'\n", __func__, special_sep_id, id_to_token.at(special_sep_id).text.c_str() ); }
|
|
2792
|
+
if (special_pad_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: PAD token = %d '%s'\n", __func__, special_pad_id, id_to_token.at(special_pad_id).text.c_str() ); }
|
|
2793
|
+
if (special_mask_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: MASK token = %d '%s'\n", __func__, special_mask_id, id_to_token.at(special_mask_id).text.c_str() ); }
|
|
2794
|
+
|
|
2795
|
+
if (linefeed_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: LF token = %d '%s'\n", __func__, linefeed_id, id_to_token.at(linefeed_id).text.c_str() ); }
|
|
2796
|
+
|
|
2797
|
+
if (special_fim_pre_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM PRE token = %d '%s'\n", __func__, special_fim_pre_id, id_to_token.at(special_fim_pre_id).text.c_str() ); }
|
|
2798
|
+
if (special_fim_suf_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM SUF token = %d '%s'\n", __func__, special_fim_suf_id, id_to_token.at(special_fim_suf_id).text.c_str() ); }
|
|
2799
|
+
if (special_fim_mid_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM MID token = %d '%s'\n", __func__, special_fim_mid_id, id_to_token.at(special_fim_mid_id).text.c_str() ); }
|
|
2800
|
+
if (special_fim_pad_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM PAD token = %d '%s'\n", __func__, special_fim_pad_id, id_to_token.at(special_fim_pad_id).text.c_str() ); }
|
|
2801
|
+
if (special_fim_rep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM REP token = %d '%s'\n", __func__, special_fim_rep_id, id_to_token.at(special_fim_rep_id).text.c_str() ); }
|
|
2802
|
+
if (special_fim_sep_id != LLAMA_TOKEN_NULL) { LLAMA_LOG_INFO( "%s: FIM SEP token = %d '%s'\n", __func__, special_fim_sep_id, id_to_token.at(special_fim_sep_id).text.c_str() ); }
|
|
2779
2803
|
|
|
2780
2804
|
for (const auto & id : special_eog_ids) {
|
|
2781
|
-
LLAMA_LOG_INFO( "%s: EOG token = %d '%s'\n", __func__, id, id_to_token
|
|
2805
|
+
LLAMA_LOG_INFO( "%s: EOG token = %d '%s'\n", __func__, id, id_to_token.at(id).text.c_str() );
|
|
2782
2806
|
}
|
|
2783
2807
|
|
|
2784
2808
|
LLAMA_LOG_INFO("%s: max token length = %d\n", __func__, max_token_len);
|
|
@@ -2986,6 +3010,10 @@ bool llama_vocab::get_add_eos() const {
|
|
|
2986
3010
|
return pimpl->add_eos;
|
|
2987
3011
|
}
|
|
2988
3012
|
|
|
3013
|
+
bool llama_vocab::get_add_sep() const {
|
|
3014
|
+
return pimpl->add_sep;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
2989
3017
|
bool llama_vocab::get_ignore_merges() const {
|
|
2990
3018
|
return pimpl->ignore_merges;
|
|
2991
3019
|
}
|
|
@@ -3046,6 +3074,11 @@ int32_t llama_vocab::tokenize(
|
|
|
3046
3074
|
bool add_special,
|
|
3047
3075
|
bool parse_special) const {
|
|
3048
3076
|
auto res = tokenize(std::string(text, text_len), add_special, parse_special);
|
|
3077
|
+
if (res.size() >= static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
|
|
3078
|
+
LLAMA_LOG_ERROR("%s: tokenization result size %zu exceeds int32_t limit\n", __func__, res.size());
|
|
3079
|
+
return std::numeric_limits<int32_t>::min();
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3049
3082
|
if (n_tokens_max < (int) res.size()) {
|
|
3050
3083
|
// LLAMA_LOG_ERROR("%s: too many tokens\n", __func__);
|
|
3051
3084
|
return -((int) res.size());
|
|
@@ -3177,6 +3210,10 @@ bool llama_vocab_get_add_eos(const struct llama_vocab * vocab) {
|
|
|
3177
3210
|
return vocab->get_add_eos();
|
|
3178
3211
|
}
|
|
3179
3212
|
|
|
3213
|
+
bool llama_vocab_get_add_sep(const struct llama_vocab * vocab) {
|
|
3214
|
+
return vocab->get_add_sep();
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3180
3217
|
llama_token llama_vocab_fim_pre(const struct llama_vocab * vocab) {
|
|
3181
3218
|
return vocab->token_fim_pre();
|
|
3182
3219
|
}
|
|
@@ -74,6 +74,7 @@ struct llama_vocab {
|
|
|
74
74
|
bool get_add_space_prefix () const;
|
|
75
75
|
bool get_add_bos () const;
|
|
76
76
|
bool get_add_eos () const;
|
|
77
|
+
bool get_add_sep () const;
|
|
77
78
|
bool get_ignore_merges () const;
|
|
78
79
|
bool get_clean_spaces () const;
|
|
79
80
|
bool get_remove_extra_whitespaces () const;
|
|
@@ -198,14 +198,18 @@ static struct llama_model * llama_model_load_from_file_impl(
|
|
|
198
198
|
|
|
199
199
|
// if using single GPU mode, remove all except the main GPU
|
|
200
200
|
if (params.split_mode == LLAMA_SPLIT_MODE_NONE) {
|
|
201
|
-
if (params.main_gpu < 0
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
if (params.main_gpu < 0) {
|
|
202
|
+
model->devices.clear();
|
|
203
|
+
} else {
|
|
204
|
+
if (params.main_gpu >= (int)model->devices.size()) {
|
|
205
|
+
LLAMA_LOG_ERROR("%s: invalid value for main_gpu: %d (available devices: %zu)\n", __func__, params.main_gpu, model->devices.size());
|
|
206
|
+
llama_model_free(model);
|
|
207
|
+
return nullptr;
|
|
208
|
+
}
|
|
209
|
+
ggml_backend_dev_t main_gpu = model->devices[params.main_gpu];
|
|
210
|
+
model->devices.clear();
|
|
211
|
+
model->devices.push_back(main_gpu);
|
|
205
212
|
}
|
|
206
|
-
ggml_backend_dev_t main_gpu = model->devices[params.main_gpu];
|
|
207
|
-
model->devices.clear();
|
|
208
|
-
model->devices.push_back(main_gpu);
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
for (auto * dev : model->devices) {
|
|
@@ -204,12 +204,17 @@ static inline std::wstring unicode_wstring_from_utf8(const std::string & s) {
|
|
|
204
204
|
// disable C++17 deprecation warning for std::codecvt_utf8
|
|
205
205
|
# pragma clang diagnostic push
|
|
206
206
|
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
207
|
+
#elif defined(__GNUC__)
|
|
208
|
+
# pragma GCC diagnostic push
|
|
209
|
+
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
207
210
|
#endif
|
|
208
211
|
|
|
209
212
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
|
|
210
213
|
|
|
211
214
|
#if defined(__clang__)
|
|
212
215
|
# pragma clang diagnostic pop
|
|
216
|
+
#elif defined(__GNUC__)
|
|
217
|
+
# pragma GCC diagnostic pop
|
|
213
218
|
#endif
|
|
214
219
|
|
|
215
220
|
return conv.from_bytes(s);
|