sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / tools / adapter / check
| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | [[ $# == 2 ]] || { echo 'usage: check QWEN.gguf STORIES.gguf' >&2; exit 2; } |
| 4 | base=$(cd -- "$(dirname -- "$0")" && pwd) |
| 5 | tmp=$(mktemp -d) |
| 6 | trap 'rm -rf -- "$tmp"' EXIT |
| 7 | export SI_ADAPTER_CACHE=$tmp/cache |
| 8 | run() { "$base/qualify" "$1" | tee "$tmp/log"; } |
| 9 | reject() { |
| 10 | local reason=$1 |
| 11 | shift |
| 12 | if "$@" > "$tmp/log" 2>&1; then echo "unexpected success: $reason" >&2; exit 1; fi |
| 13 | grep -Fx "REFUSED $reason" "$tmp/log" |
| 14 | } |
| 15 | run "$1" |
| 16 | grep -q 'architecture=qwen2 .*cache=generated' "$tmp/log" |
| 17 | qkey=$(sed -n 's/^ROW_PASS .* key=\([^ ]*\) kernel=.*/\1/p' "$tmp/log") |
| 18 | run "$2" |
| 19 | grep -q 'architecture=llama .*cache=generated' "$tmp/log" |
| 20 | lkey=$(sed -n 's/^ROW_PASS .* key=\([^ ]*\) kernel=.*/\1/p' "$tmp/log") |
| 21 | [[ -n $qkey && -n $lkey && $qkey != "$lkey" ]] |
| 22 | run "$2" |
| 23 | grep -q 'cache=reused' "$tmp/log" |
| 24 | # Change only the reported kernel release, keeping the real CPU/runtime. |
| 25 | mkdir "$tmp/bin" |
| 26 | cat > "$tmp/bin/uname" <<'PROBE' |
| 27 | #!/bin/sh |
| 28 | if [ "$1" = -smr ]; then echo 'Linux CONTROL aarch64'; else exec /usr/bin/uname "$@"; fi |
| 29 | PROBE |
| 30 | chmod +x "$tmp/bin/uname" |
| 31 | PATH="$tmp/bin:$PATH" run "$2" |
| 32 | grep -q 'cache=generated' "$tmp/log" |
| 33 | other=$(sed -n 's/^ROW_PASS .* key=\([^ ]*\) kernel=.*/\1/p' "$tmp/log") |
| 34 | [[ -n $other && $other != "$lkey" ]] |
| 35 | echo HARDWARE_KEY_CONTROL_PASS |
| 36 | echo truncated > "$tmp/bad" |
| 37 | reject unsupported_size "$base/qualify" "$tmp/bad" |
| 38 | truncate -s "$(stat -c %s "$2")" "$tmp/bad" |
| 39 | reject model_digest "$base/qualify" "$tmp/bad" |
| 40 | cp "$tmp/cache/$qkey" "$tmp/cache/$lkey" |
| 41 | reject kernel_digest "$base/qualify" "$2" |
| 42 | rm "$tmp/cache/$lkey" |
| 43 | reject compiler_digest env OMC=/bin/true "$base/qualify" "$2" |
| 44 | mkdir "$tmp/mutant" |
| 45 | cp "$base"/{qualify,models.tsv,half.om,dq8.om.in,row.om.in} "$tmp/mutant/" |
| 46 | sed -i 's/3223118742/3223118743/' "$tmp/mutant/models.tsv" |
| 47 | reject parity "$tmp/mutant/qualify" "$2" |
| 48 | [[ ! -e $tmp/cache/$lkey ]] |
| 49 | echo CHECK_PASS |