#!/usr/bin/env python3 """tools/qwen36_check_eval_callback.py - check the printed output of the submodule's `llama-eval-callback` against the numpy oracle's dumps. llama-eval-callback -m MODEL.gguf -p "hello" -ctk f32 -ctv f32 -fa off -c 64 -t 1 -ngl 0 > eval.txt 2>&1 python3 ref/qwen36.py MODEL.gguf --text hello --dump ORA python3 tools/qwen36_check_eval_callback.py ORA eval.txt [--tol 1e-4] `llama-eval-callback` prints, per graph node, the first and last 3 entries along every dimension (`%12.4f`, so each printed value carries up to 5e-5 of rounding) and a float32 `sum` of the whole tensor. This reconstructs which indices were printed from the shape (common/debug.cpp:75-117), looks them up in the oracle's array of the same cb() name, and requires |printed - oracle| <= tol on every printed value and the sum to agree to tol of the tensor's L1 mass. Repeated names get "#2", "#3" in execution order, as in the dumps. Nodes llama.cpp leaves unnamed ("node_30", "x (view)") are ignored; "kq" and "kq_soft_max" are skipped because llama.cpp pads their KV axis to its cache size. Exit status 1 on any mismatch or if fewer than --min-seams names were checked. """ import argparse import math import re import sys import pathlib import numpy as np HEAD = re.compile(r"^common_debug_cb_eval:\s+(.+?) = \((\w+)\)\s+\w+\(.*\) = \{(\d+), (\d+), (\d+), (\d+)\}\s*$") NUM = re.compile(r"(? 6 else "") return 1 if bad or checked < a.min_seams or (a.require_tail and not complete) else 0 if __name__ == "__main__": sys.exit(main())