diff options
| -rw-r--r-- | main.c | 20 | ||||
| -rwxr-xr-x | test_prompts.sh | 40 |
2 files changed, 40 insertions, 20 deletions
@@ -7,8 +7,6 @@ #include "mem.h" #include "llama.h" -#define MODEL_PATH "Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf" - #define SYSTEM_PROMPT \ "You are a lexicographer. Define the target word strictly in the context provided.\n\n" \ "Output format strictly as follows:\n" \ @@ -192,8 +190,13 @@ 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 (argc < 3) + errx(1, "usage: %s [model] [prompt]", argv[0]); + + const char *model_path = argv[1]; + + if (unveil(model_path, "r") == -1) + err(1, "unveil %s failed", model_path); if (unveil(NULL, NULL) == -1) err(1, "unveil lock failed"); @@ -201,23 +204,20 @@ int main(int argc , char *argv[]) if (pledge("stdio rpath", NULL) == -1) err(1, "initial pledge failed"); - if (argc < 2) - errx(1, "usage: %s [prompt]", argv[0]); - 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); + model = llama_model_load_from_file(model_path, mparams); if (!model) - errx(1, "failed to load model from file %s", MODEL_PATH); + errx(1, "failed to load model from file %s", model_path); if (pledge("stdio", NULL) == -1) err(1, "secondary pledge failed"); - const char *prompt = argv[1]; + const char *prompt = argv[2]; process_request(model, prompt); llama_model_free(model); diff --git a/test_prompts.sh b/test_prompts.sh index 04020c3..e22e90f 100755 --- a/test_prompts.sh +++ b/test_prompts.sh @@ -1,8 +1,27 @@ #!/bin/sh -# Default filenames -PROMPT_FILE="${1:-test_prompts.txt}" -RESULT_FILE="${2:-results.txt}" +# Usage: ./test_prompts.sh <model_path> [prompt_file] + +# Mandatory Model Argument +MODEL_PATH="$1" + +if [ -z "$MODEL_PATH" ]; then + echo "Usage: $0 <model_path> [prompt_file]" >&2 + exit 1 +fi + +if [ ! -f "$MODEL_PATH" ]; then + echo "Error: Model file '$MODEL_PATH' not found." >&2 + exit 1 +fi + +# Derive base model name and output result filename +# e.g., models/qwen2.5-7b-q4.gguf -> results_qwen2.5-7b-q4.gguf.txt +MODEL_NAME=$(basename "$MODEL_PATH") +RESULT_FILE="results_${MODEL_NAME}.txt" + +# Default prompt filename (optional 2nd argument) +PROMPT_FILE="${2:-test_prompts.txt}" EXECUTABLE="./lex" # Ensure the executable exists and is runnable @@ -28,15 +47,16 @@ fi # Create (or truncate) the result file at the start of the run > "$RESULT_FILE" -# Create a 70-character horizontal rule: " -- " + 66 "-" -RULE=" -- " +# Create horizontal rule. +RULE="" i=0 -while [ $i -lt 66 ]; do +while [ $i -lt 72 ]; do RULE="${RULE}-" i=$((i + 1)) done -echo "Starting evaluation: $total_prompts prompt(s) found." +echo "Starting evaluation with model: '$MODEL_PATH'" +echo "Evaluating $total_prompts prompt(s) from '$PROMPT_FILE'" echo "Writing results to: '$RESULT_FILE'" echo "---------------------------------------------------" @@ -66,12 +86,12 @@ while IFS= read -r prompt || [ -n "$prompt" ]; do # Log prompt header to the result file printf "PROMPT: %s\n\n" "$prompt" >> "$RESULT_FILE" - # On OpenBSD, /usr/bin/time -lp outputs POSIX timings and rusage stats to stderr - /usr/bin/time -lp "$EXECUTABLE" "$prompt" >> "$RESULT_FILE" 2> "$TIME_LOG" + # Invoke executable with model path and prompt + /usr/bin/time -lp "$EXECUTABLE" "$MODEL_PATH" "$prompt" >> "$RESULT_FILE" 2> "$TIME_LOG" # Extract execution time and peak memory (maximum resident set size) from OpenBSD time output real_time=$(awk '/^real/ {print $2}' "$TIME_LOG") - max_rss_mb=$(awk '/maximum resident set size/ {printf "%.2f", $1/1024}' "$TIME_LOG") + max_rss_mb=$(awk '/maximum resident set size/ {printf "%.2f", $1/1024}' "$TIME_LOG") # Format metrics summary line metrics_summary="ELAPSED: ${real_time}s | MAX RSS: ${max_rss_mb} MB" |
