summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-07-26 18:14:39 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-07-26 18:15:57 +0800
commit4fb8801eebca334bebd52c2e96b03fccc07a1dc5 (patch)
treea2577a3151b6909a8b7fbc8cee8560f47aed5e46 /main.c
parent3fc0bbf69d2839389c63b1d7af8b7e9064ad2e1b (diff)
downloadwordbook-4fb8801eebca334bebd52c2e96b03fccc07a1dc5.tar.gz
Load model, pledge+unveil.
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/main.c b/main.c
index e221a28..c5ecd8a 100644
--- a/main.c
+++ b/main.c
@@ -1,10 +1,41 @@
#include <stdio.h>
+#include <stdbool.h>
+#include <err.h>
+#include <unistd.h>
+
#include "llama.h"
+#define MODEL_PATH "Qwen2.5-7B-Instruct-Q4_K_M.gguf"
+
int main(int argc , char *argv[])
{
+ struct llama_model *model;
+ struct llama_model_params mparams;
+
+ if (unveil(MODEL_PATH, "r") == -1)
+ err(1, "unveil %s failed", MODEL_PATH);
+
+ if (unveil(NULL, NULL) == -1)
+ err(1, "unveil lock failed");
+
+ if (pledge("stdio rpath", NULL) == -1)
+ err(1, "initial pledge failed");
+
llama_backend_init();
+ mparams = llama_model_default_params();
+ mparams.n_gpu_layers = 0; /* force all layers onto CPU */
+ mparams.load_mode = LLAMA_LOAD_MODE_MMAP;
+
+ model = llama_model_load_from_file(MODEL_PATH, mparams);
+ if (!model)
+ errx(1, "failed to load model from file %s", MODEL_PATH);
+
+ /* drop rpath after loading the model */
+ if (pledge("stdio", NULL) == -1)
+ err(1, "secondary pledge failed");
+
+ llama_model_free(model);
llama_backend_free();
return 0;