Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sovereign-intelligence/blob/main/tools/adapter/qualify # sovereign-intelligence Front door to Drake Stapleton's sovereign stack. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `sovereign-intelligence / tools / adapter / qualify` 74 lines ยท 3359 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Qualify one pinned Q8_0 attention row on a Linux AArch64 host. 3 set -euo pipefail 4 export LC_ALL=C 5 umask 077 6 refuse() { printf 'REFUSED %s\n' "$1" >&2; exit 1; } 7 digest() { sha256sum < "$1" | cut -d' ' -f1; } 8 [[ $# == 1 ]] || refuse 'usage: qualify MODEL.gguf' 9 base=$(cd -- "$(dirname -- "$0")" && pwd) 10 [[ -f $1 ]] || refuse model_file 11 exec 3< "$1" 12 model=/proc/self/fd/3 13 [[ -f $model ]] || refuse model_type 14 size=$(stat -Lc %s "$model") 15 awk -v size="$size" '$1 == size {found=1} END {exit !found}' "$base/models.tsv" || refuse unsupported_size 16 hash=$(digest "$model") 17 spec=$(awk -v s="$size" -v h="$hash" '$1 == s && $2 == h {print}' "$base/models.tsv") 18 [[ -n $spec ]] || refuse model_digest 19 read -r _ _ arch tokenizer width offset row_sha reference binary_sha <<< "$spec" 20 [[ $(uname -s)/$(uname -m) == Linux/aarch64 ]] || refuse unsupported_host 21 tmp=$(mktemp -d) 22 trap 'rm -rf -- "$tmp"' EXIT 23 blocks=$((width / 32)) 24 length=$((34 * blocks)) 25 dd if="$model" of="$tmp/row" iflag=skip_bytes,count_bytes skip="$offset" count="$length" status=none 26 [[ $(digest "$tmp/row") == "$row_sha" ]] || refuse row_digest 27 28 { 29 uname -smr 30 # Include all reported core types on heterogeneous hosts. 31 cat /sys/devices/system/cpu/cpu*/regs/identification/midr_el1 | sort -u 32 awk '/^MemTotal:/ {print}' /proc/meminfo 33 for pci in /sys/bus/pci/devices/*; do 34 [[ -r $pci/class ]] || continue 35 class=$(cat "$pci/class") 36 [[ $class == 0x03* ]] || continue 37 printf 'display %s %s %s %s\n' "${pci##*/}" "$(cat "$pci/vendor")" "$(cat "$pci/device")" "$class" 38 if [[ -L $pci/driver ]]; then basename "$(readlink "$pci/driver")"; fi 39 done 40 if [[ -r /proc/driver/nvidia/version ]]; then head -1 /proc/driver/nvidia/version; fi 41 } > "$tmp/hardware" 42 cat "$tmp/hardware" 43 compiler_sha=`45442c7d517fd605507bda5d1ec52493ff182661301cda69a95fc4f77dc6080d` 44 sed -e "s/@W@/$length/g;s/@X@/$width/g;s/@B@/$blocks/g" \ 45 "$base/half.om" "$base/dq8.om.in" "$base/row.om.in" > "$tmp/source" 46 key=$(printf '%s\n' "$hash" "$(digest "$tmp/hardware")" "$compiler_sha" "$(digest "$tmp/source")" "$binary_sha" | sha256sum | cut -d' ' -f1) 47 cache=${SI_ADAPTER_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/si-adapter} 48 mkdir -p -- "$cache" 49 if [[ -e $cache/$key ]]; then 50 cp -- "$cache/$key" "$tmp/kernel" 51 state=reused 52 else 53 omc=${OMC:-$base/../../out/omc} 54 [[ -f $omc ]] || refuse compiler_missing 55 cp -- "$omc" "$tmp/compiler" 56 [[ $(digest "$tmp/compiler") == "$compiler_sha" ]] || refuse compiler_digest 57 chmod 700 "$tmp/compiler" 58 "$tmp/compiler" < "$tmp/source" > "$tmp/kernel" 59 state=generated 60 fi 61 [[ $(digest "$tmp/kernel") == "$binary_sha" ]] || refuse kernel_digest 62 chmod 700 "$tmp/kernel" 63 "$tmp/kernel" < "$tmp/row" > "$tmp/bits" 64 [[ $(stat -c %s "$tmp/bits") == 4 ]] || refuse result_length 65 bits=$(od -An -tu4 "$tmp/bits" | tr -d ' ') 66 [[ $bits == "$reference" ]] || refuse parity 67 if [[ $state == generated ]]; then 68 publish=$(mktemp -- "$cache/.kernel.XXXXXXXX") 69 trap 'rm -rf -- "$tmp"; rm -f -- "$publish"' EXIT 70 cp -- "$tmp/kernel" "$publish" 71 mv -fT -- "$publish" "$cache/$key" 72 fi 73 printf 'ROW_PASS format=GGUFv3 quant=Q8_0 architecture=%s tokenizer=%s model=%s width=%s bits=%s device=cpu cache=%s key=%s kernel=%s\n' \ 74 "$arch" "$tokenizer" "$hash" "$width" "$bits" "$state" "$key" "$binary_sha"