Skip to content

Commit e78a971

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

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

examples/quantize/quantize.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ int main(int argc, char ** argv) {
5252
return 1;
5353
}
5454

55+
// needed to initialize f16 tables
56+
{
57+
struct ggml_init_params params = { 0, NULL, false };
58+
struct ggml_context * ctx = ggml_init(params);
59+
ggml_free(ctx);
60+
}
61+
5562
// parse command line arguments
5663
const std::string fname_inp = argv[1];
5764
std::string fname_out;

llama.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,11 @@ 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_context * ctx = ggml_init(params);
2193+
ggml_free(ctx);
2194+
}
2195+
21912196
void llama_free(struct llama_context * ctx) {
21922197
delete ctx;
21932198
}
@@ -2198,12 +2203,6 @@ int llama_model_quantize(
21982203
enum llama_ftype ftype,
21992204
int nthread) {
22002205
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-
}
22072206
llama_model_quantize_internal(fname_inp, fname_out, ftype, nthread);
22082207
return 0;
22092208
} catch (const std::string & err) {

llama.h

+4
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)