diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-07-26 18:14:39 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-07-26 18:15:57 +0800 |
| commit | 4fb8801eebca334bebd52c2e96b03fccc07a1dc5 (patch) | |
| tree | a2577a3151b6909a8b7fbc8cee8560f47aed5e46 | |
| parent | 3fc0bbf69d2839389c63b1d7af8b7e9064ad2e1b (diff) | |
| download | wordbook-4fb8801eebca334bebd52c2e96b03fccc07a1dc5.tar.gz | |
Load model, pledge+unveil.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.txt | 2 | ||||
| -rw-r--r-- | main.c | 31 |
3 files changed, 34 insertions, 0 deletions
@@ -1,3 +1,4 @@ *.o *.cgi +*.gguf deps/ diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..c45e800 --- /dev/null +++ b/README.txt @@ -0,0 +1,2 @@ +Run with no logs: GGML_LOG_LEVEL=0 ./wordbook.cgi +Run with error logs: GGML_LOG_LEVEL=error ./wordbook.cgi @@ -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; |
