Skip to content

Commit eb5f516

Browse files
committed
update to b4958
- quick test on new update cycle with copy script to see how painful updates are - NB: remember to delete your project dlls to sync to latest
1 parent a0420bc commit eb5f516

File tree

8 files changed

+120
-31
lines changed

8 files changed

+120
-31
lines changed

Llama.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "0.9.2",
4+
"VersionName": "0.9.3",
55
"FriendlyName": "Llama",
66
"Description": "Llama.cpp plugin for large language model (LLM) inference.",
77
"Category": "LLM",

Source/LlamaCore/Private/Internal/LlamaInternal.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int32 FLlamaInternal::UsedContext()
273273
{
274274
if (Context)
275275
{
276-
return llama_get_kv_cache_used_cells(Context);
276+
return llama_kv_self_used_cells(Context);
277277
}
278278
else
279279
{
@@ -313,7 +313,7 @@ void FLlamaInternal::ResetContextHistory(bool bKeepSystemsPrompt)
313313
ContextHistory.clear();
314314
Messages.clear();
315315

316-
llama_kv_cache_clear(Context);
316+
llama_kv_self_clear(Context);
317317
FilledContextCharLength = 0;
318318
}
319319

@@ -322,7 +322,7 @@ void FLlamaInternal::RollbackContextHistoryByTokens(int32 NTokensToErase)
322322
// clear the last n_regen tokens from the KV cache and update n_past
323323
int32 TokensUsed = llama_get_kv_cache_used_cells(Context); //FilledContextCharLength
324324

325-
llama_kv_cache_seq_rm(Context, 0, TokensUsed - NTokensToErase, -1);
325+
llama_kv_self_seq_rm(Context, 0, TokensUsed - NTokensToErase, -1);
326326

327327
//FilledContextCharLength -= NTokensToErase;
328328

@@ -442,7 +442,7 @@ int32 FLlamaInternal::ProcessPrompt(const std::string& Prompt, EChatTemplateRole
442442

443443
//Grab vocab
444444
const llama_vocab* Vocab = llama_model_get_vocab(LlamaModel);
445-
const bool IsFirst = llama_get_kv_cache_used_cells(Context) == 0;
445+
const bool IsFirst = llama_kv_self_used_cells(Context) == 0;
446446

447447
// tokenize the prompt
448448
const int NPromptTokens = -llama_tokenize(Vocab, Prompt.c_str(), Prompt.size(), NULL, 0, IsFirst, true);
@@ -461,7 +461,7 @@ int32 FLlamaInternal::ProcessPrompt(const std::string& Prompt, EChatTemplateRole
461461

462462
//check sizing before running prompt decode
463463
int NContext = llama_n_ctx(Context);
464-
int NContextUsed = llama_get_kv_cache_used_cells(Context);
464+
int NContextUsed = llama_kv_self_used_cells(Context);
465465

466466
if (NContextUsed + NPromptTokens > NContext)
467467
{
@@ -506,7 +506,7 @@ int32 FLlamaInternal::ProcessPrompt(const std::string& Prompt, EChatTemplateRole
506506

507507
// Check context before running decode
508508
int NContext = llama_n_ctx(Context);
509-
int NContextUsed = llama_get_kv_cache_used_cells(Context);
509+
int NContextUsed = llama_kv_self_used_cells(Context);
510510

511511
if (NContextUsed + BatchTokens.size() > NContext)
512512
{
@@ -563,7 +563,7 @@ std::string FLlamaInternal::Generate(const std::string& Prompt, bool bAppendToMe
563563

564564
// check if we have enough space in the context to evaluate this batch - might need to be inside loop
565565
int NContext = llama_n_ctx(Context);
566-
int NContextUsed = llama_get_kv_cache_used_cells(Context);
566+
int NContextUsed = llama_kv_self_used_cells(Context);
567567
bool bEOGExit = false;
568568

569569
while (bGenerationActive) //processing can be aborted by flipping the boolean

ThirdParty/LlamaCpp/Include/common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using llama_tokens = std::vector<llama_token>;
3636

3737
// build info
3838
int LLAMA_BUILD_NUMBER = 0;
39-
const char* LLAMA_COMMIT = "f08f4b3187b691bb08a8884ed39ebaa94e956707";
39+
const char* LLAMA_COMMIT = "ef19c71769681a0b3dde6bc90911728376e5d236";
4040
const char* LLAMA_COMPILER = "";
4141
const char* LLAMA_BUILD_TARGET = "Vulkan - Unreal";
4242

ThirdParty/LlamaCpp/Include/ggml.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ extern "C" {
454454
GGML_OP_RMS_NORM,
455455
GGML_OP_RMS_NORM_BACK,
456456
GGML_OP_GROUP_NORM,
457+
GGML_OP_L2_NORM,
457458

458459
GGML_OP_MUL_MAT,
459460
GGML_OP_MUL_MAT_ID,
@@ -502,6 +503,7 @@ extern "C" {
502503
GGML_OP_ADD_REL_POS,
503504
GGML_OP_RWKV_WKV6,
504505
GGML_OP_GATED_LINEAR_ATTN,
506+
GGML_OP_RWKV_WKV7,
505507

506508
GGML_OP_UNARY,
507509

@@ -1095,6 +1097,18 @@ extern "C" {
10951097
int n_groups,
10961098
float eps);
10971099

1100+
// l2 normalize along rows
1101+
// used in rwkv v7
1102+
GGML_API struct ggml_tensor * ggml_l2_norm(
1103+
struct ggml_context * ctx,
1104+
struct ggml_tensor * a,
1105+
float eps);
1106+
1107+
GGML_API struct ggml_tensor * ggml_l2_norm_inplace(
1108+
struct ggml_context * ctx,
1109+
struct ggml_tensor * a,
1110+
float eps);
1111+
10981112
// a - x
10991113
// b - dy
11001114
GGML_API struct ggml_tensor * ggml_rms_norm_back(
@@ -1890,6 +1904,16 @@ extern "C" {
18901904
struct ggml_tensor * state,
18911905
float scale);
18921906

1907+
GGML_API struct ggml_tensor * ggml_rwkv_wkv7(
1908+
struct ggml_context * ctx,
1909+
struct ggml_tensor * r,
1910+
struct ggml_tensor * w,
1911+
struct ggml_tensor * k,
1912+
struct ggml_tensor * v,
1913+
struct ggml_tensor * a,
1914+
struct ggml_tensor * b,
1915+
struct ggml_tensor * state);
1916+
18931917
// custom operators
18941918

18951919
typedef void (*ggml_unary_op_f32_t) (const int, float *, const float *);

ThirdParty/LlamaCpp/Include/llama.h

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern "C" {
6060
struct llama_model;
6161
struct llama_context;
6262
struct llama_sampler;
63+
struct llama_kv_cache;
6364

6465
typedef int32_t llama_pos;
6566
typedef int32_t llama_token;
@@ -106,6 +107,7 @@ extern "C" {
106107
LLAMA_VOCAB_PRE_TYPE_MINERVA = 27,
107108
LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28,
108109
LLAMA_VOCAB_PRE_TYPE_GPT4O = 29,
110+
LLAMA_VOCAB_PRE_TYPE_SUPERBPE = 30,
109111
};
110112

111113
enum llama_rope_type {
@@ -469,7 +471,8 @@ extern "C" {
469471
DEPRECATED(LLAMA_API int32_t llama_n_vocab (const struct llama_vocab * vocab), "use llama_vocab_n_tokens instead");
470472

471473
LLAMA_API const struct llama_model * llama_get_model (const struct llama_context * ctx);
472-
LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx);
474+
LLAMA_API struct llama_kv_cache * llama_get_kv_self ( struct llama_context * ctx);
475+
LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx); // TODO: rename to llama_get_pooling_type
473476

474477
LLAMA_API const struct llama_vocab * llama_model_get_vocab(const struct llama_model * model);
475478
LLAMA_API enum llama_rope_type llama_model_rope_type(const struct llama_model * model);
@@ -586,7 +589,7 @@ extern "C" {
586589
// KV cache
587590
//
588591

589-
// TODO: remove llama_kv_cache_view_* API
592+
// TODO: start using struct llama_kv_cache
590593

591594
// Information associated with an individual cell in the KV cache view.
592595
struct llama_kv_cache_view_cell {
@@ -641,21 +644,27 @@ extern "C" {
641644

642645
// Returns the number of tokens in the KV cache (slow, use only for debug)
643646
// If a KV cell has multiple sequences assigned to it, it will be counted multiple times
644-
LLAMA_API int32_t llama_get_kv_cache_token_count(const struct llama_context * ctx);
647+
LLAMA_API int32_t llama_kv_self_n_tokens(const struct llama_context * ctx);
648+
649+
DEPRECATED(LLAMA_API int32_t llama_get_kv_cache_token_count(const struct llama_context * ctx),
650+
"use llama_kv_self_n_tokens instead");
645651

646652
// Returns the number of used KV cells (i.e. have at least one sequence assigned to them)
647-
LLAMA_API int32_t llama_get_kv_cache_used_cells(const struct llama_context * ctx);
653+
LLAMA_API int32_t llama_kv_self_used_cells(const struct llama_context * ctx);
654+
655+
DEPRECATED(LLAMA_API int32_t llama_get_kv_cache_used_cells(const struct llama_context * ctx),
656+
"use llama_kv_self_used_cells instead");
648657

649658
// Clear the KV cache - both cell info is erased and KV data is zeroed
650-
LLAMA_API void llama_kv_cache_clear(
659+
LLAMA_API void llama_kv_self_clear(
651660
struct llama_context * ctx);
652661

653662
// Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
654663
// Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails
655664
// seq_id < 0 : match any sequence
656665
// p0 < 0 : [0, p1]
657666
// p1 < 0 : [p0, inf)
658-
LLAMA_API bool llama_kv_cache_seq_rm(
667+
LLAMA_API bool llama_kv_self_seq_rm(
659668
struct llama_context * ctx,
660669
llama_seq_id seq_id,
661670
llama_pos p0,
@@ -665,25 +674,25 @@ extern "C" {
665674
// Note that this does not allocate extra KV cache memory - it simply assigns the tokens to the new sequence
666675
// p0 < 0 : [0, p1]
667676
// p1 < 0 : [p0, inf)
668-
LLAMA_API void llama_kv_cache_seq_cp(
677+
LLAMA_API void llama_kv_self_seq_cp(
669678
struct llama_context * ctx,
670679
llama_seq_id seq_id_src,
671680
llama_seq_id seq_id_dst,
672681
llama_pos p0,
673682
llama_pos p1);
674683

675684
// Removes all tokens that do not belong to the specified sequence
676-
LLAMA_API void llama_kv_cache_seq_keep(
685+
LLAMA_API void llama_kv_self_seq_keep(
677686
struct llama_context * ctx,
678687
llama_seq_id seq_id);
679688

680689
// Adds relative position "delta" to all tokens that belong to the specified sequence and have positions in [p0, p1)
681690
// If the KV cache is RoPEd, the KV data is updated accordingly:
682691
// - lazily on next llama_decode()
683-
// - explicitly with llama_kv_cache_update()
692+
// - explicitly with llama_kv_self_update()
684693
// p0 < 0 : [0, p1]
685694
// p1 < 0 : [p0, inf)
686-
LLAMA_API void llama_kv_cache_seq_add(
695+
LLAMA_API void llama_kv_self_seq_add(
687696
struct llama_context * ctx,
688697
llama_seq_id seq_id,
689698
llama_pos p0,
@@ -693,35 +702,87 @@ extern "C" {
693702
// Integer division of the positions by factor of `d > 1`
694703
// If the KV cache is RoPEd, the KV data is updated accordingly:
695704
// - lazily on next llama_decode()
696-
// - explicitly with llama_kv_cache_update()
705+
// - explicitly with llama_kv_self_update()
697706
// p0 < 0 : [0, p1]
698707
// p1 < 0 : [p0, inf)
699-
LLAMA_API void llama_kv_cache_seq_div(
708+
LLAMA_API void llama_kv_self_seq_div(
700709
struct llama_context * ctx,
701710
llama_seq_id seq_id,
702711
llama_pos p0,
703712
llama_pos p1,
704713
int d);
705714

706715
// Returns the largest position present in the KV cache for the specified sequence
707-
LLAMA_API llama_pos llama_kv_cache_seq_pos_max(
716+
LLAMA_API llama_pos llama_kv_self_seq_pos_max(
708717
struct llama_context * ctx,
709-
llama_seq_id seq_id);
710-
711-
// TODO: the llama_kv_cache_defrag and llama_kv_cache_update API tightly couples llama_context with llama_kv_cache
712-
// how to avoid this?
718+
llama_seq_id seq_id);
713719

714720
// Defragment the KV cache
715721
// This will be applied:
716722
// - lazily on next llama_decode()
717-
// - explicitly with llama_kv_cache_update()
718-
LLAMA_API void llama_kv_cache_defrag(struct llama_context * ctx);
723+
// - explicitly with llama_kv_self_update()
724+
LLAMA_API void llama_kv_self_defrag(struct llama_context * ctx);
725+
726+
// Check if the context supports KV cache shifting
727+
LLAMA_API bool llama_kv_self_can_shift(const struct llama_context * ctx);
719728

720729
// Apply the KV cache updates (such as K-shifts, defragmentation, etc.)
721-
LLAMA_API void llama_kv_cache_update(struct llama_context * ctx);
730+
LLAMA_API void llama_kv_self_update(struct llama_context * ctx);
731+
732+
DEPRECATED(LLAMA_API void llama_kv_cache_clear(
733+
struct llama_context * ctx),
734+
"use llama_kv_self_clear instead");
735+
736+
DEPRECATED(LLAMA_API bool llama_kv_cache_seq_rm(
737+
struct llama_context * ctx,
738+
llama_seq_id seq_id,
739+
llama_pos p0,
740+
llama_pos p1),
741+
"use llama_kv_self_seq_rm instead");
742+
743+
DEPRECATED(LLAMA_API void llama_kv_cache_seq_cp(
744+
struct llama_context * ctx,
745+
llama_seq_id seq_id_src,
746+
llama_seq_id seq_id_dst,
747+
llama_pos p0,
748+
llama_pos p1),
749+
"use llama_kv_self_seq_cp instead");
750+
751+
DEPRECATED(LLAMA_API void llama_kv_cache_seq_keep(
752+
struct llama_context * ctx,
753+
llama_seq_id seq_id),
754+
"use llama_kv_self_seq_keep instead");
755+
756+
DEPRECATED(LLAMA_API void llama_kv_cache_seq_add(
757+
struct llama_context * ctx,
758+
llama_seq_id seq_id,
759+
llama_pos p0,
760+
llama_pos p1,
761+
llama_pos delta),
762+
"use llama_kv_self_seq_add instead");
763+
764+
DEPRECATED(LLAMA_API void llama_kv_cache_seq_div(
765+
struct llama_context * ctx,
766+
llama_seq_id seq_id,
767+
llama_pos p0,
768+
llama_pos p1,
769+
int d),
770+
"use llama_kv_self_seq_div instead");
771+
772+
DEPRECATED(LLAMA_API llama_pos llama_kv_cache_seq_pos_max(
773+
struct llama_context * ctx,
774+
llama_seq_id seq_id),
775+
"use llama_kv_self_seq_pos_max instead");
776+
777+
DEPRECATED(LLAMA_API void llama_kv_cache_defrag(struct llama_context * ctx),
778+
"use llama_kv_self_defrag instead");
779+
780+
DEPRECATED(LLAMA_API bool llama_kv_cache_can_shift(const struct llama_context * ctx),
781+
"use llama_kv_self_can_shift instead");
782+
783+
DEPRECATED(LLAMA_API void llama_kv_cache_update(struct llama_context * ctx),
784+
"use llama_kv_self_update instead");
722785

723-
// Check if the context supports KV cache shifting
724-
LLAMA_API bool llama_kv_cache_can_shift(struct llama_context * ctx);
725786

726787
//
727788
// State / sessions
@@ -885,6 +946,10 @@ extern "C" {
885946
// If set to true, the model will only attend to the past tokens
886947
LLAMA_API void llama_set_causal_attn(struct llama_context * ctx, bool causal_attn);
887948

949+
// Set whether the model is in warmup mode or not
950+
// If true, all model tensors are activated during llama_decode() to load and cache their weights.
951+
LLAMA_API void llama_set_warmup(struct llama_context * ctx, bool warmup);
952+
888953
// Set abort callback
889954
LLAMA_API void llama_set_abort_callback(struct llama_context * ctx, ggml_abort_callback abort_callback, void * abort_callback_data);
890955

5.46 KB
Binary file not shown.
614 Bytes
Binary file not shown.
3.11 KB
Binary file not shown.

0 commit comments

Comments
 (0)