@@ -493,7 +493,7 @@ std::string string_from(const struct llama_context * ctx, const std::vector<llam
493
493
first = false ;
494
494
}
495
495
496
- auto detokenized = llama_token_to_piece (ctx, token);
496
+ auto detokenized = common_token_to_piece (ctx, token);
497
497
498
498
detokenized.erase (
499
499
std::remove_if (
@@ -524,7 +524,7 @@ std::string string_from(const struct llama_context * ctx, const struct llama_bat
524
524
first = false ;
525
525
}
526
526
527
- auto detokenized = llama_token_to_piece (ctx, batch.token [i]);
527
+ auto detokenized = common_token_to_piece (ctx, batch.token [i]);
528
528
529
529
detokenized.erase (
530
530
std::remove_if (
@@ -819,16 +819,16 @@ std::string fs_get_cache_file(const std::string & filename) {
819
819
//
820
820
// Model utils
821
821
//
822
- struct llama_init_result llama_init_from_gpt_params (gpt_params & params) {
823
- llama_init_result iparams;
824
- auto mparams = llama_model_params_from_gpt_params (params);
822
+ struct common_init_result llama_init_from_gpt_params (gpt_params & params) {
823
+ common_init_result iparams;
824
+ auto mparams = common_model_params_from_gpt_params (params);
825
825
826
826
llama_model * model = nullptr ;
827
827
828
828
if (!params.hf_repo .empty () && !params.hf_file .empty ()) {
829
- model = llama_load_model_from_hf (params.hf_repo .c_str (), params.hf_file .c_str (), params.model .c_str (), params.hf_token .c_str (), mparams);
829
+ model = common_load_model_from_hf (params.hf_repo .c_str (), params.hf_file .c_str (), params.model .c_str (), params.hf_token .c_str (), mparams);
830
830
} else if (!params.model_url .empty ()) {
831
- model = llama_load_model_from_url (params.model_url .c_str (), params.model .c_str (), params.hf_token .c_str (), mparams);
831
+ model = common_load_model_from_url (params.model_url .c_str (), params.model .c_str (), params.hf_token .c_str (), mparams);
832
832
} else {
833
833
model = llama_load_model_from_file (params.model .c_str (), mparams);
834
834
}
@@ -863,7 +863,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
863
863
}
864
864
}
865
865
866
- auto cparams = llama_context_params_from_gpt_params (params);
866
+ auto cparams = common_context_params_from_gpt_params (params);
867
867
868
868
llama_context * lctx = llama_new_context_with_model (model, cparams);
869
869
if (lctx == NULL ) {
@@ -900,7 +900,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
900
900
901
901
// load and optionally apply lora adapters
902
902
for (auto & la : params.lora_adapters ) {
903
- llama_lora_adapter_container loaded_la;
903
+ common_lora_adapter_container loaded_la;
904
904
loaded_la.path = la.path ;
905
905
loaded_la.scale = la.scale ;
906
906
loaded_la.adapter = llama_lora_adapter_init (model, la.path .c_str ());
@@ -913,7 +913,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
913
913
iparams.lora_adapters .push_back (loaded_la); // copy to list of loaded adapters
914
914
}
915
915
if (!params.lora_init_without_apply ) {
916
- llama_lora_adapters_apply (lctx, iparams.lora_adapters );
916
+ common_lora_adapters_apply (lctx, iparams.lora_adapters );
917
917
}
918
918
919
919
if (params.sparams .ignore_eos && llama_token_eos (model) == LLAMA_TOKEN_NULL) {
@@ -961,7 +961,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
961
961
return iparams;
962
962
}
963
963
964
- void llama_lora_adapters_apply (struct llama_context * ctx, std::vector<llama_lora_adapter_container > & lora_adapters) {
964
+ void common_lora_adapters_apply (struct llama_context * ctx, std::vector<common_lora_adapter_container > & lora_adapters) {
965
965
llama_lora_adapter_clear (ctx);
966
966
for (auto & la : lora_adapters) {
967
967
if (la.scale != 0 .0f ) {
@@ -970,7 +970,7 @@ void llama_lora_adapters_apply(struct llama_context * ctx, std::vector<llama_lor
970
970
}
971
971
}
972
972
973
- struct llama_model_params llama_model_params_from_gpt_params (const gpt_params & params) {
973
+ struct llama_model_params common_model_params_from_gpt_params (const gpt_params & params) {
974
974
auto mparams = llama_model_default_params ();
975
975
976
976
if (params.n_gpu_layers != -1 ) {
@@ -1022,7 +1022,7 @@ static ggml_type kv_cache_type_from_str(const std::string & s) {
1022
1022
throw std::runtime_error (" Invalid cache type: " + s);
1023
1023
}
1024
1024
1025
- struct llama_context_params llama_context_params_from_gpt_params (const gpt_params & params) {
1025
+ struct llama_context_params common_context_params_from_gpt_params (const gpt_params & params) {
1026
1026
auto cparams = llama_context_default_params ();
1027
1027
1028
1028
cparams.n_ctx = params.n_ctx ;
@@ -1430,7 +1430,7 @@ struct llama_model * llama_load_model_from_hf(
1430
1430
1431
1431
#else
1432
1432
1433
- struct llama_model * llama_load_model_from_url (
1433
+ struct llama_model * common_load_model_from_url (
1434
1434
const char * /* model_url*/ ,
1435
1435
const char * /* path_model*/ ,
1436
1436
const char * /* hf_token*/ ,
@@ -1439,7 +1439,7 @@ struct llama_model * llama_load_model_from_url(
1439
1439
return nullptr ;
1440
1440
}
1441
1441
1442
- struct llama_model * llama_load_model_from_hf (
1442
+ struct llama_model * common_load_model_from_hf (
1443
1443
const char * /* repo*/ ,
1444
1444
const char * /* model*/ ,
1445
1445
const char * /* path_model*/ ,
@@ -1455,11 +1455,11 @@ struct llama_model * llama_load_model_from_hf(
1455
1455
// Batch utils
1456
1456
//
1457
1457
1458
- void llama_batch_clear (struct llama_batch & batch) {
1458
+ void common_batch_clear (struct llama_batch & batch) {
1459
1459
batch.n_tokens = 0 ;
1460
1460
}
1461
1461
1462
- void llama_batch_add (
1462
+ void common_batch_add (
1463
1463
struct llama_batch & batch,
1464
1464
llama_token id,
1465
1465
llama_pos pos,
@@ -1482,15 +1482,15 @@ void llama_batch_add(
1482
1482
// Vocab utils
1483
1483
//
1484
1484
1485
- std::vector<llama_token> llama_tokenize (
1485
+ std::vector<llama_token> common_tokenize (
1486
1486
const struct llama_context * ctx,
1487
1487
const std::string & text,
1488
1488
bool add_special,
1489
1489
bool parse_special) {
1490
- return llama_tokenize (llama_get_model (ctx), text, add_special, parse_special);
1490
+ return common_tokenize (llama_get_model (ctx), text, add_special, parse_special);
1491
1491
}
1492
1492
1493
- std::vector<llama_token> llama_tokenize (
1493
+ std::vector<llama_token> common_tokenize (
1494
1494
const struct llama_model * model,
1495
1495
const std::string & text,
1496
1496
bool add_special,
@@ -1509,7 +1509,7 @@ std::vector<llama_token> llama_tokenize(
1509
1509
return result;
1510
1510
}
1511
1511
1512
- std::string llama_token_to_piece (const struct llama_context * ctx, llama_token token, bool special) {
1512
+ std::string common_token_to_piece (const struct llama_context * ctx, llama_token token, bool special) {
1513
1513
std::string piece;
1514
1514
piece.resize (piece.capacity ()); // using string internal cache, 15 bytes + '\n'
1515
1515
const int n_chars = llama_token_to_piece (llama_get_model (ctx), token, &piece[0 ], piece.size (), 0 , special);
@@ -1525,7 +1525,7 @@ std::string llama_token_to_piece(const struct llama_context * ctx, llama_token t
1525
1525
return piece;
1526
1526
}
1527
1527
1528
- std::string llama_detokenize (llama_context * ctx, const std::vector<llama_token> & tokens, bool special) {
1528
+ std::string common_detokenize (llama_context * ctx, const std::vector<llama_token> & tokens, bool special) {
1529
1529
std::string text;
1530
1530
text.resize (std::max (text.capacity (), tokens.size ()));
1531
1531
int32_t n_chars = llama_detokenize (llama_get_model (ctx), tokens.data (), (int32_t )tokens.size (), &text[0 ], (int32_t )text.size (), false , special);
@@ -1551,9 +1551,9 @@ bool llama_chat_verify_template(const std::string & tmpl) {
1551
1551
return res >= 0 ;
1552
1552
}
1553
1553
1554
- std::string llama_chat_apply_template (const struct llama_model * model,
1554
+ std::string common_chat_apply_template (const struct llama_model * model,
1555
1555
const std::string & tmpl,
1556
- const std::vector<llama_chat_msg > & msgs,
1556
+ const std::vector<common_chat_msg > & msgs,
1557
1557
bool add_ass) {
1558
1558
int alloc_size = 0 ;
1559
1559
bool fallback = false ; // indicate if we must fallback to default chatml
@@ -1595,42 +1595,42 @@ std::string llama_chat_apply_template(const struct llama_model * model,
1595
1595
return formatted_chat;
1596
1596
}
1597
1597
1598
- std::string llama_chat_format_single (const struct llama_model * model,
1598
+ std::string common_chat_format_single (const struct llama_model * model,
1599
1599
const std::string & tmpl,
1600
- const std::vector<llama_chat_msg > & past_msg,
1601
- const llama_chat_msg & new_msg,
1600
+ const std::vector<common_chat_msg > & past_msg,
1601
+ const common_chat_msg & new_msg,
1602
1602
bool add_ass) {
1603
1603
std::ostringstream ss;
1604
- auto fmt_past_msg = past_msg.empty () ? " " : llama_chat_apply_template (model, tmpl, past_msg, false );
1605
- std::vector<llama_chat_msg > chat_new (past_msg);
1604
+ auto fmt_past_msg = past_msg.empty () ? " " : common_chat_apply_template (model, tmpl, past_msg, false );
1605
+ std::vector<common_chat_msg > chat_new (past_msg);
1606
1606
// if the past_msg ends with a newline, we must preserve it in the formatted version
1607
1607
if (add_ass && !fmt_past_msg.empty () && fmt_past_msg.back () == ' \n ' ) {
1608
1608
ss << " \n " ;
1609
1609
};
1610
1610
// format chat with new_msg
1611
1611
chat_new.push_back (new_msg);
1612
- auto fmt_new_msg = llama_chat_apply_template (model, tmpl, chat_new, add_ass);
1612
+ auto fmt_new_msg = common_chat_apply_template (model, tmpl, chat_new, add_ass);
1613
1613
// get the diff part
1614
1614
ss << fmt_new_msg.substr (fmt_past_msg.size (), fmt_new_msg.size () - fmt_past_msg.size ());
1615
1615
return ss.str ();
1616
1616
}
1617
1617
1618
- std::string llama_chat_format_example (const struct llama_model * model,
1618
+ std::string common_chat_format_example (const struct llama_model * model,
1619
1619
const std::string & tmpl) {
1620
- std::vector<llama_chat_msg > msgs = {
1620
+ std::vector<common_chat_msg > msgs = {
1621
1621
{" system" , " You are a helpful assistant" },
1622
1622
{" user" , " Hello" },
1623
1623
{" assistant" , " Hi there" },
1624
1624
{" user" , " How are you?" },
1625
1625
};
1626
- return llama_chat_apply_template (model, tmpl, msgs, true );
1626
+ return common_chat_apply_template (model, tmpl, msgs, true );
1627
1627
}
1628
1628
1629
1629
//
1630
1630
// KV cache utils
1631
1631
//
1632
1632
1633
- void llama_kv_cache_dump_view (const llama_kv_cache_view & view, int row_size) {
1633
+ void common_kv_cache_dump_view (const llama_kv_cache_view & view, int row_size) {
1634
1634
static const char slot_chars[] = " .123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+" ;
1635
1635
1636
1636
printf (" === Dumping KV cache. total cells %d, max sequences per cell %d, populated cells %d, total tokens in cache %d, largest empty slot=%d @ %d" ,
@@ -1653,7 +1653,7 @@ void llama_kv_cache_dump_view(const llama_kv_cache_view & view, int row_size) {
1653
1653
printf (" \n === Done dumping\n " );
1654
1654
}
1655
1655
1656
- void llama_kv_cache_dump_view_seqs (const llama_kv_cache_view & view, int row_size) {
1656
+ void common_kv_cache_dump_view_seqs (const llama_kv_cache_view & view, int row_size) {
1657
1657
static const char slot_chars[] = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
1658
1658
1659
1659
printf (" === Dumping KV cache. total cells %d, max sequences per cell %d, populated cells %d, total tokens in cache %d, largest empty slot=%d @ %d\n " ,
@@ -1705,7 +1705,7 @@ void llama_kv_cache_dump_view_seqs(const llama_kv_cache_view & view, int row_siz
1705
1705
// Embedding utils
1706
1706
//
1707
1707
1708
- void llama_embd_normalize (const float * inp, float * out, int n, int embd_norm) {
1708
+ void common_embd_normalize (const float * inp, float * out, int n, int embd_norm) {
1709
1709
double sum = 0.0 ;
1710
1710
1711
1711
switch (embd_norm) {
@@ -1739,7 +1739,7 @@ void llama_embd_normalize(const float * inp, float * out, int n, int embd_norm)
1739
1739
}
1740
1740
}
1741
1741
1742
- float llama_embd_similarity_cos (const float * embd1, const float * embd2, int n){
1742
+ float common_embd_similarity_cos (const float * embd1, const float * embd2, int n){
1743
1743
double sum = 0.0 ;
1744
1744
double sum1 = 0.0 ;
1745
1745
double sum2 = 0.0 ;
@@ -1765,8 +1765,8 @@ float llama_embd_similarity_cos(const float * embd1, const float * embd2, int n)
1765
1765
// Control vector utils
1766
1766
//
1767
1767
1768
- static llama_control_vector_data llama_control_vector_load_one (const llama_control_vector_load_info & load_info) {
1769
- llama_control_vector_data result = { -1 , {} };
1768
+ static common_control_vector_data llama_control_vector_load_one (const common_control_vector_load_info & load_info) {
1769
+ common_control_vector_data result = { -1 , {} };
1770
1770
1771
1771
ggml_context * ctx = nullptr ;
1772
1772
struct gguf_init_params meta_gguf_params = {
@@ -1850,8 +1850,8 @@ static llama_control_vector_data llama_control_vector_load_one(const llama_contr
1850
1850
return result;
1851
1851
}
1852
1852
1853
- llama_control_vector_data llama_control_vector_load (const std::vector<llama_control_vector_load_info > & load_infos) {
1854
- llama_control_vector_data result = { -1 , {} };
1853
+ common_control_vector_data llama_control_vector_load (const std::vector<common_control_vector_load_info > & load_infos) {
1854
+ common_control_vector_data result = { -1 , {} };
1855
1855
1856
1856
for (const auto & info : load_infos) {
1857
1857
auto cur = llama_control_vector_load_one (info);
0 commit comments