Skip to content

Commit 23f4674

Browse files
committed
Add llama_init_ggml c api.
1 parent 484f6e9 commit 23f4674

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

examples/embedding/embedding.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ int main(int argc, char ** argv) {
1111
return 1;
1212
}
1313

14+
// needed to initialize f16 tables
15+
{
16+
struct ggml_init_params params = { 0, NULL, false };
17+
struct ggml_context * ctx = ggml_init(params);
18+
ggml_free(ctx);
19+
}
20+
1421
params.embedding = true;
1522

1623
if (params.n_ctx > 2048) {

llama.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,12 @@ struct llama_context * llama_init_from_file(
21882188
return ctx;
21892189
}
21902190

2191+
void llama_init_ggml(struct ggml_init_params params) {
2192+
struct ggml_init_params params = { 0, NULL, false };
2193+
struct ggml_context * ctx = ggml_init(params);
2194+
ggml_free(ctx);
2195+
}
2196+
21912197
void llama_free(struct llama_context * ctx) {
21922198
delete ctx;
21932199
}
@@ -2198,12 +2204,6 @@ int llama_model_quantize(
21982204
enum llama_ftype ftype,
21992205
int nthread) {
22002206
try {
2201-
// needed to initialize f16 tables
2202-
{
2203-
struct ggml_init_params params = { 0, NULL, false };
2204-
struct ggml_context * ctx = ggml_init(params);
2205-
ggml_free(ctx);
2206-
}
22072207
llama_model_quantize_internal(fname_inp, fname_out, ftype, nthread);
22082208
return 0;
22092209
} catch (const std::string & err) {

llama.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ extern "C" {
9797
const char * path_model,
9898
struct llama_context_params params);
9999

100+
// Init the ggml context (it won't return a context ptr because it will free
101+
// the ctx after initialing it).
102+
LLAMA_API void llama_init_ggml(struct ggml_init_params params);
103+
100104
// Frees all allocated memory
101105
LLAMA_API void llama_free(struct llama_context * ctx);
102106

0 commit comments

Comments
 (0)