Skip to content

Commit 71d1169

Browse files
committed
context : move adapter code in the implementation [no ci]
1 parent f4ba506 commit 71d1169

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

src/llama-context.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,43 @@ float * llama_get_embeddings_seq(struct llama_context * ctx, llama_seq_id seq_id
17881788
return it->second.data();
17891789
}
17901790

1791+
// llama adapter API
1792+
1793+
int32_t llama_set_adapter_lora(
1794+
struct llama_context * ctx,
1795+
struct llama_adapter_lora * adapter,
1796+
float scale) {
1797+
ctx->loras[adapter] = scale;
1798+
return 0;
1799+
}
1800+
1801+
int32_t llama_rm_adapter_lora(
1802+
struct llama_context * ctx,
1803+
struct llama_adapter_lora * adapter) {
1804+
auto pos = ctx->loras.find(adapter);
1805+
if (pos != ctx->loras.end()) {
1806+
ctx->loras.erase(pos);
1807+
return 0;
1808+
}
1809+
1810+
return -1;
1811+
}
1812+
1813+
void llama_clear_adapter_lora(struct llama_context * ctx) {
1814+
ctx->loras.clear();
1815+
}
1816+
1817+
int32_t llama_apply_adapter_cvec(
1818+
struct llama_context * ctx,
1819+
const float * data,
1820+
size_t len,
1821+
int32_t n_embd,
1822+
int32_t il_start,
1823+
int32_t il_end) {
1824+
return ctx->cvec.apply(ctx->model, data, len, n_embd, il_start, il_end);
1825+
}
1826+
1827+
17911828
// llama state API
17921829

17931830
// deprecated

src/llama.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8322,40 +8322,6 @@ static int llama_encode_impl(
83228322
return 0;
83238323
}
83248324

8325-
int32_t llama_set_adapter_lora(
8326-
struct llama_context * ctx,
8327-
struct llama_adapter_lora * adapter,
8328-
float scale) {
8329-
ctx->loras[adapter] = scale;
8330-
return 0;
8331-
}
8332-
8333-
int32_t llama_rm_adapter_lora(
8334-
struct llama_context * ctx,
8335-
struct llama_adapter_lora * adapter) {
8336-
auto pos = ctx->loras.find(adapter);
8337-
if (pos != ctx->loras.end()) {
8338-
ctx->loras.erase(pos);
8339-
return 0;
8340-
}
8341-
8342-
return -1;
8343-
}
8344-
8345-
void llama_clear_adapter_lora(struct llama_context * ctx) {
8346-
ctx->loras.clear();
8347-
}
8348-
8349-
int32_t llama_apply_adapter_cvec(
8350-
struct llama_context * ctx,
8351-
const float * data,
8352-
size_t len,
8353-
int32_t n_embd,
8354-
int32_t il_start,
8355-
int32_t il_end) {
8356-
return ctx->cvec.apply(ctx->model, data, len, n_embd, il_start, il_end);
8357-
}
8358-
83598325
//
83608326
// interface implementation
83618327
//
@@ -8914,7 +8880,7 @@ struct llama_context * llama_new_context_with_model(
89148880
}
89158881

89168882
//
8917-
// kv cache
8883+
// kv cache view
89188884
//
89198885

89208886
struct llama_kv_cache_view llama_kv_cache_view_init(const llama_context * ctx, int32_t n_seq_max) {
@@ -8925,6 +8891,10 @@ void llama_kv_cache_view_update(const llama_context * ctx, llama_kv_cache_view *
89258891
llama_kv_cache_view_update(view, ctx->kv_self);
89268892
}
89278893

8894+
//
8895+
// kv cache
8896+
//
8897+
89288898
// deprecated
89298899
int32_t llama_get_kv_cache_token_count(const llama_context * ctx) {
89308900
return llama_kv_self_n_tokens(ctx);

0 commit comments

Comments
 (0)