From 00524ee5a706a7d3863b8bb3107b32055f6ab258 Mon Sep 17 00:00:00 2001 From: smfworks Date: Sun, 15 Nov 2026 20:58:55 -0500 Subject: [PATCH 01/13] install: detect AMD GPUs (amdgpu, ROCm, GTT) beside the NVIDIA path lib.sh: when nvidia-smi sees no GPU, hw_gpu/hw_driver/hw_vram/hw_summary read the first amdgpu card (sysfs) and rocminfo (marketing name, gfx target), hw_rocm the ROCm version, hw_gtt/hw_gtt_used the GTT pool an APU's GPU maps. hw_match gains optional hardware.min_rocm, hardware.gfx and hardware.min_gtt_gib. The NVIDIA and macOS paths are unchanged. doctor.sh: the free-memory warning reads hardware.min_free_gib (default 88, as before) and, on AMD, shows GTT in use and AMD-side hints; a deploy.service of "systemd-transient" (systemd-run --user) is checked by is-active instead of a unit file. --- tools/install/doctor.sh | 17 ++++++++++++- tools/install/lib.sh | 53 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/tools/install/doctor.sh b/tools/install/doctor.sh index 8fbae40e..9aebd921 100755 --- a/tools/install/doctor.sh +++ b/tools/install/doctor.sh @@ -47,7 +47,14 @@ while read -r line; do done < <(hw_match "$p") avail=$(hw_disk_free "$PREFIX") echo " disk free under $PREFIX: $(gib "$avail") GiB" -[ $darwin = 1 ] || [ $(($(hw_avail) / 1073741824)) -ge 88 ] || systemctl --user is-active -q "$UNIT" || warn "only $(gib "$(hw_avail)") GiB of memory is available: the GPU steps need up to 88 GiB free and the warm models about 107 GiB" "see what holds it: nvidia-smi --query-compute-apps=pid,name,used_memory --format=csv (INSTALL.md step 6)" +# the free memory the GPU steps want: the profile's hardware.min_free_gib (default 88, the GB10 figure) +need=$(jq -r '.hardware.min_free_gib // 88' "$p") +if hw_amd; then + echo " GTT in use: $(gib "$(hw_gtt_used)") of $(gib "$(hw_gtt)") GiB" + [ $(($(hw_avail) / 1073741824)) -ge "$need" ] || systemctl --user is-active -q "$UNIT" || warn "only $(gib "$(hw_avail)") GiB of memory is available: the GPU steps need up to $need GiB free" "see what holds it: cat $(amd_card)/mem_info_gtt_used; podman ps; rocm-smi --showpids" +else + [ $darwin = 1 ] || [ $(($(hw_avail) / 1073741824)) -ge "$need" ] || systemctl --user is-active -q "$UNIT" || warn "only $(gib "$(hw_avail)") GiB of memory is available: the GPU steps need up to $need GiB free and the warm models about 107 GiB" "see what holds it: nvidia-smi --query-compute-apps=pid,name,used_memory --format=csv (INSTALL.md step 6)" +fi echo "== prerequisites" while read -r q; do @@ -79,6 +86,14 @@ if [ "$(jq -r '.deploy.service // "systemd"' "$p")" = launchd ]; then # a laun ok "launchd agent $label running, pid $(launchctl print "gui/$(id -u)/$label" | awk '$1 == "pid" {print $3; exit}'); it starts at login" up=1 logs="tail -50 $log; then bash $repo/$start" fi +elif [ "$(jq -r '.deploy.service // "systemd"' "$p")" = systemd-transient ]; then # systemd-run --user (deploy/strix-halo) + echo "== service $UNIT (transient user unit) on $listen:$PORT" + if ! systemctl --user is-active -q "$UNIT"; then + miss "the transient unit $UNIT is not running" "bash $repo/$start (why it stopped: journalctl --user -u $UNIT -n 50)" + else + ok "transient unit $UNIT active since $(systemctl --user show "$UNIT" -p ActiveEnterTimestamp --value) (not started at boot: run $start after a reboot)" + up=1 logs="journalctl --user -u $UNIT -n 50; then bash $repo/$start" + fi else # a systemd user unit (deploy/jarvis) echo "== service $UNIT on $listen:$PORT" if [ ! -f "$HOME/.config/systemd/user/$UNIT.service" ]; then diff --git a/tools/install/lib.sh b/tools/install/lib.sh index 96ae8892..75c09a25 100644 --- a/tools/install/lib.sh +++ b/tools/install/lib.sh @@ -43,13 +43,52 @@ hw_os() { if [ $darwin = 1 ]; then echo "macos $(sw_vers -productVersion | cut -d. -f1)"; return; fi (. /etc/os-release 2> /dev/null && echo "${ID:-unknown} ${VERSION_ID:-}") } +# ---- AMD (amdgpu + ROCm), used only when nvidia-smi sees no GPU: the first amdgpu card in sysfs +hw_nvidia() { [ $darwin = 0 ] && nvidia-smi -L 2> /dev/null | grep -q GPU; } +amd_card() { # the sysfs device directory of the first AMD (vendor 0x1002) DRM card with a GTT counter + local d + for d in /sys/class/drm/card[0-9]*/device; do + [ "$(cat "$d/vendor" 2> /dev/null)" = 0x1002 ] && [ -r "$d/mem_info_gtt_total" ] && { echo "$d"; return; } + done + return 1 +} +hw_amd() { [ $darwin = 0 ] && ! hw_nvidia && amd_card > /dev/null; } +# the gfx target (gfx1151 on Strix Halo) and the marketing name, from rocminfo's first GPU agent +amd_gfx() { rocminfo 2> /dev/null | awk '/^ *Name: *gfx[0-9a-f]+ *$/ {print $2; exit}'; } +amd_name() { + local n + n=$(rocminfo 2> /dev/null | awk -F': *' '/Marketing Name:/ && $2 !~ /AMD (RYZEN|EPYC|Ryzen)/ {gsub(/ +$/, "", $2); print $2; exit}') + [ -n "$n" ] || n=$(cat "$(amd_card)/product_name" 2> /dev/null) + echo "${n:-AMD GPU} ($(amd_gfx || true))" | sed 's/ ()$//' +} +# ROCm's version (/opt/rocm/.info/version, else hipconfig); empty without ROCm +hw_rocm() { + local r=${ROCM_PATH:-/opt/rocm} + { cat "$r/.info/version" 2> /dev/null || hipconfig --version 2> /dev/null; } | first | sed 's/-.*//' +} +# GTT: the system memory the GPU may map (the unified pool on an APU such as Strix Halo), total and in use, in bytes +hw_gtt() { cat "$(amd_card)/mem_info_gtt_total" 2> /dev/null || echo 0; } +hw_gtt_used() { cat "$(amd_card)/mem_info_gtt_used" 2> /dev/null || echo 0; } hw_gpu() { if [ $darwin = 1 ]; then echo "$(sysctl -n machdep.cpu.brand_string) GPU (Metal)"; return; fi # Apple Silicon: on the SoC + if hw_amd; then amd_name; return; fi nvidia-smi --query-gpu=name --format=csv,noheader 2> /dev/null | first } -hw_driver() { nvidia-smi --query-gpu=driver_version --format=csv,noheader 2> /dev/null | first; } -# the GPU's own memory in bytes; 0 on a unified-memory GPU (GB10 reports none: its memory is the system's) -hw_vram() { nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2> /dev/null | awk 'NR == 1 {v = $1 + 0} END {printf "%d", v * 1048576}'; } +hw_driver() { + if hw_amd; then echo "amdgpu $(cat /sys/module/amdgpu/version 2> /dev/null || uname -r)"; return; fi + nvidia-smi --query-gpu=driver_version --format=csv,noheader 2> /dev/null | first +} +# the GPU's own memory in bytes; 0 on a unified-memory GPU (GB10 reports none: its memory is the system's; an AMD APU's +# small BIOS carve-out is not counted when GTT, the shared pool, is larger) +hw_vram() { + if hw_amd; then + local v g + v=$(cat "$(amd_card)/mem_info_vram_total" 2> /dev/null || echo 0); g=$(hw_gtt) + [ "$v" -lt "$g" ] && echo 0 || echo "$v" + return + fi + nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2> /dev/null | awk 'NR == 1 {v = $1 + 0} END {printf "%d", v * 1048576}' +} hw_mem() { if [ $darwin = 1 ]; then sysctl -n hw.memsize; return; fi awk '/^MemTotal:/{printf "%d", $2 * 1024}' /proc/meminfo @@ -74,6 +113,10 @@ hw_disk_free() { version_ge() { [ -n "$1" ] && [ "$(printf '%s\n%s\n' "$2" "$1" | sort -V | first)" = "$2" ]; } hw_summary() { [ $darwin = 1 ] && { echo "$(hw_arch), $(hw_os), GPU '$(hw_gpu)', memory $(gib "$(hw_mem)") GiB unified, $(gib "$(hw_avail)") GiB available"; return; } + if hw_amd; then + echo "$(hw_arch), $(hw_os), GPU '$(hw_gpu)' (driver $(hw_driver)), ROCm $(hw_rocm), memory $(gib "$(hw_mem)") GiB$([ "$(hw_vram)" = 0 ] && echo " unified"), GTT $(gib "$(hw_gtt)") GiB ($(gib "$(hw_gtt_used)") GiB in use), $(gib "$(hw_avail)") GiB available" + return + fi echo "$(hw_arch), $(hw_os), GPU '$(hw_gpu)' (driver $(hw_driver)), CUDA $(hw_cuda), memory $(gib "$(hw_mem)") GiB$([ "$(hw_vram)" = 0 ] && [ -n "$(hw_gpu)" ] && echo " unified"), $(gib "$(hw_avail)") GiB available" } @@ -86,6 +129,10 @@ hw_match() { [ "$(hw_mem)" -ge $((want * 1073741824)) ] || echo "memory $(gib "$(hw_mem)") GiB, the profile needs $want GiB" want=$(jq -r '.hardware.min_driver // empty' "$p"); [ -z "$want" ] || version_ge "$(hw_driver)" "$want" || echo "NVIDIA driver '$(hw_driver)', the profile needs $want or newer" want=$(jq -r '.hardware.min_cuda // empty' "$p"); [ -z "$want" ] || version_ge "$(hw_cuda)" "$want" || echo "CUDA '$(hw_cuda)' (nvcc at ${NVCC:-/usr/local/cuda/bin/nvcc}), the profile needs $want or newer" + want=$(jq -r '.hardware.min_rocm // empty' "$p"); [ -z "$want" ] || version_ge "$(hw_rocm)" "$want" || echo "ROCm '$(hw_rocm)' (${ROCM_PATH:-/opt/rocm}), the profile needs $want or newer" + want=$(jq -r '.hardware.gfx // empty' "$p"); [ -z "$want" ] || [ "$(amd_gfx)" = "$want" ] || echo "GPU target '$(amd_gfx)' (rocminfo), the profile needs $want" + want=$(jq -r '.hardware.min_gtt_gib // empty' "$p") + [ -z "$want" ] || [ "$(hw_gtt)" -ge $((want * 1073741824)) ] || echo "GTT $(gib "$(hw_gtt)") GiB (the GPU's share of system memory, amdgpu.gttsize / ttm.pages_limit), the profile needs $want GiB" want=$(jq -r .hardware.os "$p"); [ "$(hw_os)" = "$want" ] || echo "warning: OS '$(hw_os)', the profile was tested on '$want'" } From 70101d7da9eb09b58d5f63937a31d99e683aaddf Mon Sep 17 00:00:00 2001 From: smfworks Date: Mon, 16 Nov 2026 09:13:55 -0500 Subject: [PATCH 02/13] install: AMD detection regression fixtures; name the GPU agent, not the CPU tools/install/test_amd.sh runs lib.sh's detection against four recorded hosts in tests/fixtures/amd (a sysfs tree, rocminfo output, ROCm's version file and nvidia-smi answers; no GPU needed): - strix-halo: Radeon 8060S (gfx1151) APU, 96 GiB GTT, a 4 GiB carve-out that is not VRAM, connector entries (card1-DP-1) beside the card - discrete: an Intel CPU and iGPU beside a Radeon RX 7900 XTX with real VRAM - nvidia: an NVIDIA GPU and an AMD card on one box; the NVIDIA path wins and says what it said before AMD detection existed (checked against main's lib.sh) - none: no GPU The fixtures caught one bug: amd_name took the first rocminfo Marketing Name that was not an AMD CPU, so an Intel CPU agent named the GPU. It now takes the first agent whose Device Type is GPU. LR_SYSFS (default /sys) points the sysfs reads at a fixture. CI runs the script. --- .github/workflows/ci.yml | 2 + .../fixtures/amd/discrete/rocm/.info/version | 1 + tests/fixtures/amd/discrete/rocminfo.txt | 13 +++ .../sys/class/drm/card0/device/vendor | 1 + .../class/drm/card1/device/mem_info_gtt_total | 1 + .../class/drm/card1/device/mem_info_gtt_used | 1 + .../drm/card1/device/mem_info_vram_total | 1 + .../sys/class/drm/card1/device/product_name | 1 + .../sys/class/drm/card1/device/vendor | 1 + .../amd/discrete/sys/module/amdgpu/version | 1 + tests/fixtures/amd/none/sys/class/drm/.keep | 0 tests/fixtures/amd/nvidia/nvcc.txt | 1 + tests/fixtures/amd/nvidia/nvidia-smi.txt | 4 + .../nvidia/sys/class/drm/card0/device/vendor | 1 + .../class/drm/card1/device/mem_info_gtt_total | 1 + .../class/drm/card1/device/mem_info_gtt_used | 1 + .../drm/card1/device/mem_info_vram_total | 1 + .../nvidia/sys/class/drm/card1/device/vendor | 1 + .../amd/strix-halo/rocm/.info/version | 1 + tests/fixtures/amd/strix-halo/rocminfo.txt | 35 ++++++++ .../strix-halo/sys/class/drm/card1-DP-1/.keep | 0 .../sys/class/drm/card1-eDP-1/.keep | 0 .../class/drm/card1/device/mem_info_gtt_total | 1 + .../class/drm/card1/device/mem_info_gtt_used | 1 + .../drm/card1/device/mem_info_vram_total | 1 + .../sys/class/drm/card1/device/vendor | 1 + tools/install/lib.sh | 11 ++- tools/install/test_amd.sh | 83 +++++++++++++++++++ 28 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/amd/discrete/rocm/.info/version create mode 100644 tests/fixtures/amd/discrete/rocminfo.txt create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card0/device/vendor create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_total create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_used create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_vram_total create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card1/device/product_name create mode 100644 tests/fixtures/amd/discrete/sys/class/drm/card1/device/vendor create mode 100644 tests/fixtures/amd/discrete/sys/module/amdgpu/version create mode 100644 tests/fixtures/amd/none/sys/class/drm/.keep create mode 100644 tests/fixtures/amd/nvidia/nvcc.txt create mode 100644 tests/fixtures/amd/nvidia/nvidia-smi.txt create mode 100644 tests/fixtures/amd/nvidia/sys/class/drm/card0/device/vendor create mode 100644 tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_total create mode 100644 tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_used create mode 100644 tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_vram_total create mode 100644 tests/fixtures/amd/nvidia/sys/class/drm/card1/device/vendor create mode 100644 tests/fixtures/amd/strix-halo/rocm/.info/version create mode 100644 tests/fixtures/amd/strix-halo/rocminfo.txt create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1-DP-1/.keep create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1-eDP-1/.keep create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_total create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_used create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_vram_total create mode 100644 tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/vendor create mode 100755 tools/install/test_amd.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b509208f..4adaf5c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,8 @@ jobs: JARVIS=$RUNNER_TEMP/jarvis RENDER_ONLY=1 deploy/mac/install.sh | jq -e --slurpfile p deploy/profiles/mac-apple-silicon.json ' ($p[0].models | map({key: .id, value: .}) | from_entries) as $m | (.tools | length) == ($m | length) and all(.tools[]; .resident_bytes == $m[.id].memory_bytes and .residency == (if $m[.id].warm == true then "always" else "on_demand" end))' > /dev/null + - name: AMD detection against recorded hosts (tests/fixtures/amd; no GPU) + run: bash tools/install/test_amd.sh - run: zig build - run: zig build test timeout-minutes: 20 diff --git a/tests/fixtures/amd/discrete/rocm/.info/version b/tests/fixtures/amd/discrete/rocm/.info/version new file mode 100644 index 00000000..32295ea0 --- /dev/null +++ b/tests/fixtures/amd/discrete/rocm/.info/version @@ -0,0 +1 @@ +6.4.1-120 diff --git a/tests/fixtures/amd/discrete/rocminfo.txt b/tests/fixtures/amd/discrete/rocminfo.txt new file mode 100644 index 00000000..1ace3894 --- /dev/null +++ b/tests/fixtures/amd/discrete/rocminfo.txt @@ -0,0 +1,13 @@ +******* +Agent 1 +******* + Name: Intel(R) Core(TM) i7-14700K + Marketing Name: Intel(R) Core(TM) i7-14700K + Device Type: CPU +******* +Agent 2 +******* + Name: gfx1100 + Marketing Name: Radeon RX 7900 XTX + Device Type: GPU +*** Done *** diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card0/device/vendor b/tests/fixtures/amd/discrete/sys/class/drm/card0/device/vendor new file mode 100644 index 00000000..ce6dc4da --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card0/device/vendor @@ -0,0 +1 @@ +0x8086 diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_total b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_total new file mode 100644 index 00000000..2466bda7 --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_total @@ -0,0 +1 @@ +16777216000 diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_used b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_used new file mode 100644 index 00000000..b7efdd8e --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_gtt_used @@ -0,0 +1 @@ +23068672 diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_vram_total b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_vram_total new file mode 100644 index 00000000..1afcaf38 --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/mem_info_vram_total @@ -0,0 +1 @@ +25753026560 diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card1/device/product_name b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/product_name new file mode 100644 index 00000000..a62b6d64 --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/product_name @@ -0,0 +1 @@ +Radeon RX 7900 XTX diff --git a/tests/fixtures/amd/discrete/sys/class/drm/card1/device/vendor b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/vendor new file mode 100644 index 00000000..7f97d854 --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/class/drm/card1/device/vendor @@ -0,0 +1 @@ +0x1002 diff --git a/tests/fixtures/amd/discrete/sys/module/amdgpu/version b/tests/fixtures/amd/discrete/sys/module/amdgpu/version new file mode 100644 index 00000000..74631a1d --- /dev/null +++ b/tests/fixtures/amd/discrete/sys/module/amdgpu/version @@ -0,0 +1 @@ +6.12.12 diff --git a/tests/fixtures/amd/none/sys/class/drm/.keep b/tests/fixtures/amd/none/sys/class/drm/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/amd/nvidia/nvcc.txt b/tests/fixtures/amd/nvidia/nvcc.txt new file mode 100644 index 00000000..4e76c32c --- /dev/null +++ b/tests/fixtures/amd/nvidia/nvcc.txt @@ -0,0 +1 @@ +Cuda compilation tools, release 13.0, V13.0.88 diff --git a/tests/fixtures/amd/nvidia/nvidia-smi.txt b/tests/fixtures/amd/nvidia/nvidia-smi.txt new file mode 100644 index 00000000..40d578e6 --- /dev/null +++ b/tests/fixtures/amd/nvidia/nvidia-smi.txt @@ -0,0 +1,4 @@ +-L=GPU 0: NVIDIA GB10 (UUID: GPU-XX) +name=NVIDIA GB10 +driver_version=580.95.05 +memory.total=[N/A] diff --git a/tests/fixtures/amd/nvidia/sys/class/drm/card0/device/vendor b/tests/fixtures/amd/nvidia/sys/class/drm/card0/device/vendor new file mode 100644 index 00000000..466e5df4 --- /dev/null +++ b/tests/fixtures/amd/nvidia/sys/class/drm/card0/device/vendor @@ -0,0 +1 @@ +0x10de diff --git a/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_total b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_total new file mode 100644 index 00000000..159b6a76 --- /dev/null +++ b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_total @@ -0,0 +1 @@ +8589934592 diff --git a/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_used b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_used new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_gtt_used @@ -0,0 +1 @@ +0 diff --git a/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_vram_total b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_vram_total new file mode 100644 index 00000000..1f585689 --- /dev/null +++ b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/mem_info_vram_total @@ -0,0 +1 @@ +536870912 diff --git a/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/vendor b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/vendor new file mode 100644 index 00000000..7f97d854 --- /dev/null +++ b/tests/fixtures/amd/nvidia/sys/class/drm/card1/device/vendor @@ -0,0 +1 @@ +0x1002 diff --git a/tests/fixtures/amd/strix-halo/rocm/.info/version b/tests/fixtures/amd/strix-halo/rocm/.info/version new file mode 100644 index 00000000..95c0b3c5 --- /dev/null +++ b/tests/fixtures/amd/strix-halo/rocm/.info/version @@ -0,0 +1 @@ +7.2.4-87 diff --git a/tests/fixtures/amd/strix-halo/rocminfo.txt b/tests/fixtures/amd/strix-halo/rocminfo.txt new file mode 100644 index 00000000..83f34809 --- /dev/null +++ b/tests/fixtures/amd/strix-halo/rocminfo.txt @@ -0,0 +1,35 @@ +ROCk module is loaded +===================== +HSA System Attributes +===================== +Runtime Version: 1.18 +******* +Agent 1 +******* + Name: AMD RYZEN AI MAX+ 395 w/ Radeon 8060S + Uuid: CPU-XX + Marketing Name: AMD RYZEN AI MAX+ 395 w/ Radeon 8060S + Vendor Name: CPU + Device Type: CPU +******* +Agent 2 +******* + Name: gfx1151 + Uuid: GPU-XX + Marketing Name: AMD Radeon 8060S Graphics + Vendor Name: AMD + Device Type: GPU + ISA Info: + ISA 1 + Name: amdgcn-amd-amdhsa--gfx1151 + ISA 2 + Name: amdgcn-amd-amdhsa--gfx11-generic +******* +Agent 3 +******* + Name: aie2p + Uuid: AIE-XX + Marketing Name: NPU Strix Halo + Vendor Name: AMD + Device Type: DSP +*** Done *** diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1-DP-1/.keep b/tests/fixtures/amd/strix-halo/sys/class/drm/card1-DP-1/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1-eDP-1/.keep b/tests/fixtures/amd/strix-halo/sys/class/drm/card1-eDP-1/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_total b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_total new file mode 100644 index 00000000..b1e267f8 --- /dev/null +++ b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_total @@ -0,0 +1 @@ +103079215104 diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_used b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_used new file mode 100644 index 00000000..54b2373a --- /dev/null +++ b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_gtt_used @@ -0,0 +1 @@ +57671680 diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_vram_total b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_vram_total new file mode 100644 index 00000000..7df3e135 --- /dev/null +++ b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/mem_info_vram_total @@ -0,0 +1 @@ +4294967296 diff --git a/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/vendor b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/vendor new file mode 100644 index 00000000..7f97d854 --- /dev/null +++ b/tests/fixtures/amd/strix-halo/sys/class/drm/card1/device/vendor @@ -0,0 +1 @@ +0x1002 diff --git a/tools/install/lib.sh b/tools/install/lib.sh index 75c09a25..792c7d96 100644 --- a/tools/install/lib.sh +++ b/tools/install/lib.sh @@ -43,11 +43,12 @@ hw_os() { if [ $darwin = 1 ]; then echo "macos $(sw_vers -productVersion | cut -d. -f1)"; return; fi (. /etc/os-release 2> /dev/null && echo "${ID:-unknown} ${VERSION_ID:-}") } -# ---- AMD (amdgpu + ROCm), used only when nvidia-smi sees no GPU: the first amdgpu card in sysfs +# ---- AMD (amdgpu + ROCm), used only when nvidia-smi sees no GPU: the first amdgpu card in sysfs. LR_SYSFS (default /sys) +# lets tools/install/test_amd.sh run these against the recorded trees in tests/fixtures/amd. hw_nvidia() { [ $darwin = 0 ] && nvidia-smi -L 2> /dev/null | grep -q GPU; } amd_card() { # the sysfs device directory of the first AMD (vendor 0x1002) DRM card with a GTT counter local d - for d in /sys/class/drm/card[0-9]*/device; do + for d in "${LR_SYSFS:-/sys}"/class/drm/card[0-9]*/device; do [ "$(cat "$d/vendor" 2> /dev/null)" = 0x1002 ] && [ -r "$d/mem_info_gtt_total" ] && { echo "$d"; return; } done return 1 @@ -57,7 +58,9 @@ hw_amd() { [ $darwin = 0 ] && ! hw_nvidia && amd_card > /dev/null; } amd_gfx() { rocminfo 2> /dev/null | awk '/^ *Name: *gfx[0-9a-f]+ *$/ {print $2; exit}'; } amd_name() { local n - n=$(rocminfo 2> /dev/null | awk -F': *' '/Marketing Name:/ && $2 !~ /AMD (RYZEN|EPYC|Ryzen)/ {gsub(/ +$/, "", $2); print $2; exit}') + # the Marketing Name of the first agent whose Device Type is GPU (a CPU agent, AMD's or another vendor's, comes first) + n=$(rocminfo 2> /dev/null | awk -F': *' '/^\*+ *$/ {m = ""} /^ *Marketing Name:/ {m = $2} + /^ *Device Type:/ && $2 ~ /^GPU/ && m != "" {gsub(/ +$/, "", m); print m; exit}') [ -n "$n" ] || n=$(cat "$(amd_card)/product_name" 2> /dev/null) echo "${n:-AMD GPU} ($(amd_gfx || true))" | sed 's/ ()$//' } @@ -75,7 +78,7 @@ hw_gpu() { nvidia-smi --query-gpu=name --format=csv,noheader 2> /dev/null | first } hw_driver() { - if hw_amd; then echo "amdgpu $(cat /sys/module/amdgpu/version 2> /dev/null || uname -r)"; return; fi + if hw_amd; then echo "amdgpu $(cat "${LR_SYSFS:-/sys}/module/amdgpu/version" 2> /dev/null || uname -r)"; return; fi nvidia-smi --query-gpu=driver_version --format=csv,noheader 2> /dev/null | first } # the GPU's own memory in bytes; 0 on a unified-memory GPU (GB10 reports none: its memory is the system's; an AMD APU's diff --git a/tools/install/test_amd.sh b/tools/install/test_amd.sh new file mode 100755 index 00000000..57bbd610 --- /dev/null +++ b/tools/install/test_amd.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# Regression tests of lib.sh's AMD detection against recorded hosts (tests/fixtures/amd/CASE: a sysfs tree, rocminfo +# output, ROCm's version file, nvidia-smi answers), with no GPU: bash tools/install/test_amd.sh +# strix-halo Ryzen AI Max+ 395 / Radeon 8060S (gfx1151): an APU whose GTT pool is its GPU memory; connector entries +# (card1-DP-1) beside the card +# discrete an Intel CPU (rocminfo's first agent) and iGPU (card0) beside a Radeon RX 7900 XTX whose VRAM is real +# nvidia an NVIDIA GPU and an AMD card on one box: the NVIDIA path, unchanged +# none no GPU +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd); fx=$(cd "$here/../../tests/fixtures/amd" && pwd) +fails=0 n=0 +scratch=$(mktemp -d); trap 'rm -rf "$scratch"' EXIT +check() { # NAME GOT WANT + n=$((n + 1)) + if [ "$2" = "$3" ]; then echo "PASS $1"; else echo "FAIL $1: got '$2', want '$3'"; fails=$((fails + 1)); fi +} +# run CASE CMD...: CMD under lib.sh with the case's sysfs, ROCm and stub tools (each absent tool fails, as on a host +# without it); host binaries other than coreutils, awk, jq and sort are not reachable +run() { + local c=$fx/$1; shift + local bin; bin=$(mktemp -d "$scratch/bin.XXXXXX") + for t in awk basename cat cut df dirname grep head id jq realpath sed sort tr uname; do ln -s "$(command -v $t)" "$bin/$t"; done + printf '#!/bin/sh\n[ -f %q ] && exec cat %q\nexit 1\n' "$c/rocminfo.txt" "$c/rocminfo.txt" > "$bin/rocminfo" + cat > "$bin/nvidia-smi" < "$bin/nvcc" + printf '#!/bin/sh\nexit 1\n' > "$bin/hipconfig" + chmod +x "$bin/rocminfo" "$bin/nvidia-smi" "$bin/nvcc" "$bin/hipconfig" + ( PATH=$bin LR_SYSFS=$c/sys ROCM_PATH=$c/rocm NVCC=$bin/nvcc + source "$here/lib.sh"; "$@" ) + rm -rf "$bin" +} +yes_no() { "$@" && echo yes || echo no; } +profile() { local f; f=$(mktemp "$scratch/profile.XXXXXX"); echo "$1" > "$f"; echo "$f"; } +match() { run "$1" hw_match "$2" | grep -E '^(ROCm|GPU target|GTT)' | cut -d' ' -f1-2 | tr '\n' ';'; } + +# strix-halo +check "strix-halo: AMD path" "$(run strix-halo yes_no hw_amd)" yes +check "strix-halo: card (connectors skipped)" "$(run strix-halo amd_card)" "$fx/strix-halo/sys/class/drm/card1/device" +check "strix-halo: gfx" "$(run strix-halo amd_gfx)" gfx1151 +check "strix-halo: GPU name" "$(run strix-halo hw_gpu)" "AMD Radeon 8060S Graphics (gfx1151)" +check "strix-halo: ROCm" "$(run strix-halo hw_rocm)" 7.2.4 +check "strix-halo: GTT" "$(run strix-halo hw_gtt)/$(run strix-halo hw_gtt_used)" 103079215104/57671680 +check "strix-halo: the 4 GiB carve-out is not VRAM (unified)" "$(run strix-halo hw_vram)" 0 +check "strix-halo: driver (in-tree amdgpu: the kernel)" "$(run strix-halo hw_driver)" "amdgpu $(uname -r)" +s=$(run strix-halo hw_summary) +check "strix-halo: summary" "$(echo "$s" | sed 's/memory [0-9.]* GiB/memory M GiB/; s/, [0-9.]* GiB available/, A GiB available/; s/^[^,]*, [^,]*, //; s/driver amdgpu [^)]*/driver amdgpu K/')" \ + "GPU 'AMD Radeon 8060S Graphics (gfx1151)' (driver amdgpu K), ROCm 7.2.4, memory M GiB unified, GTT 96.0 GiB (0.1 GiB in use), A GiB available" +p=$(profile '{"hardware": {"min_memory_gib": 0, "min_rocm": "7.2", "gfx": "gfx1151", "min_gtt_gib": 90, "os": "x"}}') +check "strix-halo: fits min_rocm 7.2, gfx1151, min_gtt_gib 90" "$(match strix-halo "$p")" "" +p=$(profile '{"hardware": {"min_memory_gib": 0, "min_rocm": "7.10", "gfx": "gfx1100", "min_gtt_gib": 100, "os": "x"}}') +check "strix-halo: refused by min_rocm 7.10, gfx1100, min_gtt_gib 100" "$(match strix-halo "$p")" "ROCm '7.2.4';GPU target;GTT 96.0;" + +# discrete +check "discrete: AMD path" "$(run discrete yes_no hw_amd)" yes +check "discrete: the AMD card, not the Intel one" "$(run discrete amd_card)" "$fx/discrete/sys/class/drm/card1/device" +check "discrete: GPU name (the GPU agent, not the Intel CPU)" "$(run discrete hw_gpu)" "Radeon RX 7900 XTX (gfx1100)" +check "discrete: VRAM above GTT is the GPU's own" "$(run discrete hw_vram)" 25753026560 +check "discrete: driver (amdgpu-dkms version)" "$(run discrete hw_driver)" "amdgpu 6.12.12" +check "discrete: ROCm 6.4.1 fails min_rocm 7.2" "$(match discrete "$(profile '{"hardware": {"min_memory_gib": 0, "min_rocm": "7.2", "os": "x"}}')")" "ROCm '6.4.1';" + +# nvidia: what the NVIDIA path said before AMD detection existed +check "nvidia: not the AMD path" "$(run nvidia yes_no hw_amd)" no +check "nvidia: GPU" "$(run nvidia hw_gpu)" "NVIDIA GB10" +check "nvidia: driver" "$(run nvidia hw_driver)" 580.95.05 +check "nvidia: unified (no VRAM figure)" "$(run nvidia hw_vram)" 0 +s=$(run nvidia hw_summary) +check "nvidia: summary unchanged" "$(echo "$s" | sed 's/memory [0-9.]* GiB/memory M GiB/; s/, [0-9.]* GiB available/, A GiB available/; s/^[^,]*, [^,]*, //')" \ + "GPU 'NVIDIA GB10' (driver 580.95.05), CUDA 13.0, memory M GiB unified, A GiB available" +check "nvidia: the AMD keys are ignored when unset" "$(match nvidia "$(profile '{"hardware": {"min_memory_gib": 0, "os": "x"}}')")" "" + +# none +check "none: not AMD" "$(run none yes_no hw_amd)" no +check "none: no GPU" "$(run none hw_gpu)" "" +check "none: GTT 0" "$(run none hw_gtt)" 0 +check "none: no ROCm" "$(run none hw_rocm)" "" + +echo "$((n - fails))/$n passed" +[ $fails = 0 ] From 67a1a4d67c1d6513c47966312ee50efb72d4c5aa Mon Sep 17 00:00:00 2001 From: smfworks Date: Sun, 15 Nov 2026 20:58:55 -0500 Subject: [PATCH 03/13] speech: openai_audio, a cmd worker for any OpenAI-compatible audio server tools/speech/openai_audio/worker.py serves speech (POST /v1/audio/speech, raw PCM streamed into speech.wav) and transcription (POST /v1/audio/transcriptions -> transcript.json) through a model's own server, which it starts from options.server ({port}, {id}, {weights}) and stops on exit, as openai_server does for chat; or an existing options.url. Standard library only. Server 4xx -> invalid_request_error, 503/unreachable -> service_unavailable; 64-bit seeds are folded to 32 bits. test_worker.py runs it against a fake server (no GPU). --- tools/speech/openai_audio/README.md | 35 +++ tools/speech/openai_audio/test_worker.py | 74 +++++ tools/speech/openai_audio/worker.py | 332 +++++++++++++++++++++++ 3 files changed, 441 insertions(+) create mode 100644 tools/speech/openai_audio/README.md create mode 100644 tools/speech/openai_audio/test_worker.py create mode 100644 tools/speech/openai_audio/worker.py diff --git a/tools/speech/openai_audio/README.md b/tools/speech/openai_audio/README.md new file mode 100644 index 00000000..3f4195a8 --- /dev/null +++ b/tools/speech/openai_audio/README.md @@ -0,0 +1,35 @@ +# openai_audio: a `cmd` worker for any OpenAI-compatible audio server + +`worker.py` lets LocalRouter use a model's own speech server (anything that serves OpenAI's +`POST /v1/audio/speech` and/or `POST /v1/audio/transcriptions`) as a `speech` or `transcription` tool, the way the +compiled-in `openai_server` engine does for chat. It is Python standard library only, so it runs under the system +`python3 -I` with no venv. + +- **load**: starts `options.server` (an argv; `{port}`, `{id}` and `{weights}` are filled in) in its own process group + on a loopback port (`options.port`, else a free one) and waits until `options.health` (default `/v1/models`) answers + 200. Without `options.server` it uses `options.url`, a server you run yourself. +- **speech**: asks the server for raw PCM (`response_format: "pcm"`) and writes `speech.wav` as it arrives: a + placeholder header, the samples, then the real sizes. With `"stream": true` in the tool's options the daemon forwards + the audio as it grows (time to first audio is the server's). The rate is the server's `x-sample-rate` header, else + `options.sample_rate` (24000). Seeds are folded to 32 bits. +- **transcription**: posts `audio.wav` (16 kHz mono, prepared by the daemon) as multipart with `language` and `prompt`, + and writes `transcript.json` (`text`, `language`, `duration`, `segments`; one segment when the server gives none). +- **exit / unload**: SIGTERM to the server's process group, progress lines while it stops (so the daemon does not load + anything into memory that is still held), SIGKILL after `options.stop_timeout_s` (15). +- A server 4xx becomes `invalid_request_error` (400), a 503 or an unreachable server `service_unavailable` (503). + Voice cloning and references are refused. + +Declare the model's limits in `options` as for any speech tool (`voices`, `default_voice`, `min_speed`/`max_speed`, +`max_input_chars`, `max_audio_s`, `languages`), and its measured `resident_bytes`. + +```json +{"id": "qwen3-tts-customvoice", "kind": "speech", "capabilities": ["text_to_speech"], + "cmd": ["/usr/bin/python3", "-I", "tools/speech/openai_audio/worker.py"], "weights": "/models/Qwen3-TTS-12Hz-1.7B-CustomVoice", + "resident_bytes": 6979321856, "keep_loaded": true, "lane": "realtime", + "options": {"server": ["tools/gufo/serve.sh", "tts", "{port}", "-v", "{weights}:/m:ro", "--", + "gufo", "serve", "tts", "--model", "/m", "--served-model-name", "{id}"], + "port": 8091, "health": "/v1/audio/voices", "stream": true, "sample_rate": 24000, + "voices": ["ryan", "serena"], "default_voice": "serena", "min_speed": 1, "max_speed": 1}} +``` + +Tests (no GPU, a fake server): `python3 -I tools/speech/openai_audio/test_worker.py`. diff --git a/tools/speech/openai_audio/test_worker.py b/tools/speech/openai_audio/test_worker.py new file mode 100644 index 00000000..08c2fee6 --- /dev/null +++ b/tools/speech/openai_audio/test_worker.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Tests of worker.py against a fake OpenAI audio server (standard library only, no GPU): + python3 -I tools/speech/openai_audio/test_worker.py +The worker starts the fake server itself through options.server (as it starts a real one), speaks the protocol on +stdin/stdout, and stops the server on exit.""" +import json, os, subprocess, sys, tempfile, wave + +HERE = os.path.dirname(os.path.abspath(__file__)) +FAKE = r''' +import json, sys, http.server +port = int(sys.argv[1]) +class H(http.server.BaseHTTPRequestHandler): + protocol_version = "HTTP/1.1" + def log_message(self, *a): pass + def do_GET(self): + b = json.dumps({"data": [{"id": "fake"}]}).encode() + self.send_response(200); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) + def do_POST(self): + body = self.rfile.read(int(self.headers["Content-Length"])) + if self.path == "/v1/audio/speech": + req = json.loads(body) + if req.get("seed", 0) > 0xFFFFFFFF or req.get("voice") == "bad": + b = b'{"error":{"message":"bad"}}' + self.send_response(400); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b); return + pcm = b"\x01\x00" * 2400 + b"\x02" # 0.1 s at 24 kHz plus one stray byte, sent chunked + self.send_response(200); self.send_header("Transfer-Encoding", "chunked"); self.send_header("x-sample-rate", "24000"); self.end_headers() + for i in range(0, len(pcm), 777): + c = pcm[i:i + 777]; self.wfile.write(b"%x\r\n" % len(c) + c + b"\r\n") + self.wfile.write(b"0\r\n\r\n") + else: + ok = b'name="file"' in body and b'name="language"' in body + b = json.dumps({"text": " hello world " if ok else "missing fields"}).encode() + self.send_response(200); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) +http.server.ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever() +''' + +def main(): + tmp = tempfile.mkdtemp() + fake = os.path.join(tmp, "fake.py"); open(fake, "w").write(FAKE) + cfg = {"id": "fake-audio", "load_timeout_s": 20, "options": {"server": [sys.executable, "-I", fake, "{port}"], "stream": True}} + w = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "worker.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, + env={**os.environ, "LOCALROUTER_TOOL": json.dumps(cfg)}, text=True) + def call(obj): + w.stdin.write(json.dumps(obj) + "\n"); w.stdin.flush() + while True: + r = json.loads(w.stdout.readline()) + if "progress" not in r: return r + fails = 0 + def check(name, cond, got=""): + nonlocal fails + print(("PASS " if cond else "FAIL ") + name + ("" if cond else f": {got}")); fails += not cond + r = call({"op": "load"}); check("load", r.get("ok") is True, r) + job = os.path.join(tmp, "job1"); os.mkdir(job) + r = call({"op": "generate", "id": "s1", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v", "seed": 2**40 + 5, "stream": True}}}) + check("speech ok (64-bit seed folded)", r.get("ok") is True and r.get("files") == ["speech.wav"], r) + with wave.open(os.path.join(job, "speech.wav")) as f: + check("speech.wav: 24 kHz mono 16-bit, whole samples", (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes()) == (24000, 1, 2, 2400), + (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes())) + r = call({"op": "generate", "id": "s2", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "bad"}}}) + check("server 4xx is an invalid_request_error", r.get("type") == "invalid_request_error", r) + r = call({"op": "generate", "id": "s3", "dir": job, "request": {"speech": {"input": " "}}}) + check("empty input refused", r.get("type") == "invalid_request_error", r) + open(os.path.join(job, "audio.wav"), "wb").write(b"RIFF....WAVE") + r = call({"op": "generate", "id": "t1", "dir": job, "request": {"transcription": {"audio": "audio.wav", "language": "en", "duration_ms": 1500}}}) + t = json.load(open(os.path.join(job, "transcript.json"))) if r.get("ok") else {} + check("transcription: transcript.json", r.get("ok") is True and t.get("text") == "hello world" and t.get("duration") == 1.5 and len(t.get("segments", [])) == 1, (r, t)) + r = call({"op": "generate", "id": "t2", "dir": job, "request": {"transcription": {"audio": "../x.wav"}}}) + check("audio outside the job dir refused", r.get("type") == "invalid_request_error", r) + w.stdin.write(json.dumps({"op": "exit"}) + "\n"); w.stdin.flush() + check("exit 0", w.wait(timeout=30) == 0) + sys.exit(1 if fails else 0) + +if __name__ == "__main__": + main() diff --git a/tools/speech/openai_audio/worker.py b/tools/speech/openai_audio/worker.py new file mode 100644 index 00000000..5a551bcb --- /dev/null +++ b/tools/speech/openai_audio/worker.py @@ -0,0 +1,332 @@ +#!/usr/bin/env python3 +"""LocalRouter `cmd` worker for any OpenAI-compatible audio server: text to speech through `POST /v1/audio/speech`, +speech to text through `POST /v1/audio/transcriptions` (docs/ARCHITECTURE.md, "the cmd adapter" and "Speech tools"). + +Standard library only, so it runs under the system python3 with no venv. One JSON object a line on stdin and stdout; +stdout carries protocol lines only, logs go to stderr. + {"op":"load"} -> starts options.server (if any) and waits for options.health -> {"ok":true,"resident":0} + {"op":"generate","id","dir","request":{"speech":{...}}} -> speech.wav (RIFF PCM16 mono; streamed if asked) + {"op":"generate","id","dir","request":{"transcription":{...}}} -> transcript.json + {"op":"exit"} or EOF -> stops the server it started, then exits 0 + +The tool's config arrives as JSON in LOCALROUTER_TOOL. Options: + server argv of the model's own server ({port}, {id}, {weights} substituted); absent: use `url` as is + env extra environment for the server + port fixed loopback port for the server (absent: a free one) + url base URL of an already running server (only when `server` is absent), e.g. http://127.0.0.1:8091 + health path that answers 200 when the server is ready (default /v1/models) + model the model id to send (default: the tool's id) + sample_rate PCM rate of the server's "pcm" output (default 24000; an x-sample-rate header wins) + stream true: speech is written to speech.wav as it arrives (the daemon forwards it as HTTP chunks) + send_seed true (default): pass the request's seed through (folded to 32 bits) + extra object merged into every speech request body (e.g. {"language": "English"}) + transcription_format json (default) or verbose_json + stop_timeout_s seconds between SIGTERM and SIGKILL when stopping the server (default 15) +Memory is the config's resident_bytes and working_bytes: measured figures, not guessed here. +""" +import ctypes +import json +import os +import select +import signal +import socket +import struct +import subprocess +import sys +import time +import urllib.error +import urllib.request +import uuid + +PROTO = os.fdopen(os.dup(1), "w", buffering=1) # the protocol stream; fd 1 itself now points at stderr +os.dup2(2, 1) +sys.stdout = sys.stderr +PARENT = int(os.environ.get("LOCALROUTER_PARENT") or 0) + + +class InvalidRequest(Exception): + pass + + +class Unavailable(Exception): + pass + + +def log(msg): + print(f"openai-audio-worker: {msg}", file=sys.stderr, flush=True) + + +def send(obj): + PROTO.write(json.dumps(obj, separators=(",", ":")) + "\n") + PROTO.flush() + + +def orphaned(): + return PARENT not in (0, 1) and os.getppid() != PARENT + + +def die_with_parent(): + try: + ctypes.CDLL(None, use_errno=True).prctl(1, signal.SIGTERM, 0, 0, 0) # PR_SET_PDEATHSIG: stop the server first + except (OSError, AttributeError): + pass + + +_pending = bytearray() + + +def read_line(): + while True: + nl = _pending.find(b"\n") + if nl >= 0: + line = bytes(_pending[:nl]) + del _pending[:nl + 1] + return line + if orphaned(): + log("daemon gone, exiting") + return None + ready, _, _ = select.select([0], [], [], 1.0) + if ready: + chunk = os.read(0, 1 << 16) + if not chunk: + return bytes(_pending) if _pending.strip() else None + _pending.extend(chunk) + + +def free_port(): + with socket.socket() as s: + s.bind(("127.0.0.1", 0)) + return s.getsockname()[1] + + +def wav_header(rate, data_bytes): + return (b"RIFF" + struct.pack(" Date: Mon, 16 Nov 2026 09:19:24 -0500 Subject: [PATCH 04/13] openai_audio: forward the transcription options; explicit timestamps Review of 944f585: transcription replaced the requested temperature with 0 and ignored timestamp granularity, so temperature=0.7 with timestamps=word succeeded with no words. - temperature, language and prompt go to the server as asked. A server that cannot honour one refuses it, and the caller gets that 400 with the server's reason (Gufo's Qwen3-ASR: "supports temperature 0 only"). - options.timestamps lists the granularities the server returns ([] by default). A request for a listed one asks for verbose_json with that timestamp_granularities[] (word also asks for segment when listed), and a reply without them is a server_error, never a transcript missing what was asked. - word not listed is refused (invalid_request_error) before the server is asked. segment not listed keeps the whole clip as one segment, since the daemon asks for segments for every verbose_json, srt and vtt reply. The fake server now records each request's form fields: 23 checks (was 8), covering forwarding, refusals and both timestamp configurations. CI runs them. --- .github/workflows/ci.yml | 2 + tools/speech/openai_audio/README.md | 12 +- tools/speech/openai_audio/test_worker.py | 162 ++++++++++++++++++----- tools/speech/openai_audio/worker.py | 46 ++++++- 4 files changed, 178 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b509208f..fae4681a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,8 @@ jobs: JARVIS=$RUNNER_TEMP/jarvis RENDER_ONLY=1 deploy/mac/install.sh | jq -e --slurpfile p deploy/profiles/mac-apple-silicon.json ' ($p[0].models | map({key: .id, value: .}) | from_entries) as $m | (.tools | length) == ($m | length) and all(.tools[]; .resident_bytes == $m[.id].memory_bytes and .residency == (if $m[.id].warm == true then "always" else "on_demand" end))' > /dev/null + - name: the openai_audio worker against a fake server (no GPU) + run: python3 -I tools/speech/openai_audio/test_worker.py - run: zig build - run: zig build test timeout-minutes: 20 diff --git a/tools/speech/openai_audio/README.md b/tools/speech/openai_audio/README.md index 3f4195a8..ff2b1edf 100644 --- a/tools/speech/openai_audio/README.md +++ b/tools/speech/openai_audio/README.md @@ -12,8 +12,14 @@ compiled-in `openai_server` engine does for chat. It is Python standard library placeholder header, the samples, then the real sizes. With `"stream": true` in the tool's options the daemon forwards the audio as it grows (time to first audio is the server's). The rate is the server's `x-sample-rate` header, else `options.sample_rate` (24000). Seeds are folded to 32 bits. -- **transcription**: posts `audio.wav` (16 kHz mono, prepared by the daemon) as multipart with `language` and `prompt`, - and writes `transcript.json` (`text`, `language`, `duration`, `segments`; one segment when the server gives none). +- **transcription**: posts `audio.wav` (16 kHz mono, prepared by the daemon) as multipart with the request's + `language`, `prompt` and `temperature` as given (never replaced; a server that cannot honour one refuses it, and the + caller gets that 400), and writes `transcript.json` (`text`, `language`, `duration`, `segments`, and `words` when the + server returns them). Timestamps follow `options.timestamps`, the granularities the server returns (`[]` by default, + `["segment"]`, `["segment", "word"]`): a request for a listed granularity asks for `verbose_json` with that + `timestamp_granularities[]`, and a reply without them is an error. `word` not listed is refused (400) before the + server is asked. `segment` not listed gets the whole clip as one segment (the daemon asks for segments for every + `verbose_json`, `srt` and `vtt` reply). Without timestamps it asks for `options.transcription_format` (`json`). - **exit / unload**: SIGTERM to the server's process group, progress lines while it stops (so the daemon does not load anything into memory that is still held), SIGKILL after `options.stop_timeout_s` (15). - A server 4xx becomes `invalid_request_error` (400), a 503 or an unreachable server `service_unavailable` (503). @@ -32,4 +38,4 @@ Declare the model's limits in `options` as for any speech tool (`voices`, `defau "voices": ["ryan", "serena"], "default_voice": "serena", "min_speed": 1, "max_speed": 1}} ``` -Tests (no GPU, a fake server): `python3 -I tools/speech/openai_audio/test_worker.py`. +Tests (no GPU, a fake server that records what it was sent): `python3 -I tools/speech/openai_audio/test_worker.py`. diff --git a/tools/speech/openai_audio/test_worker.py b/tools/speech/openai_audio/test_worker.py index 08c2fee6..7efb7d5d 100644 --- a/tools/speech/openai_audio/test_worker.py +++ b/tools/speech/openai_audio/test_worker.py @@ -2,72 +2,166 @@ """Tests of worker.py against a fake OpenAI audio server (standard library only, no GPU): python3 -I tools/speech/openai_audio/test_worker.py The worker starts the fake server itself through options.server (as it starts a real one), speaks the protocol on -stdin/stdout, and stops the server on exit.""" +stdin/stdout, and stops the server on exit. The fake records every transcription request's form fields, so the tests +see what the worker forwarded.""" import json, os, subprocess, sys, tempfile, wave HERE = os.path.dirname(os.path.abspath(__file__)) FAKE = r''' -import json, sys, http.server -port = int(sys.argv[1]) +import json, re, sys, http.server +port, record = int(sys.argv[1]), sys.argv[2] +def fields(body, ctype): + bound = ctype.split("boundary=")[1].encode() + out = [] + for part in body.split(b"--" + bound)[1:-1]: + head, _, data = part.partition(b"\r\n\r\n") + name = re.search(rb'name="([^"]+)"', head).group(1).decode() + if b"filename=" not in head: + out.append([name, data[:-2].decode()]) + else: + out.append([name, ""]) + return out class H(http.server.BaseHTTPRequestHandler): protocol_version = "HTTP/1.1" def log_message(self, *a): pass + def reply(self, code, obj): + b = json.dumps(obj).encode() + self.send_response(code); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) def do_GET(self): - b = json.dumps({"data": [{"id": "fake"}]}).encode() - self.send_response(200); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) + self.reply(200, {"data": [{"id": "fake"}]}) def do_POST(self): body = self.rfile.read(int(self.headers["Content-Length"])) if self.path == "/v1/audio/speech": req = json.loads(body) if req.get("seed", 0) > 0xFFFFFFFF or req.get("voice") == "bad": - b = b'{"error":{"message":"bad"}}' - self.send_response(400); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b); return + return self.reply(400, {"error": {"message": "bad"}}) pcm = b"\x01\x00" * 2400 + b"\x02" # 0.1 s at 24 kHz plus one stray byte, sent chunked self.send_response(200); self.send_header("Transfer-Encoding", "chunked"); self.send_header("x-sample-rate", "24000"); self.end_headers() for i in range(0, len(pcm), 777): c = pcm[i:i + 777]; self.wfile.write(b"%x\r\n" % len(c) + c + b"\r\n") self.wfile.write(b"0\r\n\r\n") - else: - ok = b'name="file"' in body and b'name="language"' in body - b = json.dumps({"text": " hello world " if ok else "missing fields"}).encode() - self.send_response(200); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) + return + f = fields(body, self.headers["Content-Type"]) + with open(record, "a") as r: + r.write(json.dumps(f) + "\n") + d = {} + for k, v in f: + d.setdefault(k, []).append(v) + if float(d.get("temperature", ["0"])[0]) > 1: + return self.reply(400, {"error": {"message": "temperature above 1 is not supported"}}) + ok = "file" in d and "language" in d + res = {"text": " hello world " if ok else "missing fields"} + grans = d.get("timestamp_granularities[]", []) + if d.get("response_format") == ["verbose_json"]: + res.update({"language": "english", "duration": 1.5}) + if "segment" in grans and d.get("prompt") != ["nothing"]: + res["segments"] = [{"id": 0, "start": 0.0, "end": 0.7, "text": "hello"}, {"id": 1, "start": 0.7, "end": 1.5, "text": "world"}] + if "word" in grans and d.get("prompt") != ["nothing"]: + res["words"] = [{"word": "hello", "start": 0.1, "end": 0.6}, {"word": "world", "start": 0.8, "end": 1.4}] + self.reply(200, res) http.server.ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever() ''' -def main(): - tmp = tempfile.mkdtemp() - fake = os.path.join(tmp, "fake.py"); open(fake, "w").write(FAKE) - cfg = {"id": "fake-audio", "load_timeout_s": 20, "options": {"server": [sys.executable, "-I", fake, "{port}"], "stream": True}} - w = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "worker.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, - env={**os.environ, "LOCALROUTER_TOOL": json.dumps(cfg)}, text=True) - def call(obj): - w.stdin.write(json.dumps(obj) + "\n"); w.stdin.flush() +fails = 0 +def check(name, cond, got=""): + global fails + print(("PASS " if cond else "FAIL ") + name + ("" if cond else f": {got}")); fails += not cond + + +class W: + """One worker (and its fake server) for a tool config's options.""" + def __init__(self, tmp, name, **opts): + self.record = os.path.join(tmp, name + ".jsonl") + fake = os.path.join(tmp, "fake.py") + cfg = {"id": "fake-audio", "load_timeout_s": 20, "options": {"server": [sys.executable, "-I", fake, "{port}", self.record], **opts}} + self.p = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "worker.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, + env={**os.environ, "LOCALROUTER_TOOL": json.dumps(cfg)}, text=True) + def call(self, obj): + self.p.stdin.write(json.dumps(obj) + "\n"); self.p.stdin.flush() while True: - r = json.loads(w.stdout.readline()) + r = json.loads(self.p.stdout.readline()) if "progress" not in r: return r - fails = 0 - def check(name, cond, got=""): - nonlocal fails - print(("PASS " if cond else "FAIL ") + name + ("" if cond else f": {got}")); fails += not cond - r = call({"op": "load"}); check("load", r.get("ok") is True, r) + def sent(self): + """The form fields of the transcription requests the server got, oldest first ([[name, value], ...] each).""" + return [json.loads(l) for l in open(self.record)] if os.path.exists(self.record) else [] + def exit(self): + self.p.stdin.write(json.dumps({"op": "exit"}) + "\n"); self.p.stdin.flush() + return self.p.wait(timeout=30) + + +def transcribe(w, job, n, **q): + r = w.call({"op": "generate", "id": f"t{n}", "dir": job, "request": {"transcription": {"audio": "audio.wav", "language": "en", "duration_ms": 1500, **q}}}) + t = json.load(open(os.path.join(job, "transcript.json"))) if r.get("ok") else {} + return r, t + + +def field(sent, name): + return [v for k, v in sent if k == name] + + +def main(): + tmp = tempfile.mkdtemp() + open(os.path.join(tmp, "fake.py"), "w").write(FAKE) job = os.path.join(tmp, "job1"); os.mkdir(job) - r = call({"op": "generate", "id": "s1", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v", "seed": 2**40 + 5, "stream": True}}}) + open(os.path.join(job, "audio.wav"), "wb").write(b"RIFF....WAVE") + + # a server without timestamps (Gufo's Qwen3-ASR: no timestamp_granularities, temperature 0 only) + w = W(tmp, "plain", stream=True) + r = w.call({"op": "load"}); check("load", r.get("ok") is True, r) + r = w.call({"op": "generate", "id": "s1", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v", "seed": 2**40 + 5, "stream": True}}}) check("speech ok (64-bit seed folded)", r.get("ok") is True and r.get("files") == ["speech.wav"], r) with wave.open(os.path.join(job, "speech.wav")) as f: check("speech.wav: 24 kHz mono 16-bit, whole samples", (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes()) == (24000, 1, 2, 2400), (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes())) - r = call({"op": "generate", "id": "s2", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "bad"}}}) + r = w.call({"op": "generate", "id": "s2", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "bad"}}}) check("server 4xx is an invalid_request_error", r.get("type") == "invalid_request_error", r) - r = call({"op": "generate", "id": "s3", "dir": job, "request": {"speech": {"input": " "}}}) + r = w.call({"op": "generate", "id": "s3", "dir": job, "request": {"speech": {"input": " "}}}) check("empty input refused", r.get("type") == "invalid_request_error", r) - open(os.path.join(job, "audio.wav"), "wb").write(b"RIFF....WAVE") - r = call({"op": "generate", "id": "t1", "dir": job, "request": {"transcription": {"audio": "audio.wav", "language": "en", "duration_ms": 1500}}}) - t = json.load(open(os.path.join(job, "transcript.json"))) if r.get("ok") else {} + r, t = transcribe(w, job, 1) check("transcription: transcript.json", r.get("ok") is True and t.get("text") == "hello world" and t.get("duration") == 1.5 and len(t.get("segments", [])) == 1, (r, t)) - r = call({"op": "generate", "id": "t2", "dir": job, "request": {"transcription": {"audio": "../x.wav"}}}) + s = w.sent()[-1] + check("default: temperature 0, response_format json, no granularities", (field(s, "temperature"), field(s, "response_format"), field(s, "timestamp_granularities[]")) == (["0"], ["json"], []), s) + r, t = transcribe(w, job, 2, temperature=0.7, prompt="names: Ada", timestamps="segment") + s = w.sent()[-1] + check("temperature 0.7 is forwarded, not replaced by 0", field(s, "temperature") == ["0.7"], s) + check("language and prompt are forwarded", (field(s, "language"), field(s, "prompt")) == (["en"], ["names: Ada"]), s) + check("segment, not declared: the whole clip as one segment, no granularity sent", + r.get("ok") is True and field(s, "timestamp_granularities[]") == [] and t.get("segments") == [{"id": 0, "start": 0.0, "end": 1.5, "text": "hello world"}], (r, t, s)) + n = len(w.sent()) + r, t = transcribe(w, job, 3, temperature=0.7, timestamps="word") + check("word, not declared: refused before the server is asked", r.get("type") == "invalid_request_error" and "word" in r.get("error", "") and len(w.sent()) == n, (r, len(w.sent()))) + r, t = transcribe(w, job, 4, temperature=1.5) + check("a temperature the server refuses is the caller's 400, with the server's reason", + r.get("type") == "invalid_request_error" and "temperature above 1" in r.get("error", "") and field(w.sent()[-1], "temperature") == ["1.5"], r) + r, t = transcribe(w, job, 5, timestamps="phoneme") + check("an unknown timestamps value is refused", r.get("type") == "invalid_request_error", r) + r, t = transcribe(w, job, 6, temperature="warm") + check("a temperature that is not a number is refused", r.get("type") == "invalid_request_error", r) + r = w.call({"op": "generate", "id": "t7", "dir": job, "request": {"transcription": {"audio": "../x.wav"}}}) check("audio outside the job dir refused", r.get("type") == "invalid_request_error", r) - w.stdin.write(json.dumps({"op": "exit"}) + "\n"); w.stdin.flush() - check("exit 0", w.wait(timeout=30) == 0) + check("exit 0", w.exit() == 0) + + # a server with segment and word timestamps (an OpenAI-style Whisper server) + w = W(tmp, "stamped", timestamps=["segment", "word"]) + r, t = transcribe(w, job, 10, temperature=0.7, timestamps="word") + s = w.sent()[-1] + check("word, declared: verbose_json with segment and word granularities", + (field(s, "response_format"), field(s, "timestamp_granularities[]"), field(s, "temperature")) == (["verbose_json"], ["segment", "word"], ["0.7"]), s) + check("word, declared: the words and the server's segments in transcript.json", + r.get("ok") is True and [x["word"] for x in t.get("words", [])] == ["hello", "world"] and len(t.get("segments", [])) == 2, (r, t)) + r, t = transcribe(w, job, 11, timestamps="segment") + s = w.sent()[-1] + check("segment, declared: verbose_json with the segment granularity only", + (field(s, "response_format"), field(s, "timestamp_granularities[]")) == (["verbose_json"], ["segment"]) and len(t.get("segments", [])) == 2 and "words" not in t, (s, t)) + r, t = transcribe(w, job, 12, timestamps="none") + s = w.sent()[-1] + check("none: no granularities, the default response_format", (field(s, "response_format"), field(s, "timestamp_granularities[]")) == (["json"], []), s) + r, t = transcribe(w, job, 13, timestamps="word", prompt="nothing") + check("word, declared, none returned: a server error, not a transcript without words", r.get("ok") is False and r.get("type") == "server_error" and "words" in r.get("error", ""), r) + r, t = transcribe(w, job, 14, timestamps="segment", prompt="nothing") + check("segment, declared, none returned: a server error", r.get("ok") is False and r.get("type") == "server_error", r) + check("exit 0 (timestamps worker)", w.exit() == 0) + print(f"{'FAILED' if fails else 'ok'}: {fails} failure(s)") sys.exit(1 if fails else 0) if __name__ == "__main__": diff --git a/tools/speech/openai_audio/worker.py b/tools/speech/openai_audio/worker.py index 5a551bcb..acf2b288 100644 --- a/tools/speech/openai_audio/worker.py +++ b/tools/speech/openai_audio/worker.py @@ -20,7 +20,9 @@ stream true: speech is written to speech.wav as it arrives (the daemon forwards it as HTTP chunks) send_seed true (default): pass the request's seed through (folded to 32 bits) extra object merged into every speech request body (e.g. {"language": "English"}) - transcription_format json (default) or verbose_json + transcription_format json (default) or verbose_json: what a request without timestamps asks the server for + timestamps the timestamp_granularities the server returns: [] (default), ["segment"], ["segment", "word"]. A + request for a granularity listed here asks for verbose_json with it; "word" not listed is refused stop_timeout_s seconds between SIGTERM and SIGKILL when stopping the server (default 15) Memory is the config's resident_bytes and working_bytes: measured figures, not guessed here. """ @@ -118,6 +120,7 @@ def __init__(self, cfg): self.proc = None self.base = None self.model = self.opts.get("model") or cfg.get("id") or "" + self.timestamps = [g for g in (self.opts.get("timestamps") or []) if g in ("segment", "word")] # ---- the server def healthy(self, timeout=2.0): @@ -255,18 +258,42 @@ def speech(self, s, job_dir, timeout): f.write(wav_header(rate, n)) return {"ok": True, "files": ["speech.wav"], "seed": seed} + def transcription_fields(self, q): + """The form fields of one transcription request: the request's options forwarded as asked, never replaced. + temperature goes through as given (a server that cannot honour it refuses, and that refusal is the caller's + 400). timestamps: "none" asks for options.transcription_format; "segment" or "word" asks for verbose_json with + that timestamp_granularities[] when options.timestamps lists it. "word" without it is refused here, before the + server is asked. "segment" without it gets the whole clip as one segment (verbose_json, srt and vtt carry + segments, so the daemon asks every such request for them).""" + want = q.get("timestamps") or "none" + if want not in ("none", "segment", "word"): + raise InvalidRequest(f"timestamps must be none, segment or word, not {want!r}") + if want == "word" and "word" not in self.timestamps: + raise InvalidRequest("this tool has no word timestamps (its options.timestamps does not list word)") + try: + temperature = float(q.get("temperature") or 0) + except (TypeError, ValueError): + raise InvalidRequest("temperature must be a number") + fields = [("model", self.model), ("temperature", f"{temperature:g}")] + if want in self.timestamps: + fields.append(("response_format", "verbose_json")) + grans = ["segment", "word"] if want == "word" and "segment" in self.timestamps else [want] + fields += [("timestamp_granularities[]", g) for g in grans] + else: + fields.append(("response_format", self.opts.get("transcription_format", "json"))) + for k in ("language", "prompt"): + if q.get(k): + fields.append((k, str(q[k]))) + return fields + def transcription(self, q, job_dir, timeout): audio = q.get("audio") or "" if not audio or os.path.basename(audio) != audio or audio.startswith("."): raise InvalidRequest("audio must name a file in the job directory") - fmt = self.opts.get("transcription_format", "json") - fields = {"model": self.model, "response_format": fmt, "temperature": "0"} - for k in ("language", "prompt"): - if q.get(k): - fields[k] = str(q[k]) + fields = self.transcription_fields(q) b = uuid.uuid4().hex body = bytearray() - for k, v in fields.items(): + for k, v in fields: body += f'--{b}\r\nContent-Disposition: form-data; name="{k}"\r\n\r\n{v}\r\n'.encode() with open(os.path.join(job_dir, audio), "rb") as f: data = f.read() @@ -274,6 +301,11 @@ def transcription(self, q, job_dir, timeout): f'Content-Type: audio/wav\r\n\r\n').encode() + data + f"\r\n--{b}--\r\n".encode() with self.post("/v1/audio/transcriptions", bytes(body), f"multipart/form-data; boundary={b}", timeout) as r: res = json.loads(r.read()) + want = q.get("timestamps") or "none" + if want in self.timestamps: + key = "words" if want == "word" else "segments" + if not res.get(key): + raise RuntimeError(f"the model's server returned no {key}, though the tool's options.timestamps lists {want}") duration = float(q.get("duration_ms") or 0) / 1000 or float(res.get("duration") or 0) text = (res.get("text") or "").strip() segments = res.get("segments") or [{"id": 0, "start": 0.0, "end": round(duration, 3), "text": text}] From 0e6ab47b419c5ff6c4136c07b3177a386a27566a Mon Sep 17 00:00:00 2001 From: smfworks Date: Sun, 15 Nov 2026 20:58:55 -0500 Subject: [PATCH 05/13] whisper: a ROCm venv for the Linux worker (torch 2.13.0+rocm7.2) tools/speech/whisper/rocm/{pyproject.toml,uv.lock}: the same worker and pins as the Spark, with torch and triton-rocm from PyTorch's ROCm 7.2 index for x86_64 Linux AMD GPUs. The existing lock is untouched. Measured on gfx1151: WER 4.09% on 73 LibriSpeech clips, 17x real time. --- tools/speech/whisper/rocm/README.md | 17 + tools/speech/whisper/rocm/pyproject.toml | 27 ++ tools/speech/whisper/rocm/uv.lock | 467 +++++++++++++++++++++++ 3 files changed, 511 insertions(+) create mode 100644 tools/speech/whisper/rocm/README.md create mode 100644 tools/speech/whisper/rocm/pyproject.toml create mode 100644 tools/speech/whisper/rocm/uv.lock diff --git a/tools/speech/whisper/rocm/README.md b/tools/speech/whisper/rocm/README.md new file mode 100644 index 00000000..136d49dc --- /dev/null +++ b/tools/speech/whisper/rocm/README.md @@ -0,0 +1,17 @@ +# Whisper on AMD GPUs (PyTorch ROCm) + +The same worker as the Spark (`../worker.py`, `../whisper_core.py`) with a venv locked to PyTorch's ROCm 7.2 wheels +(torch 2.13.0+rocm7.2, the release the other workers pin). On ROCm `torch.cuda` is the HIP device, so the tool's +`options.device` stays `"cuda"` (or `"auto"`). + +```sh +UV_PROJECT_ENVIRONMENT=$J/venvs/whisper-rocm uv sync --locked --python 3.12 --project tools/speech/whisper/rocm +python3 -I tools/speech/whisper/fetch_model.py --root $J/models/whisper +``` + +Tool: `"cmd": ["$J/venvs/whisper-rocm/bin/python", "tools/speech/whisper/worker.py"]`, options +`{"device": "cuda", "dtype": "float16", "attn": "sdpa", "vad": "silero", "vad_model": ...}` (or `"vad": "off"`). + +Measured on a Radeon 8060S (gfx1151), 2026-11-15: 73 LibriSpeech dev-clean clips (481 s), WER 4.09% (honorifics +normalized), 17x real time, 373 ms median per clip, 1.6 GiB allocated (2.3 GiB GTT); 9.8 s cold load through the daemon, +0.5 s per short clip warm. diff --git a/tools/speech/whisper/rocm/pyproject.toml b/tools/speech/whisper/rocm/pyproject.toml new file mode 100644 index 00000000..42b1c2b0 --- /dev/null +++ b/tools/speech/whisper/rocm/pyproject.toml @@ -0,0 +1,27 @@ +[project] +name = "localrouter-speech-whisper-rocm" +version = "0.1.0" +description = "Whisper large-v3-turbo speech-to-text worker for LocalRouter's cmd adapter on AMD GPUs (PyTorch ROCm)" +requires-python = "==3.12.*" +dependencies = [ + "torch==2.13.0", # the same release as the Spark and Mac workers, from PyTorch's ROCm 7.2 index + "transformers==5.19.0", + "numpy==2.5.4", + "triton-rocm==3.7.1", # torch's own pin, listed so uv takes it from the ROCm index (a source covers direct dependencies) +] + +[tool.uv] +package = false +# x86_64 Linux with an AMD GPU (ROCm 7.2 wheels; tested on Strix Halo, gfx1151). The worker itself is ../worker.py: +# torch.cuda is ROCm's HIP device, so options.device "cuda" (or "auto") runs it on the GPU. +# UV_PROJECT_ENVIRONMENT=$J/venvs/whisper-rocm uv sync --locked --python 3.12 --project tools/speech/whisper/rocm +environments = ["sys_platform == 'linux' and platform_machine == 'x86_64'"] + +[tool.uv.sources] +torch = [{ index = "pytorch-rocm72" }] +triton-rocm = [{ index = "pytorch-rocm72" }] + +[[tool.uv.index]] +name = "pytorch-rocm72" +url = "https://download.pytorch.org/whl/rocm7.2" +explicit = true diff --git a/tools/speech/whisper/rocm/uv.lock b/tools/speech/whisper/rocm/uv.lock new file mode 100644 index 00000000..8e339fcc --- /dev/null +++ b/tools/speech/whisper/rocm/uv.lock @@ -0,0 +1,467 @@ +version = 1 +revision = 5 +requires-python = "==3.12.*" +resolution-markers = [ + "platform_machine == 'x86_64' and sys_platform == 'linux'", +] +supported-markers = [ + "platform_machine == 'x86_64' and sys_platform == 'linux'", +] + +[[package]] +name = "annotated-doc" +version = "0.0.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0f/6e/a61e86e43bb6039b31a33a8f5fba76fe1cdacf3661e7b9756d4ff1b28cdc/annotated_doc-0.0.6.tar.gz", hash = "sha256:7969bb69912085b2285849c0dcac0b4b374fd180c13cf10a87f284ffcf347bbf", size = 10767, upload-time = "2026-11-10T18:17:11.28Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cd/f5/3dd85d583e55be76cd02b1fc9bbec771b12d63124b01661d9535ccf8721f/annotated_doc-0.0.6-py3-none-any.whl", hash = "sha256:361ca0950cc7082f53fa69e9328409f40a62c61e57e0a47e1825a08078a58a53", size = 5293, upload-time = "2026-11-10T18:17:10.249Z" }, +] + +[[package]] +name = "annotated-types" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5f/56/a8120250d128bed162cd73c76d45f6ef9991f3e068f62a8ee060afa3104a/annotated_types-0.8.0.tar.gz", hash = "sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7", size = 15893, upload-time = "2026-07-23T20:16:13.995Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/99/91/8acff4f5e50511b911bbccb72b8628a49c68ce14148cd9f6431094859a90/annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", size = 13427, upload-time = "2026-07-23T20:16:12.938Z" }, +] + +[[package]] +name = "anyio" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a1/98/7e457a3b014976887a050561955c0b76e1e7e2d6e27b78ecef2ef80518f2/anyio-4.16.0.tar.gz", hash = "sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb", size = 310971, upload-time = "2026-11-01T11:20:07.282Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a9/16/7757fb84c819accc7d7e9af5291b261e4abb8627ee040f99e7d35ef2457a/anyio-4.16.0-py3-none-any.whl", hash = "sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026", size = 134521, upload-time = "2026-11-01T11:20:05.59Z" }, +] + +[[package]] +name = "click" +version = "8.5.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/45/37/edbf1b0707709013c0cf2e8317e03d97ed29bf4cac709fe328904ae92a38/click-8.5.1.tar.gz", hash = "sha256:9bbfada76703fd1d784b83eea012e3e8c6a001a876543ef104fa56aaaeb072b4", size = 399151, upload-time = "2026-11-06T17:37:01.021Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/31/7d/164b7ffc8624fe9efb4221bf9af485d5c1e41b9ae118045d2b6dc5457d8b/click-8.5.1-py3-none-any.whl", hash = "sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37", size = 126163, upload-time = "2026-11-06T17:36:59.287Z" }, +] + +[[package]] +name = "filelock" +version = "4.2.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a1/cf/05bcdacabdc0aec7dc8e19d76281bd82325df62dae3b6430e9ba57397689/filelock-4.2.10.tar.gz", hash = "sha256:fcc3c0cb8bfe7f4b3bb0e231c04b15dbad068cb3c2515f343d8fde4dce93bd5d", size = 670595, upload-time = "2026-11-09T18:58:00.54Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/90/5d0096a325aa0f83ba7a3968bfb485b67e32c947bdf9cd0fcb4b485be718/filelock-4.2.10-py3-none-any.whl", hash = "sha256:9479aaeb4db20b5a53e3da28493edd24720b66b8a0b84030aa56ccdf243d6857", size = 218040, upload-time = "2026-11-09T18:57:59.088Z" }, +] + +[[package]] +name = "fsspec" +version = "2026.9.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/77/cd/9be253869fc42e764de7f3dedd6969af7d44ff9c3375214a3442a6f3fc08/fsspec-2026.9.0.tar.gz", hash = "sha256:0f08147951c8cb31d844c3547d631053b127863b60be04cf06e121333ee0e2fe", size = 333545, upload-time = "2026-09-18T17:50:42.825Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6c/c0/a98505f18594f1bce828bb159cec0fcf9860562f1a2c85913409fc8f3d9e/fsspec-2026.9.0-py3-none-any.whl", hash = "sha256:8dd6e646e99ea382bd85f97a45e6b526a442d79423a7dc673f1e2756d05fcb5f", size = 221738, upload-time = "2026-09-18T17:50:41.341Z" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" }, +] + +[[package]] +name = "hf-xet" +version = "1.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/2f/18/d91c20f815df6cc496a5d0ad8db6d274dad5c0cfcd59babfa2440a9aba44/hf_xet-1.8.0.tar.gz", hash = "sha256:10ed23b51dacf7917d64f335c25048deb470efa755e9989b218fc0531386138e", size = 1013014, upload-time = "2026-10-30T10:04:33.741Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f8/1e/1e8ecc05ef034e9a95c18ed32d2ec07905a7cd2ca611a9d88e25ee1f4850/hf_xet-1.8.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:29dab7c904cd1914a0439c6e1306c12c7497c8bd32290fbe563ebf51ca4b6d6d", size = 4292483, upload-time = "2026-10-30T10:04:22.875Z" }, + { url = "https://files.pythonhosted.org/packages/48/77/886f09e91a5eadb054ce03b8855323cd2a72f20db76ab4119e0ecda65eef/hf_xet-1.8.0-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1ebaf248c9bef8bb0c9d1d8d71db1fdf0cac14f922cc7a936a81adbf12eb5f01", size = 4500689, upload-time = "2026-10-30T10:04:28.394Z" }, +] + +[[package]] +name = "httpcore2" +version = "2.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h11" }, + { name = "truststore" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c0/61/afa9d6b7452f9eca73f73d45324eb0bb52f098fd5e6049bf6b8263be9b4e/httpcore2-2.16.0.tar.gz", hash = "sha256:c72cd0413563b17e1cd8354677dff887466f8ec2551679759e93126534428643", size = 69886, upload-time = "2026-10-21T07:09:45.31Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/af/c2/ce417c397afa5181f0e3c6ff01a4d01639414e1adef08730d97571297151/httpcore2-2.16.0-py3-none-any.whl", hash = "sha256:5c4358319f2602d984ad93182c9fee5160f22e9da7babdda870a5e7c4e2dc34f", size = 85070, upload-time = "2026-10-21T07:09:42.802Z" }, +] + +[[package]] +name = "httpx2" +version = "2.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "httpcore2" }, + { name = "idna" }, + { name = "truststore" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/43/73/5ca2cedf5e4e50423d1c258877865a6b62793633b561c58499f8aeb33b7e/httpx2-2.16.0.tar.gz", hash = "sha256:0d54c98128e8f2ff7fbbde0fca8c359e5f032edeaaaac443cdb7f31f685bcd7f", size = 103116, upload-time = "2026-10-21T07:09:46.348Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7b/3d/2e4bc4fd1ef9770871669adb348d612a6e4786b303a23f9935b81c48dd60/httpx2-2.16.0-py3-none-any.whl", hash = "sha256:fd2c5d7909e8d86fe92d53020c310ca0e4e431b838c207c5754b9bbf0308d49a", size = 97880, upload-time = "2026-10-21T07:09:44.01Z" }, +] + +[[package]] +name = "huggingface-hub" +version = "2.4.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "filelock" }, + { name = "fsspec" }, + { name = "hf-xet" }, + { name = "httpx2" }, + { name = "packaging" }, + { name = "pyyaml" }, + { name = "tqdm" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b5/3b/2fcef1eabe52aec90fc8cd253cc154da1d02a446d7bbcdec59b4a51d4be7/huggingface_hub-2.4.0.tar.gz", hash = "sha256:13a6158b9e3393d9d3f248ce99074d50c2a0a1449fb9d8e2f710751e2084c188", size = 1066194, upload-time = "2026-10-29T15:30:12.321Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d4/55/ff47f1b082ecf5f43f4bc1e3b932d68eead171dabbbd1a92666c686301d7/huggingface_hub-2.4.0-py3-none-any.whl", hash = "sha256:42ecfd93ede47bdd333daebbf66a32d7bfe2e18752754fe4d2d4f98a0179d801", size = 857021, upload-time = "2026-10-29T15:30:10.421Z" }, +] + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f5/08/8eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa/idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44", size = 216463, upload-time = "2026-09-17T14:11:04.752Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" }, +] + +[[package]] +name = "jinja2" +version = "3.1.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, +] + +[[package]] +name = "localrouter-speech-whisper-rocm" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "numpy" }, + { name = "torch" }, + { name = "transformers" }, + { name = "triton-rocm" }, +] + +[package.metadata] +requires-dist = [ + { name = "numpy", specifier = "==2.5.4" }, + { name = "torch", specifier = "==2.13.0", index = "https://download.pytorch.org/whl/rocm7.2" }, + { name = "transformers", specifier = "==5.19.0" }, + { name = "triton-rocm", specifier = "==3.7.1", index = "https://download.pytorch.org/whl/rocm7.2" }, +] + +[[package]] +name = "markdown-it-py" +version = "4.3.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/16/fc/cee2c45553c9a9bf77d8b0c391560c556d7ed756b1f0bb35eb5d48db09ea/markdown_it_py-4.3.0.tar.gz", hash = "sha256:91a58fa5b72c71a40cf7177250fd767480d7a2bb3ac426ccfb76fb90305fdaaa", size = 242701, upload-time = "2026-11-10T16:18:30.467Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c9/31/5f0ac2f1a1c67423c995c731a11cd4ad05d081a2be969d74f868bdb9cc70/markdown_it_py-4.3.0-py3-none-any.whl", hash = "sha256:7aa1511a46c39138de78d9eba92ce47e63124d8003fc98b3a351909e04239efa", size = 96951, upload-time = "2026-11-10T16:18:28.975Z" }, +] + +[[package]] +name = "markupsafe" +version = "3.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/38/9b/e422a865e1d5d57d0e509b4e0bf1c1a70a7f6382c29a5aa428df994c8bc8/markupsafe-3.0.4.tar.gz", hash = "sha256:2e9ad7dd851bf45fab9f75cbff4cb493fee9979e8d8c7c9c3ee119022518edd6", size = 153777, upload-time = "2026-10-02T23:07:22.29Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4f/a7/aeedb5140afa41fc74c225e9184ab96723a6e873b6ee1c9fede7283456d8/markupsafe-3.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8e124f974786f831d6043728e38296969d3579db8896fe004682f5758e613581", size = 22985, upload-time = "2026-10-02T23:04:57.521Z" }, + { url = "https://files.pythonhosted.org/packages/0c/fe/fb1e79be0fea60aa32602ebefc9c35a82bb42b4df157285ab7dfec12341a/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c9a7f43c0b202b334cc9184af09bb8f21d3a209e038efaf106936fb69e6b026e", size = 23048, upload-time = "2026-10-02T23:05:04.479Z" }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" }, +] + +[[package]] +name = "mpmath" +version = "1.3.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e0/47/dd32fa426cc72114383ac549964eecb20ecfd886d1e5ccf5340b55b02f57/mpmath-1.3.0.tar.gz", hash = "sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f", size = 508106, upload-time = "2023-03-07T16:47:11.061Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/43/e3/7d92a15f894aa0c9c4b49b8ee9ac9850d6e63b03c9c32c0367a13ae62209/mpmath-1.3.0-py3-none-any.whl", hash = "sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c", size = 536198, upload-time = "2023-03-07T16:47:09.197Z" }, +] + +[[package]] +name = "networkx" +version = "3.7" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/dc/76/3af777226b63a5e64a6b36b1ec5855c14e2b94a37096d4760e595fc43511/networkx-3.7.tar.gz", hash = "sha256:fd77a511bd90f39f3d016351345b52cf5319b813bdca01de3f755d3cca62e96a", size = 1866482, upload-time = "2026-09-21T16:45:16.974Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/cd/fe58041e9011f307c490e3e17dd48cc516448f7c698a3f2d9d9d65d7e6a8/networkx-3.7-py3-none-any.whl", hash = "sha256:e3fd2c13a7814cee3746340d8d7f8598a67f16a58bf47fb7f8793fab6efca1b0", size = 2142205, upload-time = "2026-09-21T16:45:14.609Z" }, +] + +[[package]] +name = "numpy" +version = "2.5.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/95/b0/c7453d0b6e2073c3264468b106ee1563750cecc910965e67357e3698c83e/numpy-2.5.4.tar.gz", hash = "sha256:9a94cf751c9ad8ebaa835bcd3d40dacf8534ad086b88c38029b65123c7999d2a", size = 20866315, upload-time = "2026-10-10T20:05:31.422Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/43/a3/c799c62e19c337e6d3770b08e475887fb30ce8477d3c09efca6b2f0228a6/numpy-2.5.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fbde6962867ee75b48b0ee29b2b9372ec5d617799dbaf38e82dc0596f2f7738a", size = 16727283, upload-time = "2026-10-10T20:02:53.186Z" }, + { url = "https://files.pythonhosted.org/packages/4a/7a/e8b58a5289a0d464c52885de47c35a935cdd70c03a4c3ab94a5126416dd0/numpy-2.5.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b89d0aaae2fe498c648f4c4795c084db535af5bd98ef942b2a3681fb74ce8645", size = 18485839, upload-time = "2026-10-10T20:02:59.018Z" }, +] + +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" }, +] + +[[package]] +name = "pydantic" +version = "2.14.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b4/fc/1203d011145c98ddce3cd2f505bb54375ef8d43223053df6bfcf3c746f46/pydantic-2.14.3.tar.gz", hash = "sha256:1054f237f4d4733e5a30e1e2333bd33a2004ab9ab1510bd053a9a31bb48e232d", size = 925636, upload-time = "2026-11-05T09:17:04.686Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/72/b8/b864503789ef5c58597d2a7b4adbee62c26440ab1e682581fc6838df8947/pydantic-2.14.3-py3-none-any.whl", hash = "sha256:3f7b347782ab7e4cf4c798496ae3a82787d9f21ec12676a9c564355eeef8daa8", size = 494071, upload-time = "2026-11-05T09:17:02.426Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.50.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9c/0f/34f9ce4ba701dd0b815033ef94d99b56f66200e578ee6052aa3ac26f064e/pydantic_core-2.50.4.tar.gz", hash = "sha256:aead3b74b68396bf0feab5d57e050b730ded7df55853c1e048a87e00aaf033c6", size = 522249, upload-time = "2026-11-05T09:15:26.774Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/91/23/e0c6e3cd09a0ac809953fea698c816b9f03bf0b35b6820c9553e4f5d85a8/pydantic_core-2.50.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c81d98e27d9d9261909dcccab1ba5d6ea1c98b0bb9470e368604614fd1d36ddd", size = 2261727, upload-time = "2026-11-05T09:12:19.097Z" }, + { url = "https://files.pythonhosted.org/packages/6e/bb/7e44d4ac6e1292f1859384c688713045bdf5448e0635c49c003d2be3bb6c/pydantic_core-2.50.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:219114f8dcdcbe4720d82ef016b1287ce5a0a67d7c69ca61524eb72e82aac344", size = 2498172, upload-time = "2026-11-05T09:12:26.434Z" }, + { url = "https://files.pythonhosted.org/packages/e0/8d/4bfbacaf191f7939893d165e18eb301731fa3366c59a6e57336c4f168fbd/pydantic_core-2.50.4-graalpy312-graalpy250_312_native-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:bee28aab5a580eec673f7b68dfa8dece3dd37bd207ef8d22fafe23a8e9837296", size = 2279952, upload-time = "2026-11-05T09:15:00.907Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8b/9d/b3589d3877982d4f2329302ef98a8026e7f4443c765c46cfecc8858c6b4b/pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc", size = 807870, upload-time = "2025-09-25T21:32:16.431Z" }, + { url = "https://files.pythonhosted.org/packages/be/8e/98435a21d1d4b46590d5459a22d88128103f8da4c2d4cb8f14f2a96504e1/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea", size = 790181, upload-time = "2025-09-25T21:32:18.834Z" }, +] + +[[package]] +name = "regex" +version = "2026.11.15" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cf/e7/67c67920a3b5183388e0853a0a564a4bf60f2dd190a4e7626f5dad2fed62/regex-2026.11.15.tar.gz", hash = "sha256:d6ec7e29e62ebf93ab2a593d1137022b6025497d8610e5cb666d52f9ee5bb0ce", size = 419660, upload-time = "2026-11-15T17:04:15.71Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4c/2c/d2c9f1c64151745d32b2fc389155cbd2af751c5c41ea634658b7fdcc199a/regex-2026.11.15-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f3758c3b1689ab778f3e1ae0f9aa4d22b8e4efc362e2e4cfdbbc5a208fed0bc1", size = 809168, upload-time = "2026-11-15T17:02:06.631Z" }, + { url = "https://files.pythonhosted.org/packages/19/65/596d7ad62189d9113917dfed33e9e78c16dfbf9c7b60988b0654b64d0735/regex-2026.11.15-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9a7d15f046e1ea4be447749462ad588effe5fe4c6e26271649385d89767d6e9b", size = 797025, upload-time = "2026-11-15T17:02:14.938Z" }, +] + +[[package]] +name = "rich" +version = "15.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c0/8f/0722ca900cc807c13a6a0c696dacf35430f72e0ec571c4275d2371fca3e9/rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36", size = 230680, upload-time = "2026-04-12T08:24:00.75Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb", size = 310654, upload-time = "2026-04-12T08:24:02.83Z" }, +] + +[[package]] +name = "safetensors" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/45/06/f955dbbb1859e3bd23c8ac6141af5106e7ad5fedec4a3a6e3d60f94b7001/safetensors-0.8.0.tar.gz", hash = "sha256:fabaf3e0f18a6618d9b36560682562157f77c2b71fcffc7b432be2baed9d753d", size = 325846, upload-time = "2026-06-09T07:52:25.563Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/28/50/f203ff3a3ddfe19308efc83c5a3a29ed02bf786732ec35e68bf9162f3365/safetensors-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fd6f3f93c9a0a7cc2788ee63fb763353d4bd2e89b0751bc78fcf7dda00bea774", size = 516040, upload-time = "2026-06-09T07:52:16.29Z" }, + { url = "https://files.pythonhosted.org/packages/27/43/41c1621732edd934d868a00d1b891584c892a7b62a9aab82ea5a0a5623ee/safetensors-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:8e080062fcde23be189565e1c3305d16751a218ecf9412c8601e64204eb6f846", size = 722361, upload-time = "2026-06-09T07:52:23.924Z" }, +] + +[[package]] +name = "setuptools" +version = "84.2.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/70/b3/c19426f783614d625699a4b247faf628ea9ab1db228674491767b417f9e1/setuptools-84.2.1.tar.gz", hash = "sha256:3ff8b3b5492a0aa66960f4419365a86b84e013070d4313e4d4a6894f5d64d6bc", size = 1230289, upload-time = "2026-10-20T19:01:37.742Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/55/6dc6d6bb953bdfc52519a0059592c52b6e3b8ad51cf8256dffceb55b0610/setuptools-84.2.1-py3-none-any.whl", hash = "sha256:ca140b45d5325a9478f880e351484f62fef15f336462e449ca0c03c873d589c2", size = 876263, upload-time = "2026-10-20T19:01:35.678Z" }, +] + +[[package]] +name = "shellingham" +version = "1.5.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", size = 10310, upload-time = "2023-10-24T04:13:40.426Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" }, +] + +[[package]] +name = "sympy" +version = "1.14.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mpmath" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/83/d3/803453b36afefb7c2bb238361cd4ae6125a569b4db67cd9e79846ba2d68c/sympy-1.14.0.tar.gz", hash = "sha256:d3d3fe8df1e5a0b42f0e7bdf50541697dbe7d23746e894990c030e2b05e72517", size = 7793921, upload-time = "2025-04-27T18:05:01.611Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a2/09/77d55d46fd61b4a135c444fc97158ef34a095e5681d0a6c10b75bf356191/sympy-1.14.0-py3-none-any.whl", hash = "sha256:e091cc3e99d2141a0ba2847328f5479b05d94a6635cb96148ccb3f34671bd8f5", size = 6299353, upload-time = "2025-04-27T18:04:59.103Z" }, +] + +[[package]] +name = "tokenizers" +version = "0.23.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "huggingface-hub" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e0/7c/2cabb2174e772636683008f2c5621949b645da7d303c596589e84516a184/tokenizers-0.23.3.tar.gz", hash = "sha256:cded33237c77caeef62944d32aa9a7ef42bdce2b3497e18d137e072a8c4be438", size = 385286, upload-time = "2026-10-09T10:16:55.759Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/3a/40/6706b82693715581457c6d5423eaa7faae576bb0526c5738a57085eb4449/tokenizers-0.23.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:376851d22bcf9d650a5c3090bb83e6cf9e895fbf0595369fa4cd43c1f69b5f87", size = 3396193, upload-time = "2026-10-09T10:01:05.48Z" }, + { url = "https://files.pythonhosted.org/packages/26/e5/065625317690ea3548d834dad81f48ea1fd32e4964610e658e195d7fe28e/tokenizers-0.23.3-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:e05ab7baf7f47b406a95fea6f3b0a484b2ddcd9e1d14b68844c457eb755085a3", size = 10266026, upload-time = "2026-10-09T10:16:33.054Z" }, +] + +[[package]] +name = "torch" +version = "2.13.0+rocm7.2" +source = { registry = "https://download.pytorch.org/whl/rocm7.2" } +dependencies = [ + { name = "filelock" }, + { name = "fsspec" }, + { name = "jinja2" }, + { name = "networkx" }, + { name = "setuptools" }, + { name = "sympy" }, + { name = "triton-rocm" }, + { name = "typing-extensions" }, +] +wheels = [ + { url = "https://download-r2.pytorch.org/whl/rocm7.2/torch-2.13.0%2Brocm7.2-cp312-cp312-manylinux_2_28_x86_64.whl", upload-time = "2026-07-08T11:26:11Z" }, +] + +[[package]] +name = "tqdm" +version = "4.70.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0d/ea/b2a5bd54b28a324dae8211928b2d730b6547500342c7e6c6dea08bd0a485/tqdm-4.70.1.tar.gz", hash = "sha256:cefd0eca11b2a37a3aee776544d4f4ae913f02688135b5556b8788dfa474afc4", size = 171846, upload-time = "2026-09-11T07:25:16.601Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a7/03/921a3d3c75785aca9ebfbfcabfbc3a1be12e2ab5265deb026d55a5a3f83e/tqdm-4.70.1-py3-none-any.whl", hash = "sha256:c293e525e6fef9c20e8728fd4612df02a0aa31bb5fe91ecd93e123b1b7bffa73", size = 80199, upload-time = "2026-09-11T07:25:14.599Z" }, +] + +[[package]] +name = "transformers" +version = "5.19.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "huggingface-hub" }, + { name = "numpy" }, + { name = "packaging" }, + { name = "pyyaml" }, + { name = "regex" }, + { name = "safetensors" }, + { name = "tokenizers" }, + { name = "tqdm" }, + { name = "typer" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/65/4c/70012ed0795235fb6bd7806fafd4a1842f03e49ebbfa3bb9580e451948ce/transformers-5.19.0.tar.gz", hash = "sha256:87f38dd25e4521151b97e94520ac457f44a0ae8a8358a5b112daff6c64a822d6", size = 10032022, upload-time = "2026-10-06T16:39:00.229Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b9/59/1e7f1212c215c73690ae6cab4678efe1555ff985953e145d88cc212859b0/transformers-5.19.0-py3-none-any.whl", hash = "sha256:afcd2dd5f603ed28c1e1fcb00a338ccbb4ef5f878ed289635df8b58187afb518", size = 12599123, upload-time = "2026-10-06T16:38:56.794Z" }, +] + +[[package]] +name = "triton-rocm" +version = "3.7.1" +source = { registry = "https://download.pytorch.org/whl/rocm7.2" } +wheels = [ + { url = "https://download-r2.pytorch.org/whl/triton_rocm-3.7.1-cp312-cp312-linux_x86_64.whl", hash = "sha256:b200ade2418b8450e4e3e69c33c804e2cc07d1e36dc9678ac8ac1dd65f9e10e1", upload-time = "2026-06-17T17:05:14Z" }, +] + +[[package]] +name = "truststore" +version = "0.10.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ee/9f/c5201d42a484c061e528825fc8e2d565f5abd50a4ced6fb7d29c4ec99b2b/truststore-0.10.5.tar.gz", hash = "sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd", size = 28091, upload-time = "2026-10-12T22:27:31.808Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/e9/3a7820be2bb0fe53b6bc9c3be26d3d1158004e4c3ab953aa6840b955b1e9/truststore-0.10.5-py3-none-any.whl", hash = "sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c", size = 19017, upload-time = "2026-10-12T22:27:30.377Z" }, +] + +[[package]] +name = "typer" +version = "0.29.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-doc" }, + { name = "pydantic" }, + { name = "rich" }, + { name = "shellingham" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/6c/aa/0de7986aa1fa856adb961c67345189b97d13f6e250b34ba68884df865f07/typer-0.29.1.tar.gz", hash = "sha256:ab6eb3880bf67ce96147734717f9ec333c06f66e361f3ea947d0be43da39f242", size = 205843, upload-time = "2026-11-11T09:18:39.782Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/05/ff/51969745f31cea6bcd12151e668febcf979656316e67a7755942267c1273/typer-0.29.1-py3-none-any.whl", hash = "sha256:00dbc549c13428bec1be55fe1f4d0fb8c6637a310e4f178ef14abe9534ee7b58", size = 121064, upload-time = "2026-11-11T09:18:38.671Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, +] + +[[package]] +name = "typing-inspection" +version = "0.4.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ff/50/0195198eb1d75bab716bb0a813abea4cc394bfa17a92a189f021a34859af/typing_inspection-0.4.5.tar.gz", hash = "sha256:7f16c411e7930dc79596d42ab44672a3fe5f60eb34b781a1647e7872363120c7", size = 81194, upload-time = "2026-11-04T14:13:23.774Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/de/0c/ea2544850a7c135e15033a5c7a8e7211136184b7ae63e2239d557c2b3019/typing_inspection-0.4.5-py3-none-any.whl", hash = "sha256:bc210535442b39e1bf2805e0c7a17dfd6a4ace760c84c7f7d16245d23a6b1c39", size = 14874, upload-time = "2026-11-04T14:13:22.616Z" }, +] From 330a9f9efac16d713df43c67f4d879d0b3510489 Mon Sep 17 00:00:00 2001 From: smfworks Date: Sun, 15 Nov 2026 20:58:55 -0500 Subject: [PATCH 06/13] tools/gufo: run a Gufo server in rootless Podman under a worker serve.sh NAME PORT [podman opts] -- gufo serve ...: foreground, loopback-only, stops the container on SIGTERM and waits so GPU memory is free; --replace clears leftovers; video/render groups by name (keep-groups needs crun). --- tools/gufo/README.md | 20 ++++++++++++++++++++ tools/gufo/serve.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/gufo/README.md create mode 100755 tools/gufo/serve.sh diff --git a/tools/gufo/README.md b/tools/gufo/README.md new file mode 100644 index 00000000..883864e8 --- /dev/null +++ b/tools/gufo/README.md @@ -0,0 +1,20 @@ +# Gufo in rootless Podman + +[Gufo](https://github.com/gufo-org/gufo) (MIT) is an inference engine for AMD Strix Halo (gfx1151): Qwen3.8 Flash-Next +and 27B, Qwen3-TTS, Qwen3-ASR, Qwen-Image, MiniMax H3 and more behind OpenAI-compatible servers. +`serve.sh NAME PORT [podman options] -- gufo serve ...` runs one of them in the foreground so a LocalRouter worker can +supervise it: the `openai_server` engine for chat, `tools/speech/openai_audio` for speech and transcription. + +- The container is `lr-gufo-NAME`, published on `127.0.0.1:PORT` only; `--host 0.0.0.0 --port 8080` are added after + `serve` inside the container. +- SIGTERM or SIGINT (the worker unloading) runs `podman stop` and waits, so the GPU memory is free when the script exits. + `--replace` removes a container left by a worker that was killed outright; `deploy/strix-halo/stop.sh` also stops any + `lr-gufo-*` left over. +- `/dev/kfd` and `/dev/dri` are passed with the `video` and `render` groups by name: Gufo's docs use + `--group-add keep-groups`, which needs the crun runtime, and many hosts run runc. +- `GUFO_IMAGE` picks the image (default `ghcr.io/gufo-org/toolboxes/gufo-runtime:latest`; pin a version for + reproducible installs). + +Measured on a Radeon 8060S with 96 GiB GTT (2026-11-15): Flash-Next UD-Q4_K_XL with the MTP head peaks at 88 GiB GTT +serving 32k context with 2 sessions (pp512 1196 tok/s, decode 60-78 tok/s with MTP); Qwen3-TTS CustomVoice 6.5 GiB, about +220 ms to first audio, 2.3x real time; Qwen3-ASR 5.5 GiB, 14x real time. diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh new file mode 100755 index 00000000..200b9f1d --- /dev/null +++ b/tools/gufo/serve.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Runs one Gufo server (https://github.com/gufo-org/gufo, the AMD Strix Halo engine) in rootless Podman, in the +# foreground, for LocalRouter's `openai_server` engine and the openai_audio `cmd` worker: +# tools/gufo/serve.sh NAME PORT [podman options...] -- gufo serve ... [--port 8080 is added] +# The container listens on 127.0.0.1:PORT only. SIGTERM/SIGINT (the daemon unloading the tool) stops the container and +# waits until it is gone, so its GPU memory is free before this script exits. `--replace` clears a container left over +# from a worker that was killed outright. +# Environment: GUFO_IMAGE (default ghcr.io/gufo-org/toolboxes/gufo-runtime:latest), GUFO_STOP_TIMEOUT (default 10 s). +# Devices: /dev/kfd and /dev/dri; the video and render groups are passed by name, since keep-groups needs crun and +# many hosts run runc. +set -euo pipefail +name=${1:?usage: serve.sh NAME PORT [podman options...] -- gufo serve ...}; port=${2:?port}; shift 2 +popts=() +while [ $# -gt 0 ] && [ "$1" != -- ]; do popts+=("$1"); shift; done +[ "${1:-}" = -- ] || { echo "serve.sh: missing -- before the gufo command" >&2; exit 2; } +shift +image=${GUFO_IMAGE:-ghcr.io/gufo-org/toolboxes/gufo-runtime:latest} +cname="lr-gufo-$name" +stop() { podman stop -t "${GUFO_STOP_TIMEOUT:-10}" "$cname" > /dev/null 2>&1 || true; wait "$pid" 2> /dev/null || true; exit 0; } +trap stop TERM INT +# "gufo serve [global opts] KIND ...": insert host/port right after "serve" +args=(); placed=0 +for a in "$@"; do args+=("$a"); if [ $placed = 0 ] && [ "$a" = serve ]; then args+=(--host 0.0.0.0 --port 8080); placed=1; fi; done +podman run --rm --replace --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ + --device /dev/kfd --device /dev/dri --group-add video --group-add render --ulimit memlock=-1 \ + -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & +pid=$! +wait "$pid" From 754c97975a1c8cf2407bfbe96221144dabef7bf2 Mon Sep 17 00:00:00 2001 From: smfworks Date: Sun, 15 Nov 2026 20:58:55 -0500 Subject: [PATCH 07/13] deploy: strix-halo-gfx1151 profile and deploy kit (preview) AMD Strix Halo (Radeon 8060S, gfx1151, 96 GiB GTT): Qwen3.8 Flash-Next chat via Gufo (Q4 + MTP) and llama.cpp (Q3 + MTP) as openai_server tools, Qwen3-TTS and Qwen3-ASR via Gufo behind openai_audio, Whisper on ROCm. budget_bytes = GTT less 2 GiB. The daemon runs as a transient systemd user unit (render/start/stop/status.sh); site files override env.sh. Tested end to end: /v1 chat, /v1/audio, and the voice loop (voice_e2e.py --smoke) passing with 1.2-1.4 s first audio on warm turns. --- deploy/profiles/strix-halo-gfx1151.json | 292 ++++++++++++++++++++++++ deploy/strix-halo/README.md | 42 ++++ deploy/strix-halo/config.json.in | 69 ++++++ deploy/strix-halo/env.sh | 32 +++ deploy/strix-halo/render.sh | 21 ++ deploy/strix-halo/start.sh | 15 ++ deploy/strix-halo/status.sh | 11 + deploy/strix-halo/stop.sh | 11 + 8 files changed, 493 insertions(+) create mode 100644 deploy/profiles/strix-halo-gfx1151.json create mode 100644 deploy/strix-halo/README.md create mode 100644 deploy/strix-halo/config.json.in create mode 100644 deploy/strix-halo/env.sh create mode 100755 deploy/strix-halo/render.sh create mode 100755 deploy/strix-halo/start.sh create mode 100755 deploy/strix-halo/status.sh create mode 100755 deploy/strix-halo/stop.sh diff --git a/deploy/profiles/strix-halo-gfx1151.json b/deploy/profiles/strix-halo-gfx1151.json new file mode 100644 index 00000000..8ffb05d1 --- /dev/null +++ b/deploy/profiles/strix-halo-gfx1151.json @@ -0,0 +1,292 @@ +{ + "profile": "strix-halo-gfx1151", + "status": "preview", + "description": "LocalRouter on one AMD Strix Halo box (Ryzen AI Max+ 395, Radeon 8060S gfx1151, unified memory with a 96 GiB GTT pool): Qwen3.8 Flash-Next chat through Gufo (ROCm, Q4 + MTP) or llama.cpp (Vulkan, Q3 + MTP) as openai_server tools, Qwen3-TTS and Qwen3-ASR through Gufo behind the generic openai_audio cmd worker, and Whisper large-v3-turbo on PyTorch ROCm. Model servers run in rootless Podman (tools/gufo/serve.sh); the daemon runs as a transient systemd user unit (deploy/strix-halo). The compiled-in CUDA engines (Qwen-Image, MiniMax H3, Kandinsky-6) and Drama 3 have no AMD build and are not part of this profile.", + "tested_on": "Ryzen AI Max+ 395 / Radeon 8060S (gfx1151), 128 GB LPDDR5X with amdgpu.gttsize=98304 (96 GiB GTT), kernel 7.2, ROCm 7.2.4, Podman 6.1 (runc), 2026-11-15: chat over /v1 on both chat tools, speech and transcription over /v1/audio, the voice loop over /v1/realtime (tools/spark/jarvis/voice_e2e.py --smoke)", + "hardware": { + "arch": "x86_64", + "gpu": "gfx1151", + "gfx": "gfx1151", + "unified_memory": true, + "min_memory_gib": 96, + "min_gtt_gib": 90, + "min_rocm": "7.2", + "min_free_gib": 96, + "os": "omarchy 4.5.0" + }, + "disk_margin_gib": 30, + "env": { + "LR_BIN": "$REPO/zig-out/bin/localrouter", + "STEPS": "bash $REPO/tools/install/steps.sh", + "UV_CACHE_DIR": "$J/uv-cache", + "FLASHNEXT_DIR": "${FLASHNEXT_DIR:-$J/models/Qwen3.8-Flash-Next-GGUF}", + "TTS_DIR": "${TTS_DIR:-$J/models/Qwen3-TTS-12Hz-1.7B-CustomVoice}", + "ASR_DIR": "${ASR_DIR:-$J/models/Qwen3-ASR-1.7B}", + "LLAMA_BIN": "${LLAMA_BIN:-$J/llama.cpp/bin}", + "GUFO_IMAGE": "${GUFO_IMAGE:-ghcr.io/gufo-org/toolboxes/gufo-runtime:latest}" + }, + "prereqs": [ + { + "id": "commands", + "title": "jq, curl, git, tar, xz, sha256sum, python3, podman, systemd-run", + "test": "for t in jq curl git tar xz sha256sum python3 podman systemctl systemd-run; do command -v $t > /dev/null || exit 1; done", + "fix": "install them with the distribution's package manager (Arch/Omarchy: sudo pacman -S jq curl git tar xz python podman)" + }, + { + "id": "python", + "title": "/usr/bin/python3 3.11 or newer (the openai_audio worker and the scripts)", + "test": "/usr/bin/python3 -I -c 'import sys; sys.exit(sys.version_info < (3, 11))'", + "fix": "install python 3.11 or newer" + }, + { + "id": "amdgpu", + "title": "an AMD GPU on amdgpu with ROCm (rocminfo lists a gfx1151 agent)", + "test": "rocminfo 2> /dev/null | grep -q gfx1151", + "fix": "install ROCm 7.2 or newer (rocminfo, the HIP runtime); add yourself to the video and render groups and log in again" + }, + { + "id": "gpu-devices", + "title": "/dev/kfd and /dev/dri/renderD* usable by this user", + "test": "[ -r /dev/kfd ] && [ -w /dev/kfd ] && ls /dev/dri/renderD* > /dev/null 2>&1", + "fix": "sudo usermod -aG video,render $(id -un), then log in again" + }, + { + "id": "gtt", + "title": "a GTT pool of 90 GiB or more (amdgpu.gttsize / ttm.pages_limit on the kernel command line)", + "test": "source $REPO/tools/install/lib.sh && [ $(hw_gtt) -ge $((90 * 1073741824)) ]", + "fix": "a host setting this installer never changes: see the Gufo host configuration guide (amdgpu.gttsize=98304 ttm.pages_limit=25165824) and reboot" + }, + { + "id": "podman-rootless", + "title": "rootless Podman that can run a container", + "test": "podman info --format '{{.Host.Security.Rootless}}' 2> /dev/null | grep -qx true", + "fix": "install podman (and crun or runc); check: podman run --rm docker.io/library/alpine true" + }, + { + "id": "systemd-user", + "title": "a systemd user session (the daemon runs as a transient user unit)", + "test": "systemctl --user show-environment > /dev/null", + "fix": "log in through ssh or a desktop session (not su)" + }, + { + "id": "network", + "title": "HTTPS to huggingface.co, github.com, ghcr.io and ziglang.org", + "test": "for u in https://huggingface.co https://github.com https://ziglang.org; do curl -fsS -m 15 -o /dev/null -I $u || exit 1; done; curl -sS -m 15 -o /dev/null https://ghcr.io/v2/", + "fix": "open outbound HTTPS to those hosts (and download.pytorch.org, pypi.org)" + } + ], + "host": { + "download_bytes": 73986483, + "disk_bytes": 450000000, + "tools": { + "zig": { + "url": "https://ziglang.org/download/0.17.0/zig-x86_64-linux-0.17.0.tar.xz", + "sha256": "1cbe9df9f27e6b78d14ccbca43b6703a404ef79ef1c463de901d7f088d4e2026", + "bytes": 57332648, + "bin": [ + "zig" + ], + "version": "0.17.0", + "version_cmd": "$J/bin/zig version" + }, + "uv": { + "url": "https://github.com/astral-sh/uv/releases/download/0.13.4/uv-x86_64-unknown-linux-gnu.tar.gz", + "sha256": "2b428396f12572d4429cf210ca234dd599a33b3af0958a4d5ed569d63e3f344f", + "bytes": 16653835, + "bin": [ + "uv-x86_64-unknown-linux-gnu/uv", + "uv-x86_64-unknown-linux-gnu/uvx" + ], + "version": "uv 0.13.4", + "version_cmd": "$J/bin/uv --version" + } + }, + "steps": [ + { + "id": "zig", + "download_bytes": 57332648, + "disk_bytes": 330000000, + "title": "Zig 0.17.0 (x86_64 Linux, builds LocalRouter)", + "run": "$STEPS tool zig", + "done": "$STEPS tool-ok zig", + "fix": "a failed download or checksum: run again (it resumes)" + }, + { + "id": "uv", + "download_bytes": 16653835, + "disk_bytes": 50000000, + "title": "uv 0.13.4 (the Whisper ROCm venv, hf downloads)", + "run": "$STEPS tool uv", + "done": "$STEPS tool-ok uv", + "fix": "a failed download or checksum: run again (it resumes)" + }, + { + "id": "build", + "download_bytes": 0, + "disk_bytes": 300000000, + "title": "LocalRouter itself, from this checkout (zig build without -Dnvcc: the CUDA engines are compiled with empty kernel images and are not configured)", + "run": "cd $REPO && $J/bin/zig build -Doptimize=ReleaseSafe", + "done": "[ -x \"$LR_BIN\" ]", + "fix": "the build output says why; check zig version (0.17.0)" + }, + { + "id": "gufo-image", + "download_bytes": 3490000000, + "disk_bytes": 3490000000, + "title": "the Gufo runtime image (ghcr.io/gufo-org/toolboxes/gufo-runtime, MIT; ROCm 10.1 inside)", + "run": "podman pull $GUFO_IMAGE && podman run --rm --device /dev/kfd --device /dev/dri --group-add video --group-add render $GUFO_IMAGE gufo diagnose", + "done": "podman image exists $GUFO_IMAGE", + "fix": "network to ghcr.io: run again; gufo diagnose says what the host lacks" + } + ] + }, + "models": [ + { + "key": "chat", + "id": "qwen3.8-flash-next", + "warm": false, + "title": "Qwen3.8 Flash-Next, Gufo (ROCm) UD-Q4_K_XL with the shared MTP head; 88 GiB GTT at 32k context", + "licence": { + "name": "Apache-2.0", + "url": "https://huggingface.co/Qwen/Qwen3.8-Flash-Next" + }, + "download_bytes": 115028765978, + "disk_bytes": 115100000000, + "memory_bytes": 94489280512, + "steps": [ + { + "id": "weights", + "download_bytes": 115028765978, + "disk_bytes": 115100000000, + "title": "unsloth/Qwen3.8-Flash-Next-GGUF: UD-Q4_K_XL (4 shards), MTP/mtp-...-shared-Q8_0.gguf, mmproj-BF16.gguf", + "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download unsloth/Qwen3.8-Flash-Next-GGUF --local-dir $FLASHNEXT_DIR --include 'UD-Q4_K_XL/*' --include 'MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf' --include 'mmproj-BF16.gguf'", + "done": "[ -s $FLASHNEXT_DIR/UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00004-of-00004.gguf ] && [ -s $FLASHNEXT_DIR/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf ] && [ -s $FLASHNEXT_DIR/mmproj-BF16.gguf ]", + "fix": "network to huggingface.co: run again (hf resumes)" + } + ] + }, + { + "key": "chat-q3", + "id": "qwen3.8-flash-next-q3", + "warm": false, + "title": "Qwen3.8 Flash-Next, llama.cpp (Vulkan, Unsloth fork b12347) UD-Q3_K_XL with the shared MTP head; 62 GiB GTT, the voice loop's chat model", + "licence": { + "name": "Apache-2.0", + "url": "https://huggingface.co/Qwen/Qwen3.8-Flash-Next" + }, + "download_bytes": 89497018544, + "disk_bytes": 89600000000, + "memory_bytes": 66571993088, + "steps": [ + { + "id": "llama-cpp", + "download_bytes": 32070038, + "disk_bytes": 120000000, + "title": "llama.cpp b12347-mix-241a0f3 (unslothai fork, Vulkan x64: loads the qwen4exp architecture and the shared MTP head)", + "run": "$STEPS file https://github.com/unslothai/llama.cpp/releases/download/b12347-mix-241a0f3/app-b12347-mix-241a0f3-linux-x64-vulkan.tar.gz 3eb345b7abd8cab58e6915543e5cb30686c0726c3f082f2787ec19b1a1592615 $J/dl/llama-us-vk.tgz && mkdir -p $LLAMA_BIN && tar -xzf $J/dl/llama-us-vk.tgz -C $LLAMA_BIN", + "done": "[ -x $LLAMA_BIN/llama-server ]", + "fix": "network to github.com: run again" + }, + { + "id": "weights", + "download_bytes": 89464948506, + "disk_bytes": 89500000000, + "title": "unsloth/Qwen3.8-Flash-Next-GGUF: UD-Q3_K_XL (4 shards) and the shared MTP head", + "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download unsloth/Qwen3.8-Flash-Next-GGUF --local-dir $FLASHNEXT_DIR --include 'UD-Q3_K_XL/*' --include 'MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf'", + "done": "[ -s $FLASHNEXT_DIR/UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00004-of-00004.gguf ] && [ -s $FLASHNEXT_DIR/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf ]", + "fix": "network to huggingface.co: run again (hf resumes)" + } + ] + }, + { + "key": "tts", + "id": "qwen3-tts-customvoice", + "warm": true, + "title": "Qwen3-TTS 12Hz 1.7B CustomVoice through Gufo and tools/speech/openai_audio (9 voices, 24 kHz, streamed; 6.5 GiB)", + "licence": { + "name": "Apache-2.0", + "url": "https://huggingface.co/Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice" + }, + "download_bytes": 4544233100, + "disk_bytes": 4600000000, + "memory_bytes": 6979321856, + "steps": [ + { + "id": "weights", + "download_bytes": 4544233100, + "disk_bytes": 4600000000, + "title": "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice", + "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice --local-dir $TTS_DIR", + "done": "[ -s $TTS_DIR/config.json ] && ls $TTS_DIR/*.safetensors > /dev/null 2>&1", + "fix": "network to huggingface.co: run again" + } + ] + }, + { + "key": "stt", + "id": "qwen3-asr", + "warm": true, + "title": "Qwen3-ASR 1.7B through Gufo and tools/speech/openai_audio (5.5 GiB)", + "licence": { + "name": "Apache-2.0", + "url": "https://huggingface.co/Qwen/Qwen3-ASR-1.7B" + }, + "download_bytes": 4703117477, + "disk_bytes": 4750000000, + "memory_bytes": 5905580032, + "steps": [ + { + "id": "weights", + "download_bytes": 4703117477, + "disk_bytes": 4750000000, + "title": "Qwen/Qwen3-ASR-1.7B", + "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download Qwen/Qwen3-ASR-1.7B --local-dir $ASR_DIR", + "done": "[ -s $ASR_DIR/config.json ] && ls $ASR_DIR/*.safetensors > /dev/null 2>&1", + "fix": "network to huggingface.co: run again" + } + ] + }, + { + "key": "whisper", + "id": "whisper-large-v3-turbo", + "warm": false, + "title": "Whisper large-v3-turbo on PyTorch ROCm 7.2 (tools/speech/whisper/rocm/uv.lock; FP16; 2.5 GiB)", + "licence": { + "name": "MIT", + "url": "https://huggingface.co/openai/whisper-large-v3-turbo" + }, + "pins": "tools/speech/whisper/rocm/uv.lock", + "download_bytes": 6120000000, + "disk_bytes": 12000000000, + "memory_bytes": 3221225472, + "steps": [ + { + "id": "venv", + "download_bytes": 4500000000, + "disk_bytes": 10000000000, + "title": "the Whisper venv from tools/speech/whisper/rocm/uv.lock (Python 3.12, torch 2.13.0+rocm7.2, transformers 5.19.0; every wheel by its locked hash)", + "run": "UV_PROJECT_ENVIRONMENT=$J/venvs/whisper-rocm $J/bin/uv sync --locked --python 3.12 --project $REPO/tools/speech/whisper/rocm && $STEPS stamp whisper-rocm-venv $REPO/tools/speech/whisper/rocm/uv.lock", + "done": "[ -x $J/venvs/whisper-rocm/bin/python ] && $STEPS stamped whisper-rocm-venv $REPO/tools/speech/whisper/rocm/uv.lock", + "fix": "network (download.pytorch.org, pypi.org): run again" + }, + { + "id": "model", + "download_bytes": 1620000000, + "disk_bytes": 1620000000, + "title": "openai/whisper-large-v3-turbo at its pinned revision, every file by sha256", + "run": "python3 -I $REPO/tools/speech/whisper/fetch_model.py --root $J/models/whisper", + "done": "python3 -I $REPO/tools/speech/whisper/fetch_model.py --verify $J/models/whisper/whisper-large-v3-turbo/41f01f3fe87f28c78e2fbf8b568835947dd65ed9 > /dev/null", + "fix": "network: run again" + } + ] + } + ], + "deploy": { + "service": "systemd-transient", + "install": "deploy/strix-halo/render.sh", + "start": "deploy/strix-halo/start.sh", + "stop": "deploy/strix-halo/stop.sh", + "status": "deploy/strix-halo/status.sh", + "smoke": "python3 -I tools/spark/jarvis/voice_e2e.py --smoke --skip-barge --leak-probe 0 --url http://127.0.0.1:$PORT --out $J/smoke --tts qwen3-tts-customvoice --stt qwen3-asr --chat qwen3.8-flash-next-q3" + } +} diff --git a/deploy/strix-halo/README.md b/deploy/strix-halo/README.md new file mode 100644 index 00000000..4ffd29d2 --- /dev/null +++ b/deploy/strix-halo/README.md @@ -0,0 +1,42 @@ +# deploy/strix-halo: LocalRouter on an AMD Strix Halo box + +Profile: `deploy/profiles/strix-halo-gfx1151.json` (status: preview). One box with a Ryzen AI Max+ 395 / Radeon 8060S +(gfx1151): unified LPDDR5X memory of which the GPU may map the GTT pool (96 GiB with `amdgpu.gttsize=98304`). The +installer never changes kernel parameters, firmware or the bootloader; the GTT size is a prerequisite it only checks. + +| Tool | Kind | Runs as | GTT | +| --- | --- | --- | --- | +| `qwen3.8-flash-next` | chat (default) | `openai_server` → `tools/gufo/serve.sh` → Gufo `serve llm` (UD-Q4_K_XL + MTP) on :8081 | 88 GiB | +| `qwen3.8-flash-next-q3` | chat (the voice loop's) | `openai_server` → llama.cpp `llama-server` (Vulkan, UD-Q3_K_XL + MTP) on :8080 | 62 GiB | +| `qwen3-tts-customvoice` | speech | `tools/speech/openai_audio` → Gufo `serve tts` on :8091 | 6.5 GiB | +| `qwen3-asr` | transcription (default) | `tools/speech/openai_audio` → Gufo `serve asr` on :8092 | 5.5 GiB | +| `whisper-large-v3-turbo` | transcription | `tools/speech/whisper/worker.py` in the ROCm venv | 2.5 GiB | + +`budget_bytes` is the GTT pool less 2 GiB (`render.sh`, from `tools/install/lib.sh hw_gtt`): a GPU allocation past GTT +fails even when MemAvailable has room, so the scheduler must plan against GTT. Q3 + TTS + ASR fit together (the voice +loop); Q4 + TTS + ASR do not, so a `/v1` chat on the Q4 model unloads the speech models and the voice loop swaps back. + +```sh +zig build -Doptimize=ReleaseSafe # no -Dnvcc: the CUDA engines build with empty kernel images +deploy/strix-halo/start.sh # render config.json, start the transient user unit, wait for /health +deploy/strix-halo/status.sh # unit, health, each tool's state, containers, GTT +deploy/strix-halo/stop.sh # stop the daemon (its workers stop their servers), then leftovers +SITE=path/to/site.env deploy/strix-halo/start.sh # with a site file (paths, voice, which model does what) +``` + +`env.sh` holds every default (prefix `$J`, ports, model directories, measured memory); a site file sourced after it +overrides any of them. `tools/install/doctor.sh --profile strix-halo-gfx1151 --unit localrouter-amd` checks the box +(GPU, ROCm, GTT, Podman, the steps, the service); export the site file's variables first when it moves model paths. + +## Measured (2026-11-15, Radeon 8060S, ROCm 7.2.4, kernel 7.2, Podman 6.1 with runc) + +- `/v1/chat/completions` on `qwen3.8-flash-next` (cold load 17.5 s): 56 tokens in 1.69 s; streamed answers. +- `/v1/audio/speech` (`stream`: pcm, chunked): first audio 226 ms, about 2.4x real time; `wav` 4.75 s cold. +- `/v1/audio/transcriptions`: Qwen3-ASR 2.4 s cold, 0.58 s warm for a 5.9 s clip; Whisper ROCm 9.8 s cold, 0.52 s warm. +- Voice loop over `/v1/realtime` (`tools/spark/jarvis/voice_e2e.py --smoke --skip-barge`, chat on the Q3 tool): + PASSED; first audio after the end of speech 1217 ms and 1376 ms on warm turns (25 s on the first, a cold chat load), + a 42.6 s spoken reply with no underrun. + +Not here: the compiled-in engines (Qwen-Image, MiniMax H3, Kandinsky-6) are CUDA kernels, and Drama 3 has GB10 and Metal +builds only. Gufo serves Qwen-Image 2.1 and MiniMax H3 on gfx1151; wrapping them is the next step (a `cmd` image/video +worker, or ComfyUI behind one). diff --git a/deploy/strix-halo/config.json.in b/deploy/strix-halo/config.json.in new file mode 100644 index 00000000..4b4ea4af --- /dev/null +++ b/deploy/strix-halo/config.json.in @@ -0,0 +1,69 @@ +{ + "machine": "@MACHINE@", + "reserve_bytes": @RESERVE_BYTES@, + "budget_bytes": @BUDGET_BYTES@, + "local_files": ["@DEPLOY@/inbox"], + "defaults": {"chat_completion": "@CHAT_DEFAULT@", "text_to_speech": "qwen3-tts-customvoice", + "speech_to_text": "@STT_DEFAULT@"}, + "stt": {"language": "en"}, + "voice": { + "chat_model": "@VOICE_CHAT@", + "chat_extra": {"chat_template_kwargs": {"enable_thinking": false}, "top_p": 0.8}, + "temperature": 0.7, + "speech_models": ["qwen3-tts-customvoice"], + "voice": "@VOICE@", + "prime_chat": true, "greedy_transcripts": true, "partial_interval_ms": 0, "manage_models": true + }, + "tools": [ + {"id": "qwen3.8-flash-next", "kind": "chat", + "name": "Qwen3.8 Flash-Next (Gufo on ROCm, UD-Q4_K_XL + MTP head, rootless Podman)", + "engine": "openai_server", "weights": "@FLASHNEXT_DIR@", "resident_bytes": @FLASHNEXT_RESIDENT@, "working_bytes": 0, "keep_loaded": false, + "priority": 100, "idle_ttl_s": 900, "load_timeout_s": 600, "generate_timeout_s": 600, + "license": {"name": "Apache-2.0 (model); MIT (Gufo)", "url": "https://github.com/gufo-org/gufo", "commercial": true}, + "options": {"server": ["@SRC@/tools/gufo/serve.sh", "llm", "{port}", "-v", "{weights}:/m:ro", "--", + "gufo", "serve", "llm", "--model", "/m/UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf", + "--mmproj", "/m/mmproj-BF16.gguf", "--speculative", "mtp", + "--mtp-model", "/m/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf", + "--served-model-name", "{id}", "--context", "32768", "--sessions", "2", + "--cache-ram-bytes", "4294967296"], + "port": @GUFO_LLM_PORT@, "health": "/v1/models", "stop_timeout_s": 30, + "memory": "Strix Halo (Radeon 8060S, 96 GiB GTT): GTT peak 88.0 GiB serving at 32k context, 2 sessions, MTP"}}, + {"id": "qwen3.8-flash-next-q3", "kind": "chat", + "name": "Qwen3.8 Flash-Next (llama.cpp llama-server, Vulkan, UD-Q3_K_XL + MTP head)", + "engine": "openai_server", "weights": "@Q3_DIR@", "resident_bytes": @Q3_RESIDENT@, "working_bytes": 0, "keep_loaded": false, + "priority": 90, "idle_ttl_s": 900, "load_timeout_s": 600, "generate_timeout_s": 600, + "license": {"name": "Apache-2.0 (model); MIT (llama.cpp)", "url": "https://github.com/ggml-org/llama.cpp", "commercial": true}, + "options": {"server": ["@LLAMA_BIN@/llama-server", "-m", "{weights}/UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00001-of-00004.gguf", + "-ngl", "999", "-fa", "on", "-c", "32768", "--jinja", "--host", "127.0.0.1", "--port", "{port}", + "--alias", "{id}", "--temp", "1.0", "--top-p", "0.95", "--top-k", "20", "--min-p", "0", + "-md", "{weights}/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf", "-ngld", "999", + "--spec-type", "draft-mtp", "--spec-draft-n-max", "2"], + "env": {"LD_LIBRARY_PATH": "@LLAMA_BIN@"}, "port": @LLAMA_PORT@, "health": "/health", + "memory": "Strix Halo: GTT 61.4 GiB serving at 32k context with the MTP head"}}, + {"id": "qwen3-tts-customvoice", "kind": "speech", "capabilities": ["text_to_speech"], + "name": "Qwen3-TTS 12Hz 1.7B CustomVoice (Gufo on ROCm, 24 kHz, streamed)", + "cmd": ["@PYTHON@", "-I", "@SRC@/tools/speech/openai_audio/worker.py"], "weights": "@TTS_DIR@", + "resident_bytes": @TTS_RESIDENT@, "working_bytes": 0, "keep_loaded": true, "priority": 95, "lane": "realtime", + "idle_ttl_s": 3600, "load_timeout_s": 300, "generate_timeout_s": 600, + "license": {"name": "Apache-2.0", "url": "https://huggingface.co/Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice", "commercial": true}, + "options": {"server": ["@SRC@/tools/gufo/serve.sh", "tts", "{port}", "-v", "{weights}:/m:ro", "--", + "gufo", "serve", "tts", "--model", "/m", "--served-model-name", "{id}"], + "port": @GUFO_TTS_PORT@, "health": "/v1/audio/voices", "sample_rate": 24000, "stream": true, + "voices": ["aiden", "dylan", "eric", "ono_anna", "ryan", "serena", "sohee", "uncle_fu", "vivian"], + "default_voice": "@VOICE@", "min_speed": 1, "max_speed": 1, "max_input_chars": 4096}}, + {"id": "qwen3-asr", "kind": "transcription", + "name": "Qwen3-ASR 1.7B (Gufo on ROCm)", + "cmd": ["@PYTHON@", "-I", "@SRC@/tools/speech/openai_audio/worker.py"], "weights": "@ASR_DIR@", + "resident_bytes": @ASR_RESIDENT@, "working_bytes": 0, "keep_loaded": true, "priority": 92, "lane": "realtime", + "idle_ttl_s": 3600, "load_timeout_s": 300, "generate_timeout_s": 600, + "license": {"name": "Apache-2.0", "url": "https://huggingface.co/Qwen/Qwen3-ASR-1.7B", "commercial": true}, + "options": {"server": ["@SRC@/tools/gufo/serve.sh", "asr", "{port}", "-v", "{weights}:/m:ro", "--", + "gufo", "serve", "asr", "--model", "/m", "--served-model-name", "{id}"], + "port": @GUFO_ASR_PORT@, "health": "/v1/models", "max_audio_s": 1800}}, + {"id": "whisper-large-v3-turbo", "kind": "transcription", "name": "Whisper large-v3-turbo (PyTorch ROCm, FP16)", + "cmd": ["@J@/venvs/whisper-rocm/bin/python", "@SRC@/tools/speech/whisper/worker.py"], "weights": "@WHISPER_DIR@", + "resident_bytes": 2684354560, "working_bytes": 536870912, "priority": 85, "idle_ttl_s": 600, + "license": {"name": "MIT", "url": "https://huggingface.co/openai/whisper-large-v3-turbo", "commercial": true}, + "options": {"device": "cuda", "dtype": "float16", "attn": "sdpa", "threads": 4, "vad": "off"}} + ] +} diff --git a/deploy/strix-halo/env.sh b/deploy/strix-halo/env.sh new file mode 100644 index 00000000..66bdeccb --- /dev/null +++ b/deploy/strix-halo/env.sh @@ -0,0 +1,32 @@ +# Defaults for deploy/strix-halo (sourced by render.sh, start.sh, stop.sh, status.sh). Override any of them in a site +# file passed as SITE=path/to/site.env; a site file is sourced after this one. +J=${J:-$HOME/localrouter-amd} # the deployment prefix: venvs, models, deploy/{config.json,data,logs} +DEPLOY=${DEPLOY:-$J/deploy} +PORT=${PORT:-8190} # the daemon, on loopback +UNIT=${UNIT:-localrouter-amd} # the transient systemd user unit start.sh runs the daemon in +MACHINE=${MACHINE:-strix-halo} +LR_BIN=${LR_BIN:-$REPO/zig-out/bin/localrouter} +PYTHON=${PYTHON:-/usr/bin/python3} +# models (Hugging Face snapshots / GGUF directories) +FLASHNEXT_DIR=${FLASHNEXT_DIR:-$J/models/Qwen3.8-Flash-Next-GGUF} # UD-Q4_K_XL/, MTP/, mmproj-BF16.gguf (Gufo) +Q3_DIR=${Q3_DIR:-$FLASHNEXT_DIR} # UD-Q3_K_XL/, MTP/ (llama.cpp) +TTS_DIR=${TTS_DIR:-$J/models/Qwen3-TTS-12Hz-1.7B-CustomVoice} +ASR_DIR=${ASR_DIR:-$J/models/Qwen3-ASR-1.7B} +WHISPER_DIR=${WHISPER_DIR:-$J/models/whisper/whisper-large-v3-turbo/41f01f3fe87f28c78e2fbf8b568835947dd65ed9} +LLAMA_BIN=${LLAMA_BIN:-$J/llama.cpp/bin} # a llama.cpp build with llama-server +# which model serves what +CHAT_DEFAULT=${CHAT_DEFAULT:-qwen3.8-flash-next} +VOICE_CHAT=${VOICE_CHAT:-qwen3.8-flash-next-q3} # Q3 + TTS + ASR fit the 96 GiB GTT together; Q4 + both do not +STT_DEFAULT=${STT_DEFAULT:-qwen3-asr} +VOICE=${VOICE:-serena} +# fixed loopback ports of the model servers +GUFO_LLM_PORT=${GUFO_LLM_PORT:-8081}; LLAMA_PORT=${LLAMA_PORT:-8080} +GUFO_TTS_PORT=${GUFO_TTS_PORT:-8091}; GUFO_ASR_PORT=${GUFO_ASR_PORT:-8092} +# memory: measured GTT peaks on a Radeon 8060S (gfx1151) with 96 GiB GTT; the budget is the GTT pool less a margin, +# because GPU allocations beyond GTT fail even when MemAvailable has room +FLASHNEXT_RESIDENT=${FLASHNEXT_RESIDENT:-94489280512} # 88 GiB +Q3_RESIDENT=${Q3_RESIDENT:-66571993088} # 62 GiB +TTS_RESIDENT=${TTS_RESIDENT:-6979321856} # 6.5 GiB +ASR_RESIDENT=${ASR_RESIDENT:-5905580032} # 5.5 GiB +RESERVE_BYTES=${RESERVE_BYTES:-4294967296} +GTT_MARGIN_BYTES=${GTT_MARGIN_BYTES:-2147483648} diff --git a/deploy/strix-halo/render.sh b/deploy/strix-halo/render.sh new file mode 100755 index 00000000..4489e90d --- /dev/null +++ b/deploy/strix-halo/render.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Renders deploy/strix-halo/config.json.in into $DEPLOY/config.json from env.sh (+ $SITE). budget_bytes defaults to +# the GPU's GTT pool less GTT_MARGIN_BYTES (tools/install/lib.sh hw_gtt). Prints the path. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) +source "$REPO/tools/install/lib.sh" +source "$here/env.sh"; [ -z "${SITE:-}" ] || source "$SITE" +gtt=$(hw_gtt); BUDGET_BYTES=${BUDGET_BYTES:-$(( gtt > GTT_MARGIN_BYTES ? gtt - GTT_MARGIN_BYTES : 0 ))} +SRC=$REPO +mkdir -p "$DEPLOY/inbox" "$DEPLOY/data" "$DEPLOY/logs" +export MACHINE RESERVE_BYTES BUDGET_BYTES DEPLOY CHAT_DEFAULT STT_DEFAULT VOICE_CHAT VOICE FLASHNEXT_DIR FLASHNEXT_RESIDENT \ + GUFO_LLM_PORT Q3_DIR Q3_RESIDENT LLAMA_BIN LLAMA_PORT PYTHON SRC TTS_DIR TTS_RESIDENT GUFO_TTS_PORT ASR_DIR ASR_RESIDENT \ + GUFO_ASR_PORT J WHISPER_DIR +python3 -I - "$here/config.json.in" "$DEPLOY/config.json" <<'PY' +import json, os, re, sys +src, out = sys.argv[1], sys.argv[2] +text = re.sub(r"@([A-Z0-9_]+)@", lambda m: os.environ[m.group(1)], open(src).read()) +json.loads(text) # a template or site value that breaks JSON fails here, not in the daemon +open(out + ".tmp", "w").write(text); os.replace(out + ".tmp", out) +PY +echo "$DEPLOY/config.json" diff --git a/deploy/strix-halo/start.sh b/deploy/strix-halo/start.sh new file mode 100755 index 00000000..65b03209 --- /dev/null +++ b/deploy/strix-halo/start.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Starts the daemon as a transient systemd user unit ($UNIT; no unit file, no sudo), after rendering the config, and +# waits for /health. Logs: journalctl --user -u $UNIT. SITE=path/to/site.env selects a site file. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) +source "$here/env.sh"; [ -z "${SITE:-}" ] || source "$SITE" +[ -x "$LR_BIN" ] || { echo "start.sh: no $LR_BIN (cd $REPO && zig build -Doptimize=ReleaseSafe)" >&2; exit 1; } +cfg=$(bash "$here/render.sh") +systemctl --user is-active -q "$UNIT" && { echo "start.sh: $UNIT is already running (stop.sh first)" >&2; exit 1; } +systemctl --user reset-failed "$UNIT" 2> /dev/null || true +systemd-run --user --unit="$UNIT" --collect -p KillMode=mixed -p TimeoutStopSec=90 \ + --setenv=PATH="$PATH" --setenv=HOME="$HOME" \ + "$LR_BIN" serve --config "$cfg" --host 127.0.0.1 --port "$PORT" --data "$DEPLOY/data" > /dev/null +for _ in $(seq 1 60); do curl -fs -m 2 "http://127.0.0.1:$PORT/health" > /dev/null && { echo "localrouter up on http://127.0.0.1:$PORT ($UNIT)"; exit 0; }; sleep 1; done +echo "start.sh: no /health after 60 s; journalctl --user -u $UNIT -n 50" >&2; exit 1 diff --git a/deploy/strix-halo/status.sh b/deploy/strix-halo/status.sh new file mode 100755 index 00000000..3ab941af --- /dev/null +++ b/deploy/strix-halo/status.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# The unit, /health, each tool's state, the model containers and GTT. +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) +source "$here/env.sh"; [ -z "${SITE:-}" ] || source "$SITE" +source "$REPO/tools/install/lib.sh" +echo "unit $UNIT: $(systemctl --user is-active "$UNIT" 2> /dev/null)" +curl -fs -m 3 "http://127.0.0.1:$PORT/health" > /dev/null && echo "health: ok" || echo "health: no answer on :$PORT" +curl -fs -m 5 "http://127.0.0.1:$PORT/v1/tools" 2> /dev/null | jq -r '.data[] | " \(.id): \(.state)"' 2> /dev/null +echo "containers: $(podman ps --format '{{.Names}}' --filter name=lr-gufo- | tr '\n' ' ')" +hw_amd && echo "GTT in use: $(gib "$(hw_gtt_used)") of $(gib "$(hw_gtt)") GiB" diff --git a/deploy/strix-halo/stop.sh b/deploy/strix-halo/stop.sh new file mode 100755 index 00000000..9aee6d10 --- /dev/null +++ b/deploy/strix-halo/stop.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Stops the daemon (its workers stop their model servers), then any Gufo container a killed worker left behind. +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) +source "$here/env.sh"; [ -z "${SITE:-}" ] || source "$SITE" +systemctl --user stop "$UNIT" 2> /dev/null +left=$(podman ps -q --filter name=lr-gufo- 2> /dev/null) +[ -z "$left" ] || { echo "stopping leftover containers: $(podman ps --format '{{.Names}}' --filter name=lr-gufo- | tr '\n' ' ')"; podman stop -t 10 $left > /dev/null; } +source "$REPO/tools/install/lib.sh" +hw_amd && echo "GTT in use: $(gib "$(hw_gtt_used)") GiB" +exit 0 From b46deecf98b8f792d678f3a63e7e6c4d29c70404 Mon Sep 17 00:00:00 2001 From: smfworks Date: Mon, 16 Nov 2026 09:25:10 -0500 Subject: [PATCH 08/13] strix-halo: pin every download, pass the image to the unit, diagnose as a GPU step Review of 944f585: - Torch wheel unhashed (whisper/rocm/uv.lock): PyTorch's index publishes no digest, so the wheel's sha256 (2ad8066c..., 6227849000 bytes) is added by hand. uv sync --locked refuses other bytes (checked with a one-digit change: "Hash mismatch"). tools/install/check_hashes.py refuses any uv.lock or requirements*.txt artifact without a sha256; CI runs it over the checkout, and its tests. - Gufo pinned by digest: tools/gufo/IMAGE is gufo-runtime:0.34.0@sha256:49b1fce4... (engine 2845939b, the build measured here). serve.sh refuses a reference without a digest unless GUFO_ALLOW_UNPINNED=1; the profile's step checks the pulled digest. - Hugging Face weights by commit, every file by size and sha256: pins/*.json for Flash-Next Q4 and Q3 (f5d175de), Qwen3-TTS CustomVoice (0c0e3051) and Qwen3-ASR (7278e1e7). tools/install/hf_pinned.py downloads the manifest's files at its revision through hf (resumable) and verifies them; done is a stamp of the manifest plus a size check. The local copies on the test box verify against all four. - GUFO_IMAGE reaches the workers: start.sh passes it (and GUFO_ALLOW_UNPINNED, GUFO_STOP_TIMEOUT when set) into the transient unit; env.sh defaults it from tools/gufo/IMAGE. deploy/strix-halo/test_start.sh runs start.sh with a stub systemd-run that gives the daemon only --setenv values and a stub podman that records the image: default, exported and site-file overrides, a digest-less refusal (11 checks; 3 pass against the old start.sh). - gufo diagnose is its own step, gpu: true, so --no-gpu skips it; the image step only pulls and checks the digest. - CI: bash -n over deploy/strix-halo/*.sh and tools/gufo/*.sh; the hash check, hf_pinned tests and the unit test. --- .github/workflows/ci.yml | 9 +- deploy/profiles/strix-halo-gfx1151.json | 68 +++++++---- deploy/strix-halo/README.md | 5 + deploy/strix-halo/env.sh | 1 + deploy/strix-halo/pins/flash-next-q3.json | 8 ++ deploy/strix-halo/pins/flash-next-q4.json | 9 ++ deploy/strix-halo/pins/qwen3-asr.json | 15 +++ .../pins/qwen3-tts-customvoice.json | 16 +++ deploy/strix-halo/start.sh | 6 +- deploy/strix-halo/test_start.sh | 61 ++++++++++ tools/gufo/IMAGE | 1 + tools/gufo/README.md | 6 +- tools/gufo/serve.sh | 9 +- tools/install/check_hashes.py | 73 ++++++++++++ tools/install/hf_pinned.py | 109 ++++++++++++++++++ tools/install/test_check_hashes.py | 56 +++++++++ tools/install/test_hf_pinned.py | 56 +++++++++ tools/speech/whisper/rocm/README.md | 5 +- tools/speech/whisper/rocm/uv.lock | 2 +- 19 files changed, 481 insertions(+), 34 deletions(-) create mode 100644 deploy/strix-halo/pins/flash-next-q3.json create mode 100644 deploy/strix-halo/pins/flash-next-q4.json create mode 100644 deploy/strix-halo/pins/qwen3-asr.json create mode 100644 deploy/strix-halo/pins/qwen3-tts-customvoice.json create mode 100755 deploy/strix-halo/test_start.sh create mode 100644 tools/gufo/IMAGE create mode 100644 tools/install/check_hashes.py create mode 100644 tools/install/hf_pinned.py create mode 100644 tools/install/test_check_hashes.py create mode 100644 tools/install/test_hf_pinned.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85068b13..a190c84c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: echo "$RUNNER_TEMP/zig" >> "$GITHUB_PATH" - name: the installer's scripts and manifests parse, and its plan runs (INSTALL.md) run: | - for f in tools/install/*.sh deploy/jarvis/*.sh deploy/mac/*.sh tools/spark/install.sh tools/spark/prepare.sh; do bash -n "$f"; done + for f in tools/install/*.sh deploy/jarvis/*.sh deploy/mac/*.sh deploy/strix-halo/*.sh tools/gufo/*.sh tools/spark/install.sh tools/spark/prepare.sh; do bash -n "$f"; done for f in deploy/profiles/*.json tools/twin/packs/sources/*.json tools/twin/packs/built/*.json; do jq empty "$f"; done for p in deploy/profiles/*.json; do tools/install/bootstrap.sh --profile "$(basename "$p" .json)" --prefix "$RUNNER_TEMP/jarvis" --dry-run; done # the Mac service's config: every profile model has its tool entry, each booked and resident as the profile says @@ -32,6 +32,13 @@ jobs: run: bash tools/install/test_amd.sh - name: the openai_audio worker against a fake server (no GPU) run: python3 -I tools/speech/openai_audio/test_worker.py + - name: every lock file pins every artifact by sha256 (tools/install/check_hashes.py), and the pinned downloads verify + run: | + python3 -I tools/install/check_hashes.py + python3 -I tools/install/test_check_hashes.py + python3 -I tools/install/test_hf_pinned.py + - name: the Strix Halo unit passes the pinned Gufo image to its workers (no GPU, stub systemd-run and podman) + run: bash deploy/strix-halo/test_start.sh - run: zig build - run: zig build test timeout-minutes: 20 diff --git a/deploy/profiles/strix-halo-gfx1151.json b/deploy/profiles/strix-halo-gfx1151.json index 8ffb05d1..cefea30f 100644 --- a/deploy/profiles/strix-halo-gfx1151.json +++ b/deploy/profiles/strix-halo-gfx1151.json @@ -23,7 +23,10 @@ "TTS_DIR": "${TTS_DIR:-$J/models/Qwen3-TTS-12Hz-1.7B-CustomVoice}", "ASR_DIR": "${ASR_DIR:-$J/models/Qwen3-ASR-1.7B}", "LLAMA_BIN": "${LLAMA_BIN:-$J/llama.cpp/bin}", - "GUFO_IMAGE": "${GUFO_IMAGE:-ghcr.io/gufo-org/toolboxes/gufo-runtime:latest}" + "GUFO_IMAGE": "${GUFO_IMAGE:-$(cat $REPO/tools/gufo/IMAGE)}", + "PINS": "$REPO/deploy/strix-halo/pins", + "HF_PINNED": "python3 -I $REPO/tools/install/hf_pinned.py", + "HF": "$J/bin/uvx --from huggingface_hub==2.4.0 hf" }, "prereqs": [ { @@ -133,10 +136,21 @@ "id": "gufo-image", "download_bytes": 3490000000, "disk_bytes": 3490000000, - "title": "the Gufo runtime image (ghcr.io/gufo-org/toolboxes/gufo-runtime, MIT; ROCm 10.1 inside)", - "run": "podman pull $GUFO_IMAGE && podman run --rm --device /dev/kfd --device /dev/dri --group-add video --group-add render $GUFO_IMAGE gufo diagnose", - "done": "podman image exists $GUFO_IMAGE", - "fix": "network to ghcr.io: run again; gufo diagnose says what the host lacks" + "title": "the Gufo runtime image (ghcr.io/gufo-org/toolboxes/gufo-runtime 0.34.0, MIT; ROCm 10.1 inside), pinned by digest in tools/gufo/IMAGE", + "run": "case $GUFO_IMAGE in *@sha256:*) ;; *) echo \"GUFO_IMAGE $GUFO_IMAGE is not pinned by digest\" >&2; exit 1 ;; esac; podman pull $GUFO_IMAGE && [ \"$(podman image inspect --format '{{.Digest}}' $GUFO_IMAGE)\" = \"${GUFO_IMAGE##*@}\" ]", + "done": "podman image exists $GUFO_IMAGE && [ \"$(podman image inspect --format '{{.Digest}}' $GUFO_IMAGE)\" = \"${GUFO_IMAGE##*@}\" ]", + "fix": "network to ghcr.io: run again; a digest mismatch means the registry served other bytes than the pin (podman refuses those too)" + }, + { + "id": "gufo-diagnose", + "gpu": true, + "min_free_gib": 8, + "download_bytes": 0, + "disk_bytes": 0, + "title": "gufo diagnose in the pinned image: the host's GPU devices, groups and GTT as Gufo sees them", + "run": "podman run --rm --device /dev/kfd --device /dev/dri --group-add video --group-add render $GUFO_IMAGE gufo diagnose && mkdir -p $J/install/state && echo $GUFO_IMAGE > $J/install/state/gufo-diagnose", + "done": "[ \"$(cat $J/install/state/gufo-diagnose 2> /dev/null)\" = \"$GUFO_IMAGE\" ]", + "fix": "gufo diagnose says what the host lacks (the gpu-devices and gtt prerequisites above)" } ] }, @@ -158,12 +172,13 @@ "id": "weights", "download_bytes": 115028765978, "disk_bytes": 115100000000, - "title": "unsloth/Qwen3.8-Flash-Next-GGUF: UD-Q4_K_XL (4 shards), MTP/mtp-...-shared-Q8_0.gguf, mmproj-BF16.gguf", - "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download unsloth/Qwen3.8-Flash-Next-GGUF --local-dir $FLASHNEXT_DIR --include 'UD-Q4_K_XL/*' --include 'MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf' --include 'mmproj-BF16.gguf'", - "done": "[ -s $FLASHNEXT_DIR/UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00004-of-00004.gguf ] && [ -s $FLASHNEXT_DIR/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf ] && [ -s $FLASHNEXT_DIR/mmproj-BF16.gguf ]", - "fix": "network to huggingface.co: run again (hf resumes)" + "title": "unsloth/Qwen3.8-Flash-Next-GGUF at f5d175de: UD-Q4_K_XL (4 shards), MTP/mtp-...-shared-Q8_0.gguf, mmproj-BF16.gguf; every file by sha256 (deploy/strix-halo/pins/flash-next-q4.json)", + "run": "$HF_PINNED download $PINS/flash-next-q4.json $FLASHNEXT_DIR --hf '$HF' && $STEPS stamp flash-next-q4 $PINS/flash-next-q4.json", + "done": "$STEPS stamped flash-next-q4 $PINS/flash-next-q4.json && $HF_PINNED verify $PINS/flash-next-q4.json $FLASHNEXT_DIR --sizes", + "fix": "network to huggingface.co: run again (hf resumes); a file that differs from its pin is named in the log" } - ] + ], + "pins": "deploy/strix-halo/pins/flash-next-q4.json" }, { "key": "chat-q3", @@ -191,12 +206,13 @@ "id": "weights", "download_bytes": 89464948506, "disk_bytes": 89500000000, - "title": "unsloth/Qwen3.8-Flash-Next-GGUF: UD-Q3_K_XL (4 shards) and the shared MTP head", - "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download unsloth/Qwen3.8-Flash-Next-GGUF --local-dir $FLASHNEXT_DIR --include 'UD-Q3_K_XL/*' --include 'MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf'", - "done": "[ -s $FLASHNEXT_DIR/UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00004-of-00004.gguf ] && [ -s $FLASHNEXT_DIR/MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf ]", - "fix": "network to huggingface.co: run again (hf resumes)" + "title": "unsloth/Qwen3.8-Flash-Next-GGUF at f5d175de: UD-Q3_K_XL (4 shards) and the shared MTP head; every file by sha256 (deploy/strix-halo/pins/flash-next-q3.json)", + "run": "$HF_PINNED download $PINS/flash-next-q3.json $FLASHNEXT_DIR --hf '$HF' && $STEPS stamp flash-next-q3 $PINS/flash-next-q3.json", + "done": "$STEPS stamped flash-next-q3 $PINS/flash-next-q3.json && $HF_PINNED verify $PINS/flash-next-q3.json $FLASHNEXT_DIR --sizes", + "fix": "network to huggingface.co: run again (hf resumes); a file that differs from its pin is named in the log" } - ] + ], + "pins": "deploy/strix-halo/pins/flash-next-q3.json" }, { "key": "tts", @@ -215,12 +231,13 @@ "id": "weights", "download_bytes": 4544233100, "disk_bytes": 4600000000, - "title": "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice", - "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice --local-dir $TTS_DIR", - "done": "[ -s $TTS_DIR/config.json ] && ls $TTS_DIR/*.safetensors > /dev/null 2>&1", - "fix": "network to huggingface.co: run again" + "title": "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice at 0c0e3051, every file by sha256 (deploy/strix-halo/pins/qwen3-tts-customvoice.json)", + "run": "$HF_PINNED download $PINS/qwen3-tts-customvoice.json $TTS_DIR --hf '$HF' && $STEPS stamp qwen3-tts-customvoice $PINS/qwen3-tts-customvoice.json", + "done": "$STEPS stamped qwen3-tts-customvoice $PINS/qwen3-tts-customvoice.json && $HF_PINNED verify $PINS/qwen3-tts-customvoice.json $TTS_DIR --sizes", + "fix": "network to huggingface.co: run again (hf resumes); a file that differs from its pin is named in the log" } - ] + ], + "pins": "deploy/strix-halo/pins/qwen3-tts-customvoice.json" }, { "key": "stt", @@ -239,12 +256,13 @@ "id": "weights", "download_bytes": 4703117477, "disk_bytes": 4750000000, - "title": "Qwen/Qwen3-ASR-1.7B", - "run": "$J/bin/uvx --from huggingface_hub==2.4.0 hf download Qwen/Qwen3-ASR-1.7B --local-dir $ASR_DIR", - "done": "[ -s $ASR_DIR/config.json ] && ls $ASR_DIR/*.safetensors > /dev/null 2>&1", - "fix": "network to huggingface.co: run again" + "title": "Qwen/Qwen3-ASR-1.7B at 7278e1e7, every file by sha256 (deploy/strix-halo/pins/qwen3-asr.json)", + "run": "$HF_PINNED download $PINS/qwen3-asr.json $ASR_DIR --hf '$HF' && $STEPS stamp qwen3-asr $PINS/qwen3-asr.json", + "done": "$STEPS stamped qwen3-asr $PINS/qwen3-asr.json && $HF_PINNED verify $PINS/qwen3-asr.json $ASR_DIR --sizes", + "fix": "network to huggingface.co: run again (hf resumes); a file that differs from its pin is named in the log" } - ] + ], + "pins": "deploy/strix-halo/pins/qwen3-asr.json" }, { "key": "whisper", diff --git a/deploy/strix-halo/README.md b/deploy/strix-halo/README.md index 4ffd29d2..6112c68f 100644 --- a/deploy/strix-halo/README.md +++ b/deploy/strix-halo/README.md @@ -24,6 +24,11 @@ deploy/strix-halo/stop.sh # stop the daemon (its workers SITE=path/to/site.env deploy/strix-halo/start.sh # with a site file (paths, voice, which model does what) ``` +Every download is pinned: the Gufo runtime by digest (`tools/gufo/IMAGE`; `start.sh` passes it into the unit, so the +workers run the image bootstrap pulled), the Hugging Face weights by commit with every file's size and sha256 +(`pins/*.json`, fetched and checked by `tools/install/hf_pinned.py`), the Whisper venv by `uv.lock` hashes, llama.cpp +and the host tools by sha256. `gufo diagnose` is a GPU step of its own (`--no-gpu` skips it). + `env.sh` holds every default (prefix `$J`, ports, model directories, measured memory); a site file sourced after it overrides any of them. `tools/install/doctor.sh --profile strix-halo-gfx1151 --unit localrouter-amd` checks the box (GPU, ROCm, GTT, Podman, the steps, the service); export the site file's variables first when it moves model paths. diff --git a/deploy/strix-halo/env.sh b/deploy/strix-halo/env.sh index 66bdeccb..ec934000 100644 --- a/deploy/strix-halo/env.sh +++ b/deploy/strix-halo/env.sh @@ -14,6 +14,7 @@ TTS_DIR=${TTS_DIR:-$J/models/Qwen3-TTS-12Hz-1.7B-CustomVoice} ASR_DIR=${ASR_DIR:-$J/models/Qwen3-ASR-1.7B} WHISPER_DIR=${WHISPER_DIR:-$J/models/whisper/whisper-large-v3-turbo/41f01f3fe87f28c78e2fbf8b568835947dd65ed9} LLAMA_BIN=${LLAMA_BIN:-$J/llama.cpp/bin} # a llama.cpp build with llama-server +GUFO_IMAGE=${GUFO_IMAGE:-$(cat "$REPO/tools/gufo/IMAGE")} # the Gufo runtime, pinned by digest; start.sh passes it to the unit # which model serves what CHAT_DEFAULT=${CHAT_DEFAULT:-qwen3.8-flash-next} VOICE_CHAT=${VOICE_CHAT:-qwen3.8-flash-next-q3} # Q3 + TTS + ASR fit the 96 GiB GTT together; Q4 + both do not diff --git a/deploy/strix-halo/pins/flash-next-q3.json b/deploy/strix-halo/pins/flash-next-q3.json new file mode 100644 index 00000000..e67b721e --- /dev/null +++ b/deploy/strix-halo/pins/flash-next-q3.json @@ -0,0 +1,8 @@ +{"repo": "unsloth/Qwen3.8-Flash-Next-GGUF", "revision": "f5d175de2cf7f720d45d6064019a81fcf056e986", + "files": { + "MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf": [2786568256, "5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6"], + "UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00001-of-00004.gguf": [10946618, "7666000ba91eb5527f8e12e0414de36766dc82a082876337f7827c2caa859143"], + "UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00002-of-00004.gguf": [49742117248, "e954cb3044ae087a003ce8cc1631c9d40fe15ae64a8befcf4aa06457848c647c"], + "UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00003-of-00004.gguf": [10911746208, "fcce26b1e5e6e54559a7e7c2f8d6e37067ec695ff1f14bce662810bde78abe1f"], + "UD-Q3_K_XL/Qwen3.8-Flash-Next-UD-Q3_K_XL-00004-of-00004.gguf": [28800138432, "5de8b5dbf89409acc39468decafd4a4a95b13c29d88a14b0356107897829ec36"] + }} diff --git a/deploy/strix-halo/pins/flash-next-q4.json b/deploy/strix-halo/pins/flash-next-q4.json new file mode 100644 index 00000000..91e0fb7c --- /dev/null +++ b/deploy/strix-halo/pins/flash-next-q4.json @@ -0,0 +1,9 @@ +{"repo": "unsloth/Qwen3.8-Flash-Next-GGUF", "revision": "f5d175de2cf7f720d45d6064019a81fcf056e986", + "files": { + "MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf": [2786568256, "5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6"], + "UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf": [10946618, "acc44040f74d0e55fb89c3967056cce5dbda1bcc52e909c3ba6fc72b5e9c0858"], + "UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00002-of-00004.gguf": [49720539552, "45792ae869072d8229384c51c7c73dd959e191505252b41dd71852d9746f5ce4"], + "UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00003-of-00004.gguf": [32803030176, "8c76e79d444b16a663d9c8db54e585ed3b1da13eebd2619c37b0c355da803c82"], + "UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00004-of-00004.gguf": [28800138432, "5de8b5dbf89409acc39468decafd4a4a95b13c29d88a14b0356107897829ec36"], + "mmproj-BF16.gguf": [907542944, "2e788f8c511d8093c7b43cb87b2fd7e14228340318057f8fb20c86df2efe2355"] + }} diff --git a/deploy/strix-halo/pins/qwen3-asr.json b/deploy/strix-halo/pins/qwen3-asr.json new file mode 100644 index 00000000..91d22eed --- /dev/null +++ b/deploy/strix-halo/pins/qwen3-asr.json @@ -0,0 +1,15 @@ +{"repo": "Qwen/Qwen3-ASR-1.7B", "revision": "7278e1e70fe206f11671096ffdd38061171dd6e5", + "files": { + ".gitattributes": [1519, "11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361"], + "README.md": [57456, "5058416891bc47a2051557765997e8c42f8eb78a0e33c3e775bd17d4b0ba4d50"], + "chat_template.json": [1161, "75a8cfca24f00de72d796fbfed6858fc9614ef3dabd8696684cc3bc03a9c58ff"], + "config.json": [6194, "2e74a751548b8ad7d7526d29365ad8144c345d8b412b1152d25dc6698452712f"], + "generation_config.json": [142, "1da527824d81e07118facff437e03f2e24a23311e3bdeb2368973fe77e5f275c"], + "merges.txt": [1671853, "8831e4f1a044471340f7c0a83d7bd71306a5b867e95fd870f74d0c5308a904d5"], + "model-00001-of-00002.safetensors": [4220320824, "a4cd1f1a04d90b757dc7f7dd26254e69a013b19e80efe590a83c6a3bde8608d6"], + "model-00002-of-00002.safetensors": [478200688, "6e0b9d9e09e2e0238e7ef3cc8a484ab387e91b90f1900bedf88bc92d7929ccfc"], + "model.safetensors.index.json": [64821, "f994739fe38e5210b9e3e8ce6c6307315e2ceac3cb630e7b7414d69dce520f60"], + "preprocessor_config.json": [330, "45e120a4eda2c20c5d7f2ea9354e63536bf35e27aa573fb7cdf78017b378770d"], + "tokenizer_config.json": [12487, "4942d005604266809309cabc9f4e9cb89ce855d59b14681fdc0e1cc62ea26c4c"], + "vocab.json": [2776833, "ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910"] + }} diff --git a/deploy/strix-halo/pins/qwen3-tts-customvoice.json b/deploy/strix-halo/pins/qwen3-tts-customvoice.json new file mode 100644 index 00000000..b7910b69 --- /dev/null +++ b/deploy/strix-halo/pins/qwen3-tts-customvoice.json @@ -0,0 +1,16 @@ +{"repo": "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice", "revision": "0c0e3051f131929182e2c023b9537f8b1c68adfe", + "files": { + ".gitattributes": [1519, "11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361"], + "README.md": [57846, "64f65e809b51cc0c35f393fbbfcc2d735c0cb3fdbbc6f3fdc4a5e6ce55e9d088"], + "config.json": [4908, "17a07f527a1c25ea30b4e023a184482a23d3e279d697b1dc81b1bde498d29cf9"], + "generation_config.json": [245, "f1b90b4513f3b34c62851049e2492d7b4c5940daf1276f89c82b8ef04127f3aa"], + "merges.txt": [1671839, "599bab54075088774b1733fde865d5bd747cbcc7a547c5bc12610e874e26f5e3"], + "model.safetensors": [3833402552, "38b1d5971bdbd982b561cccec982669a53b0537c3cf5e9bd4778ed07bb2f5137"], + "preprocessor_config.json": [127, "efdde1022ea9d76928bf7a9cd53139138f5ba2e466e837f08f6105ab1af1c119"], + "speech_tokenizer/config.json": [2336, "ee65bb901c876664ab8707c487157aa1a6ee57c65969b28fb5ec9dc211e68167"], + "speech_tokenizer/configuration.json": [76, "6bc26d64eb5024b4d1dab5a52371958b429256d6c9d59787f1f5294a54e0cebd"], + "speech_tokenizer/model.safetensors": [682293092, "836b7b357f5ea43e889936a3709af68dfe3751881acefe4ecf0dbd30ba571258"], + "speech_tokenizer/preprocessor_config.json": [234, "fcb3805e597e786d4067706e602f6688524640f8d3396790e2e09b5942fcbdfb"], + "tokenizer_config.json": [7344, "dc3c31c3bdaedd5016382bb3cbe07323026775ad51f5a4fb564505992ae4a670"], + "vocab.json": [2776833, "ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910"] + }} diff --git a/deploy/strix-halo/start.sh b/deploy/strix-halo/start.sh index 65b03209..da5501f8 100755 --- a/deploy/strix-halo/start.sh +++ b/deploy/strix-halo/start.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Starts the daemon as a transient systemd user unit ($UNIT; no unit file, no sudo), after rendering the config, and -# waits for /health. Logs: journalctl --user -u $UNIT. SITE=path/to/site.env selects a site file. +# waits for /health. Logs: journalctl --user -u $UNIT. SITE=path/to/site.env selects a site file. A transient unit +# starts with an empty environment: what the workers need from this one (PATH, HOME, GUFO_IMAGE) is passed explicitly. set -euo pipefail here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) source "$here/env.sh"; [ -z "${SITE:-}" ] || source "$SITE" @@ -9,7 +10,8 @@ cfg=$(bash "$here/render.sh") systemctl --user is-active -q "$UNIT" && { echo "start.sh: $UNIT is already running (stop.sh first)" >&2; exit 1; } systemctl --user reset-failed "$UNIT" 2> /dev/null || true systemd-run --user --unit="$UNIT" --collect -p KillMode=mixed -p TimeoutStopSec=90 \ - --setenv=PATH="$PATH" --setenv=HOME="$HOME" \ + --setenv=PATH="$PATH" --setenv=HOME="$HOME" --setenv=GUFO_IMAGE="$GUFO_IMAGE" \ + ${GUFO_ALLOW_UNPINNED:+--setenv=GUFO_ALLOW_UNPINNED="$GUFO_ALLOW_UNPINNED"} ${GUFO_STOP_TIMEOUT:+--setenv=GUFO_STOP_TIMEOUT="$GUFO_STOP_TIMEOUT"} \ "$LR_BIN" serve --config "$cfg" --host 127.0.0.1 --port "$PORT" --data "$DEPLOY/data" > /dev/null for _ in $(seq 1 60); do curl -fs -m 2 "http://127.0.0.1:$PORT/health" > /dev/null && { echo "localrouter up on http://127.0.0.1:$PORT ($UNIT)"; exit 0; }; sleep 1; done echo "start.sh: no /health after 60 s; journalctl --user -u $UNIT -n 50" >&2; exit 1 diff --git a/deploy/strix-halo/test_start.sh b/deploy/strix-halo/test_start.sh new file mode 100755 index 00000000..86c71614 --- /dev/null +++ b/deploy/strix-halo/test_start.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Tests that the Gufo image start.sh chooses reaches the workers' containers (no GPU, no systemd, no podman): +# bash deploy/strix-halo/test_start.sh +# A stub systemd-run runs the daemon the way a transient unit does, with an empty environment plus its --setenv +# values; the stub daemon starts tools/gufo/serve.sh as a worker would, and a stub podman records the image it is given. +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$here/../.." && pwd) +pinned=$(cat "$REPO/tools/gufo/IMAGE") +other="registry.invalid/gufo/runtime:9.9@sha256:$(printf 'ab%.0s' $(seq 32))" +fails=0 n=0 +scratch=$(mktemp -d); trap 'rm -rf "$scratch"' EXIT +check() { n=$((n + 1)); if [ "$2" = "$3" ]; then echo "PASS $1"; else echo "FAIL $1: got '$2', want '$3'"; fails=$((fails + 1)); fi; } + +# start [VAR=VALUE...]: start.sh in a fresh prefix with these variables exported; sets $t (the scratch directory) +start() { + t=$(mktemp -d "$scratch/run.XXXXXX"); mkdir -p "$t/bin" + cat > "$t/bin/systemd-run" < "$t/unit.log" 2>&1 +SH + printf '#!/bin/sh\n[ "$2" = is-active ] && exit 3\nexit 0\n' > "$t/bin/systemctl" + printf '#!/bin/sh\nexit 0\n' > "$t/bin/curl" + printf '#!/bin/sh\nfor a in "$@"; do case $a in *@sha256:*|*:latest|*/*:*) echo "$a" > %q ;; esac; done\n' "$t/podman-image" > "$t/bin/podman" + cat > "$t/lr" < "$t/unit-env" +"$REPO/tools/gufo/serve.sh" asr 18092 -- gufo serve asr --model /m 2> "$t/serve.err" +echo \$? > "$t/serve-rc" +SH + chmod +x "$t/bin/"* "$t/lr" + ( export PATH="$t/bin:$PATH" J="$t/j" LR_BIN="$t/lr" "$@"; bash "$here/start.sh" > "$t/start.out" 2>&1 ) +} +unit() { sed -n "s/^$1=//p" "$t/unit-env"; } +seen() { cat "$t/podman-image" 2> /dev/null; } + +start +check "default: the unit gets the pinned image" "$(unit GUFO_IMAGE)" "$pinned" +check "default: the worker's container runs it" "$(seen)" "$pinned" +check "the pin is a digest" "$(grep -c '@sha256:[0-9a-f]\{64\}$' "$REPO/tools/gufo/IMAGE")" 1 +start GUFO_IMAGE="$other" UNRELATED=leak +check "exported override: reaches the unit" "$(unit GUFO_IMAGE)" "$other" +check "exported override: reaches the container" "$(seen)" "$other" +check "a variable start.sh does not pass stays out (the unit's environment is empty)" "$(unit UNRELATED)" "" +site=$scratch/site.env; echo "GUFO_IMAGE=$other" > "$site" +start SITE="$site" +check "site file override: reaches the container" "$(seen)" "$other" +start GUFO_IMAGE=ghcr.io/gufo-org/toolboxes/gufo-runtime:latest +check "a tag without a digest: serve.sh refuses (exit 2)" "$(cat "$t/serve-rc")" 2 +check "a tag without a digest: no container" "$(seen)" "" +check "a tag without a digest: it says why" "$(grep -c 'not pinned by digest' "$t/serve.err")" 1 +start GUFO_IMAGE=ghcr.io/gufo-org/toolboxes/gufo-runtime:latest GUFO_ALLOW_UNPINNED=1 +check "GUFO_ALLOW_UNPINNED=1 reaches the unit and runs the tag" "$(unit GUFO_ALLOW_UNPINNED) $(seen)" "1 ghcr.io/gufo-org/toolboxes/gufo-runtime:latest" +echo "$((n - fails))/$n passed" +[ $fails = 0 ] diff --git a/tools/gufo/IMAGE b/tools/gufo/IMAGE new file mode 100644 index 00000000..ea0f585b --- /dev/null +++ b/tools/gufo/IMAGE @@ -0,0 +1 @@ +ghcr.io/gufo-org/toolboxes/gufo-runtime:0.34.0@sha256:49b1fce40cb43e33c46d91595e300cb320cdec768fcd976f8c8da24b402fc133 diff --git a/tools/gufo/README.md b/tools/gufo/README.md index 883864e8..412d3e6d 100644 --- a/tools/gufo/README.md +++ b/tools/gufo/README.md @@ -12,8 +12,10 @@ supervise it: the `openai_server` engine for chat, `tools/speech/openai_audio` f `lr-gufo-*` left over. - `/dev/kfd` and `/dev/dri` are passed with the `video` and `render` groups by name: Gufo's docs use `--group-add keep-groups`, which needs the crun runtime, and many hosts run runc. -- `GUFO_IMAGE` picks the image (default `ghcr.io/gufo-org/toolboxes/gufo-runtime:latest`; pin a version for - reproducible installs). +- The image is pinned by digest in `IMAGE` (`gufo-runtime:0.34.0@sha256:49b1fce4…`, Gufo engine 2845939b), the + build these figures were measured on; podman checks the pulled manifest against the digest. `GUFO_IMAGE` overrides + it with another `name@sha256:…` (a reference without a digest is refused unless `GUFO_ALLOW_UNPINNED=1`). + `deploy/strix-halo/start.sh` passes the chosen image into the daemon's unit, so the workers run what bootstrap pulled. Measured on a Radeon 8060S with 96 GiB GTT (2026-11-15): Flash-Next UD-Q4_K_XL with the MTP head peaks at 88 GiB GTT serving 32k context with 2 sessions (pp512 1196 tok/s, decode 60-78 tok/s with MTP); Qwen3-TTS CustomVoice 6.5 GiB, about diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh index 200b9f1d..b277717a 100755 --- a/tools/gufo/serve.sh +++ b/tools/gufo/serve.sh @@ -5,7 +5,8 @@ # The container listens on 127.0.0.1:PORT only. SIGTERM/SIGINT (the daemon unloading the tool) stops the container and # waits until it is gone, so its GPU memory is free before this script exits. `--replace` clears a container left over # from a worker that was killed outright. -# Environment: GUFO_IMAGE (default ghcr.io/gufo-org/toolboxes/gufo-runtime:latest), GUFO_STOP_TIMEOUT (default 10 s). +# Environment: GUFO_IMAGE (default: tools/gufo/IMAGE, the runtime pinned by digest), GUFO_STOP_TIMEOUT (default 10 s). +# An image named without @sha256: is refused unless GUFO_ALLOW_UNPINNED=1: a tag can move between two installs. # Devices: /dev/kfd and /dev/dri; the video and render groups are passed by name, since keep-groups needs crun and # many hosts run runc. set -euo pipefail @@ -14,7 +15,11 @@ popts=() while [ $# -gt 0 ] && [ "$1" != -- ]; do popts+=("$1"); shift; done [ "${1:-}" = -- ] || { echo "serve.sh: missing -- before the gufo command" >&2; exit 2; } shift -image=${GUFO_IMAGE:-ghcr.io/gufo-org/toolboxes/gufo-runtime:latest} +image=${GUFO_IMAGE:-$(cat "$(dirname "$0")/IMAGE")} +case $image in + *@sha256:????????????????????????????????????????????????????????????????) ;; + *) [ "${GUFO_ALLOW_UNPINNED:-0}" = 1 ] || { echo "serve.sh: GUFO_IMAGE '$image' is not pinned by digest (name@sha256:...); GUFO_ALLOW_UNPINNED=1 runs it anyway" >&2; exit 2; } ;; +esac cname="lr-gufo-$name" stop() { podman stop -t "${GUFO_STOP_TIMEOUT:-10}" "$cname" > /dev/null 2>&1 || true; wait "$pid" 2> /dev/null || true; exit 0; } trap stop TERM INT diff --git a/tools/install/check_hashes.py b/tools/install/check_hashes.py new file mode 100644 index 00000000..b9ca8e98 --- /dev/null +++ b/tools/install/check_hashes.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +"""Refuses a lock file with an artifact it does not pin by hash (standard library only): + python3 -I tools/install/check_hashes.py [FILE...] +With no FILE it checks every uv.lock and requirements*.txt under the checkout (git ls-files, else a walk). uv.lock: +every wheel and sdist of every package must carry hash = "sha256:<64 hex>" (uv sync --locked then refuses any download +whose bytes differ; an artifact without a hash would be installed unchecked). requirements*.txt: every requirement +must carry --hash=sha256:<64 hex> (pip/uv --require-hashes). Exit 1 and one line per artifact otherwise.""" +import os +import re +import subprocess +import sys +import tomllib + +SHA = re.compile(r"sha256:[0-9a-f]{64}") +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + + +def uv_lock(path): + bad = [] + with open(path, "rb") as f: + lock = tomllib.load(f) + for p in lock.get("package", []): + src = p.get("source", {}) + if not any(k in src for k in ("registry", "url")): + continue # virtual, editable, path, git: no downloaded artifact + arts = ([p["sdist"]] if "sdist" in p else []) + list(p.get("wheels", [])) + if not arts: + bad.append(f"{p['name']} {p.get('version', '')}: no artifact listed") + for a in arts: + if not SHA.fullmatch(a.get("hash", "")): + bad.append(f"{p['name']} {p.get('version', '')}: {a.get('url') or a.get('path') or a.get('filename')} has no sha256") + return bad + + +def requirements(path): + bad, logical = [], "" + for raw in open(path): + line = raw.split(" #", 1)[0].rstrip("\n") if not raw.lstrip().startswith("#") else "" + if line.rstrip().endswith("\\"): + logical += line.rstrip()[:-1] + " " + continue + logical += line + req, logical = logical.strip(), "" + if not req or req.startswith("-"): + continue # an option line (--index-url, -r, ...) + if not any(SHA.fullmatch(h) for h in re.findall(r"--hash[= ](\S+)", req)): + bad.append(f"{req.split()[0]} has no --hash=sha256") + return bad + + +def tracked(): + try: + out = subprocess.run(["git", "-C", ROOT, "ls-files"], capture_output=True, text=True, check=True).stdout.split() + except (OSError, subprocess.CalledProcessError): + out = [os.path.relpath(os.path.join(d, f), ROOT) for d, _, fs in os.walk(ROOT) for f in fs] + return [os.path.join(ROOT, f) for f in sorted(out) + if os.path.basename(f) == "uv.lock" or re.fullmatch(r"requirements.*\.txt", os.path.basename(f))] + + +def main(argv): + files = argv or tracked() + failed = 0 + for f in files: + bad = uv_lock(f) if os.path.basename(f).endswith(".lock") else requirements(f) + for b in bad: + print(f"{os.path.relpath(f, ROOT)}: {b}") + failed += bool(bad) + print(f"{len(files) - failed}/{len(files)} lock files pin every artifact by sha256") + return 1 if failed else 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/install/hf_pinned.py b/tools/install/hf_pinned.py new file mode 100644 index 00000000..595f9457 --- /dev/null +++ b/tools/install/hf_pinned.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +"""Hugging Face downloads pinned by revision and checked file by file (standard library only). A manifest is +{"repo", "revision", "files": {"path": [bytes, "sha256"], ...}}, the files at one commit of the repo. + hf_pinned.py download MANIFEST DIR [--hf CMD] `CMD download REPO FILES... --revision REV --local-dir DIR` (hf resumes; + CMD default "hf"), then verify + hf_pinned.py verify MANIFEST DIR [--sizes] every manifest file in DIR has its size and sha256 (--sizes: its size + only, the cheap check of a tree a full verify already passed) + hf_pinned.py files MANIFEST the manifest's paths, one a line + hf_pinned.py pin REPO REVISION [GLOB...] writes a manifest for the files at REVISION matching GLOB (all when + none): sizes and sha256 from the Hub's LFS records, small files hashed + here. Needs the network; the others do not, except download +Exit 1 with one line per file that is missing or differs.""" +import fnmatch +import hashlib +import json +import os +import shlex +import subprocess +import sys +import urllib.parse +import urllib.request + +HUB = "https://huggingface.co" + + +def load(path): + with open(path) as f: + m = json.load(f) + if len(m.get("revision", "")) != 40 or not m.get("files"): + raise SystemExit(f"hf_pinned: {path} needs a 40-hex revision and files") + return m + + +def sha256_file(path): + h = hashlib.sha256() + with open(path, "rb") as f: + while chunk := f.read(1 << 24): + h.update(chunk) + return h.hexdigest() + + +def verify(m, root, sizes_only=False): + bad = [] + for name, (size, sha) in sorted(m["files"].items()): + p = os.path.join(root, name) + if not os.path.isfile(p): + bad.append(f"{name}: missing") + elif os.path.getsize(p) != size: + bad.append(f"{name}: {os.path.getsize(p)} bytes, the pin says {size}") + elif not sizes_only and sha256_file(p) != sha: + bad.append(f"{name}: sha256 differs from the pin {sha}") + return bad + + +def get(url): + req = urllib.request.Request(url, headers={"User-Agent": "localrouter-hf-pinned/1"}) + with urllib.request.urlopen(req, timeout=120) as r: + return r.read() + + +def pin(repo, rev, globs): + tree = json.loads(get(f"{HUB}/api/models/{repo}/tree/{rev}?recursive=true")) + files = {} + for e in tree: + if e.get("type") != "file" or (globs and not any(fnmatch.fnmatch(e["path"], g) for g in globs)): + continue + if e.get("lfs"): + files[e["path"]] = [e["lfs"]["size"], e["lfs"]["oid"]] + else: + data = get(f"{HUB}/{repo}/resolve/{rev}/{urllib.parse.quote(e['path'])}") + files[e["path"]] = [len(data), hashlib.sha256(data).hexdigest()] + if not files: + raise SystemExit(f"hf_pinned: nothing in {repo}@{rev} matches {globs}") + return {"repo": repo, "revision": rev, "files": dict(sorted(files.items()))} + + +def main(argv): + if not argv: + print(__doc__) + return 2 + cmd, args = argv[0], argv[1:] + if cmd == "pin": + print(json.dumps(pin(args[0], args[1], args[2:]), indent=1)) + return 0 + m = load(args[0]) + if cmd == "files": + print("\n".join(sorted(m["files"]))) + return 0 + root = args[1] + if cmd == "download": + hf = shlex.split(args[args.index("--hf") + 1]) if "--hf" in args else ["hf"] + r = subprocess.run([*hf, "download", m["repo"], *sorted(m["files"]), "--revision", m["revision"], "--local-dir", root], + stdout=subprocess.DEVNULL) + if r.returncode: + print(f"hf_pinned: hf download {m['repo']}@{m['revision'][:12]} failed ({r.returncode}); run again (it resumes)", file=sys.stderr) + return 1 + elif cmd != "verify": + print(__doc__) + return 2 + bad = verify(m, root, sizes_only="--sizes" in args) + for b in bad: + print(f"hf_pinned: {m['repo']}@{m['revision'][:12]} in {root}: {b}", file=sys.stderr) + if not bad and cmd == "download": + print(f"{m['repo']}@{m['revision'][:12]}: {len(m['files'])} file(s) verified in {root}") + return 1 if bad else 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/install/test_check_hashes.py b/tools/install/test_check_hashes.py new file mode 100644 index 00000000..6e564da2 --- /dev/null +++ b/tools/install/test_check_hashes.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Tests of check_hashes.py on small lock files (standard library only): python3 -I tools/install/test_check_hashes.py""" +import os, subprocess, sys, tempfile + +HERE = os.path.dirname(os.path.abspath(__file__)) +H = "sha256:" + "ab" * 32 +LOCK = '''version = 1 +[[package]] +name = "app" +version = "0.1.0" +source = {{ virtual = "." }} + +[[package]] +name = "torch" +version = "2.13.0+rocm7.2" +source = {{ registry = "https://download.pytorch.org/whl/rocm7.2" }} +wheels = [ + {{ url = "https://example.invalid/torch-2.13.0-cp312-cp312-linux_x86_64.whl"{torch} }}, +] + +[[package]] +name = "numpy" +version = "2.5.4" +source = {{ registry = "https://pypi.org/simple" }} +sdist = {{ url = "https://example.invalid/numpy-2.5.4.tar.gz", hash = "{H}" }} +wheels = [ + {{ url = "https://example.invalid/numpy-2.5.4-cp312-cp312-linux_x86_64.whl", hash = "{H}" }}, +] +''' +fails = 0 +def check(name, cond, got=""): + global fails + print(("PASS " if cond else "FAIL ") + name + ("" if cond else f": {got}")); fails += not cond + +def run(name, text): + d = tempfile.mkdtemp(); f = os.path.join(d, name) + open(f, "w").write(text) + r = subprocess.run([sys.executable, "-I", os.path.join(HERE, "check_hashes.py"), f], capture_output=True, text=True) + return r.returncode, r.stdout + +code, out = run("uv.lock", LOCK.format(torch=f', hash = "{H}"', H=H)) +check("uv.lock: every artifact hashed passes", code == 0, out) +code, out = run("uv.lock", LOCK.format(torch="", H=H)) +check("uv.lock: an unhashed wheel is refused, by name", code == 1 and "torch 2.13.0+rocm7.2" in out and "numpy" not in out, out) +code, out = run("uv.lock", LOCK.format(torch=', hash = "sha256:1234"', H=H)) +check("uv.lock: a malformed sha256 is refused", code == 1 and "torch" in out, out) +code, out = run("uv.lock", LOCK.format(torch=f', hash = "md5:{"ab" * 16}"', H=H)) +check("uv.lock: another digest is refused", code == 1, out) +code, out = run("requirements-x.txt", f"# comment\n--index-url https://pypi.org/simple\nnumpy==2.5.4 \\\n --hash={H} \\\n --hash={H}\n # via app\n") +check("requirements: hashed passes", code == 0, out) +code, out = run("requirements-x.txt", f"numpy==2.5.4 \\\n --hash={H}\ntorch==2.13.0\n") +check("requirements: an unhashed requirement is refused", code == 1 and "torch==2.13.0" in out and "numpy" not in out, out) +r = subprocess.run([sys.executable, "-I", os.path.join(HERE, "check_hashes.py")], capture_output=True, text=True) +check("this checkout's lock files all pass", r.returncode == 0, r.stdout) +print(f"{'FAILED' if fails else 'ok'}: {fails} failure(s)") +sys.exit(1 if fails else 0) diff --git a/tools/install/test_hf_pinned.py b/tools/install/test_hf_pinned.py new file mode 100644 index 00000000..b86bbf55 --- /dev/null +++ b/tools/install/test_hf_pinned.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Tests of hf_pinned.py verify/download with no network (standard library only): python3 -I tools/install/test_hf_pinned.py +A stub `hf` stands in for huggingface_hub's CLI and writes the files it is asked for.""" +import hashlib, json, os, subprocess, sys, tempfile + +HERE = os.path.dirname(os.path.abspath(__file__)) +TOOL = os.path.join(HERE, "hf_pinned.py") +fails = 0 +def check(name, cond, got=""): + global fails + print(("PASS " if cond else "FAIL ") + name + ("" if cond else f": {got}")); fails += not cond + +def run(*args): + r = subprocess.run([sys.executable, "-I", TOOL, *args], capture_output=True, text=True) + return r.returncode, r.stdout + r.stderr + +t = tempfile.mkdtemp() +files = {"a/model.gguf": b"weights" * 1000, "config.json": b"{}"} +m = {"repo": "org/model", "revision": "f" * 40, "files": {k: [len(v), hashlib.sha256(v).hexdigest()] for k, v in files.items()}} +man = os.path.join(t, "pin.json"); json.dump(m, open(man, "w")) +# the stub: `hf download REPO FILES... --revision REV --local-dir DIR`; logs its argv, writes FILES (one corrupted on request) +stub = os.path.join(t, "hf") +open(stub, "w").write(f"""#!{sys.executable} +import json, os, sys +a = sys.argv[1:]; open({os.path.join(t, 'argv')!r}, 'w').write(json.dumps(a)) +d = a[a.index('--local-dir') + 1]; names = a[2:a.index('--revision')] +data = {json.dumps({k: v.decode() for k, v in files.items()})} +for n in names: + os.makedirs(os.path.dirname(os.path.join(d, n)), exist_ok=True) + open(os.path.join(d, n), 'w').write(data[n] if not os.environ.get('CORRUPT') else data[n].upper()) +""") +os.chmod(stub, 0o755) + +d = os.path.join(t, "dl") +code, out = run("download", man, d, "--hf", stub) +argv = json.load(open(os.path.join(t, "argv"))) +check("download asks hf for the pinned revision and only the manifest's files", + argv[:2] == ["download", "org/model"] and argv[argv.index("--revision") + 1] == "f" * 40 and sorted(argv[2:4]) == sorted(files), argv) +check("download verifies what it got", code == 0 and "2 file(s) verified" in out, out) +check("verify: a good tree passes", run("verify", man, d)[0] == 0) +open(os.path.join(d, "config.json"), "w").write("[]") +code, out = run("verify", man, d) +check("verify: same size, other bytes: refused by sha256", code == 1 and "config.json: sha256 differs" in out, out) +check("verify --sizes: the cheap check does not hash", run("verify", man, d, "--sizes")[0] == 0) +os.remove(os.path.join(d, "a/model.gguf")) +code, out = run("verify", man, d, "--sizes") +check("verify --sizes: a missing file is refused", code == 1 and "a/model.gguf: missing" in out, out) +r = subprocess.run([sys.executable, "-I", TOOL, "download", man, os.path.join(t, "bad"), "--hf", stub], capture_output=True, text=True, env={**os.environ, "CORRUPT": "1"}) +check("download: bytes that differ from the pin fail the step", r.returncode == 1 and "sha256 differs" in r.stderr, r.stderr) +json.dump({**m, "revision": "main"}, open(man, "w")) +check("a manifest without a 40-hex revision is refused", run("verify", man, d)[0] != 0) +for p in sorted(os.listdir(os.path.join(HERE, "..", "..", "deploy", "strix-halo", "pins"))) if os.path.isdir(os.path.join(HERE, "..", "..", "deploy", "strix-halo", "pins")) else []: + q = json.load(open(os.path.join(HERE, "..", "..", "deploy", "strix-halo", "pins", p))) + check(f"pins/{p}: a commit and a sha256 for every file", len(q["revision"]) == 40 and all(len(h) == 64 and n > 0 for n, h in q["files"].values()), q["revision"]) +print(f"{'FAILED' if fails else 'ok'}: {fails} failure(s)") +sys.exit(1 if fails else 0) diff --git a/tools/speech/whisper/rocm/README.md b/tools/speech/whisper/rocm/README.md index 136d49dc..26e4f11b 100644 --- a/tools/speech/whisper/rocm/README.md +++ b/tools/speech/whisper/rocm/README.md @@ -2,7 +2,10 @@ The same worker as the Spark (`../worker.py`, `../whisper_core.py`) with a venv locked to PyTorch's ROCm 7.2 wheels (torch 2.13.0+rocm7.2, the release the other workers pin). On ROCm `torch.cuda` is the HIP device, so the tool's -`options.device` stays `"cuda"` (or `"auto"`). +`options.device` stays `"cuda"` (or `"auto"`). PyTorch's index publishes no digest for the torch wheel, so its sha256 +(`2ad8066c…`, 6227849000 bytes, hashed from download-r2.pytorch.org on 2026-11-16) was added to `uv.lock` by hand; +`uv sync --locked` refuses any other bytes, and `tools/install/check_hashes.py` (CI) refuses a lock with an unhashed +artifact. ```sh UV_PROJECT_ENVIRONMENT=$J/venvs/whisper-rocm uv sync --locked --python 3.12 --project tools/speech/whisper/rocm diff --git a/tools/speech/whisper/rocm/uv.lock b/tools/speech/whisper/rocm/uv.lock index 8e339fcc..df30c9d5 100644 --- a/tools/speech/whisper/rocm/uv.lock +++ b/tools/speech/whisper/rocm/uv.lock @@ -381,7 +381,7 @@ dependencies = [ { name = "typing-extensions" }, ] wheels = [ - { url = "https://download-r2.pytorch.org/whl/rocm7.2/torch-2.13.0%2Brocm7.2-cp312-cp312-manylinux_2_28_x86_64.whl", upload-time = "2026-07-08T11:26:11Z" }, + { url = "https://download-r2.pytorch.org/whl/rocm7.2/torch-2.13.0%2Brocm7.2-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:2ad8066cb9d3c00b2dc77ec5af998eed495e7240e724e8c28124d4d5faba52f0", size = 6227849000, upload-time = "2026-07-08T11:26:11Z" }, ] [[package]] From eaca3c0e145869ca773eb90d8915eec55f0ab45d Mon Sep 17 00:00:00 2001 From: smfworks Date: Tue, 17 Nov 2026 07:01:55 -0500 Subject: [PATCH 09/13] openai_audio: the server dies with the worker; seed 0 is forwarded The model's server no longer gets a session of its own (start_new_session): it stays in the worker's process group, so the daemon's SIGKILL of that group on abort or timeout takes it down too, and PR_SET_PDEATHSIG (SIGTERM) covers the worker dying alone. Before, a hard kill left the server, and a Gufo container behind it, holding the GPU. An unload now signals the server and every process below it (/proc children) instead of its group. Seed 0 was dropped by a truthiness check: a request's seed is sent whenever it has one and send_seed is on. Tests: SIGKILL of the worker's group mid-generation, the server is gone (fails on the old worker: the server outlived it); the server receives seed 0; no seed, none sent; send_seed false, none sent. --- tools/speech/openai_audio/README.md | 9 ++-- tools/speech/openai_audio/test_worker.py | 54 +++++++++++++++++++++++- tools/speech/openai_audio/worker.py | 48 ++++++++++++++++----- 3 files changed, 95 insertions(+), 16 deletions(-) diff --git a/tools/speech/openai_audio/README.md b/tools/speech/openai_audio/README.md index ff2b1edf..bcf90d35 100644 --- a/tools/speech/openai_audio/README.md +++ b/tools/speech/openai_audio/README.md @@ -5,13 +5,14 @@ compiled-in `openai_server` engine does for chat. It is Python standard library only, so it runs under the system `python3 -I` with no venv. -- **load**: starts `options.server` (an argv; `{port}`, `{id}` and `{weights}` are filled in) in its own process group - on a loopback port (`options.port`, else a free one) and waits until `options.health` (default `/v1/models`) answers +- **load**: starts `options.server` (an argv; `{port}`, `{id}` and `{weights}` are filled in) in the worker's process group + (so the daemon's SIGKILL of that group on abort or timeout takes the server down too; it also gets SIGTERM if the + worker dies alone, `PR_SET_PDEATHSIG`) on a loopback port (`options.port`, else a free one) and waits until `options.health` (default `/v1/models`) answers 200. Without `options.server` it uses `options.url`, a server you run yourself. - **speech**: asks the server for raw PCM (`response_format: "pcm"`) and writes `speech.wav` as it arrives: a placeholder header, the samples, then the real sizes. With `"stream": true` in the tool's options the daemon forwards the audio as it grows (time to first audio is the server's). The rate is the server's `x-sample-rate` header, else - `options.sample_rate` (24000). Seeds are folded to 32 bits. + `options.sample_rate` (24000). Seeds are folded to 32 bits; seed 0 is sent as 0 (`options.send_seed: false` sends none). - **transcription**: posts `audio.wav` (16 kHz mono, prepared by the daemon) as multipart with the request's `language`, `prompt` and `temperature` as given (never replaced; a server that cannot honour one refuses it, and the caller gets that 400), and writes `transcript.json` (`text`, `language`, `duration`, `segments`, and `words` when the @@ -20,7 +21,7 @@ compiled-in `openai_server` engine does for chat. It is Python standard library `timestamp_granularities[]`, and a reply without them is an error. `word` not listed is refused (400) before the server is asked. `segment` not listed gets the whole clip as one segment (the daemon asks for segments for every `verbose_json`, `srt` and `vtt` reply). Without timestamps it asks for `options.transcription_format` (`json`). -- **exit / unload**: SIGTERM to the server's process group, progress lines while it stops (so the daemon does not load +- **exit / unload**: SIGTERM to the server and every process below it, progress lines while it stops (so the daemon does not load anything into memory that is still held), SIGKILL after `options.stop_timeout_s` (15). - A server 4xx becomes `invalid_request_error` (400), a 503 or an unreachable server `service_unavailable` (503). Voice cloning and references are refused. diff --git a/tools/speech/openai_audio/test_worker.py b/tools/speech/openai_audio/test_worker.py index 7efb7d5d..47acebf9 100644 --- a/tools/speech/openai_audio/test_worker.py +++ b/tools/speech/openai_audio/test_worker.py @@ -4,12 +4,14 @@ The worker starts the fake server itself through options.server (as it starts a real one), speaks the protocol on stdin/stdout, and stops the server on exit. The fake records every transcription request's form fields, so the tests see what the worker forwarded.""" -import json, os, subprocess, sys, tempfile, wave +import json, os, signal, subprocess, sys, tempfile, time, wave HERE = os.path.dirname(os.path.abspath(__file__)) FAKE = r''' import json, re, sys, http.server +import os, time port, record = int(sys.argv[1]), sys.argv[2] +open(record + ".pid", "w").write(str(os.getpid())) def fields(body, ctype): bound = ctype.split("boundary=")[1].encode() out = [] @@ -33,6 +35,10 @@ def do_POST(self): body = self.rfile.read(int(self.headers["Content-Length"])) if self.path == "/v1/audio/speech": req = json.loads(body) + with open(record + ".speech", "a") as r: + r.write(json.dumps(req) + "\n") + if req.get("voice") == "slow": + time.sleep(60) # a generation the worker is killed in if req.get("seed", 0) > 0xFFFFFFFF or req.get("voice") == "bad": return self.reply(400, {"error": {"message": "bad"}}) pcm = b"\x01\x00" * 2400 + b"\x02" # 0.1 s at 24 kHz plus one stray byte, sent chunked @@ -74,8 +80,9 @@ def __init__(self, tmp, name, **opts): self.record = os.path.join(tmp, name + ".jsonl") fake = os.path.join(tmp, "fake.py") cfg = {"id": "fake-audio", "load_timeout_s": 20, "options": {"server": [sys.executable, "-I", fake, "{port}", self.record], **opts}} + # its own process group, as the daemon starts a worker (spawn with pgid 0) self.p = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "worker.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, - env={**os.environ, "LOCALROUTER_TOOL": json.dumps(cfg)}, text=True) + env={**os.environ, "LOCALROUTER_TOOL": json.dumps(cfg)}, text=True, process_group=0) def call(self, obj): self.p.stdin.write(json.dumps(obj) + "\n"); self.p.stdin.flush() while True: @@ -84,6 +91,11 @@ def call(self, obj): def sent(self): """The form fields of the transcription requests the server got, oldest first ([[name, value], ...] each).""" return [json.loads(l) for l in open(self.record)] if os.path.exists(self.record) else [] + def speech_sent(self): + p = self.record + ".speech" + return [json.loads(l) for l in open(p)] if os.path.exists(p) else [] + def server_pid(self): + return int(open(self.record + ".pid").read()) def exit(self): self.p.stdin.write(json.dumps({"op": "exit"}) + "\n"); self.p.stdin.flush() return self.p.wait(timeout=30) @@ -95,6 +107,15 @@ def transcribe(w, job, n, **q): return r, t +def alive(pid): + """Running (not a zombie: a killed server is reaped by init, or shows Z until it is).""" + try: + with open(f"/proc/{pid}/stat") as f: + return f.read().rsplit(")", 1)[1].split()[0] != "Z" + except OSError: + return False + + def field(sent, name): return [v for k, v in sent if k == name] @@ -113,6 +134,11 @@ def main(): with wave.open(os.path.join(job, "speech.wav")) as f: check("speech.wav: 24 kHz mono 16-bit, whole samples", (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes()) == (24000, 1, 2, 2400), (f.getframerate(), f.getnchannels(), f.getsampwidth(), f.getnframes())) + check("the seed folded to 32 bits reaches the server", w.speech_sent()[-1].get("seed") == 5, w.speech_sent()[-1:]) + r = w.call({"op": "generate", "id": "s0", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v", "seed": 0}}}) + check("seed 0 is forwarded, not dropped", r.get("ok") is True and w.speech_sent()[-1].get("seed") == 0, (r, w.speech_sent()[-1:])) + r = w.call({"op": "generate", "id": "s00", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v"}}}) + check("no seed: none sent", "seed" not in w.speech_sent()[-1], w.speech_sent()[-1:]) r = w.call({"op": "generate", "id": "s2", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "bad"}}}) check("server 4xx is an invalid_request_error", r.get("type") == "invalid_request_error", r) r = w.call({"op": "generate", "id": "s3", "dir": job, "request": {"speech": {"input": " "}}}) @@ -161,6 +187,30 @@ def main(): r, t = transcribe(w, job, 14, timestamps="segment", prompt="nothing") check("segment, declared, none returned: a server error", r.get("ok") is False and r.get("type") == "server_error", r) check("exit 0 (timestamps worker)", w.exit() == 0) + + # seed 0 with send_seed off: nothing sent + w = W(tmp, "noseed", send_seed=False) + r = w.call({"op": "generate", "id": "n1", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "v", "seed": 0}}}) + check("send_seed false: no seed sent", r.get("ok") is True and "seed" not in w.speech_sent()[-1], (r, w.speech_sent()[-1:])) + check("exit 0 (send_seed false)", w.exit() == 0) + + # the daemon's abort or timeout: SIGKILL to the worker's group mid-generation; the server must not outlive it + w = W(tmp, "killed") + check("load (kill test)", w.call({"op": "load"}).get("ok") is True) + w.p.stdin.write(json.dumps({"op": "generate", "id": "k1", "dir": job, "request": {"speech": {"input": "Hi.", "voice": "slow"}}}) + "\n"); w.p.stdin.flush() + t = time.monotonic() + while not w.speech_sent() and time.monotonic() - t < 10: + time.sleep(0.05) + server = w.server_pid() + check("the server is generating when the worker is killed", len(w.speech_sent()) == 1 and alive(server)) + os.killpg(w.p.pid, signal.SIGKILL) + w.p.wait(timeout=10) + t = time.monotonic() + while alive(server) and time.monotonic() - t < 10: + time.sleep(0.05) + check("SIGKILL of the worker's group mid-generation: the server is gone too", not alive(server)) + if alive(server): + os.kill(server, signal.SIGKILL) print(f"{'FAILED' if fails else 'ok'}: {fails} failure(s)") sys.exit(1 if fails else 0) diff --git a/tools/speech/openai_audio/worker.py b/tools/speech/openai_audio/worker.py index acf2b288..a1a5088c 100644 --- a/tools/speech/openai_audio/worker.py +++ b/tools/speech/openai_audio/worker.py @@ -24,6 +24,8 @@ timestamps the timestamp_granularities the server returns: [] (default), ["segment"], ["segment", "word"]. A request for a granularity listed here asks for verbose_json with it; "word" not listed is refused stop_timeout_s seconds between SIGTERM and SIGKILL when stopping the server (default 15) +The server runs in the worker's process group and gets SIGTERM if the worker dies: the daemon's SIGKILL of the group +(abort, timeout) takes it down too. An unload stops the server and what it started, then the worker exits. Memory is the config's resident_bytes and working_bytes: measured figures, not guessed here. """ import ctypes @@ -74,6 +76,36 @@ def die_with_parent(): pass +def server_preexec(): + """In the server's process, before exec: SIGTERM when this worker dies by any means (PR_SET_PDEATHSIG). The server + also stays in the worker's process group (no new session), so the daemon's SIGKILL of that group on abort or + timeout takes it down with the worker; this covers the worker dying alone.""" + die_with_parent() + + +def tree(pid): + """`pid` and every process below it (Linux: /proc/PID/task/TID/children), parents first.""" + out, todo = [], [pid] + while todo: + p = todo.pop(0) + out.append(p) + try: + for t in os.listdir(f"/proc/{p}/task"): + with open(f"/proc/{p}/task/{t}/children") as f: + todo += [int(c) for c in f.read().split()] + except (OSError, ValueError): + pass + return out + + +def signal_tree(pids, sig): + for p in pids: + try: + os.kill(p, sig) + except ProcessLookupError: + pass + + _pending = bytearray() @@ -143,8 +175,9 @@ def load(self): env = dict(os.environ) env.update({k: sub(str(v)) for k, v in (self.opts.get("env") or {}).items()}) log(f"starting {argv[0]} on 127.0.0.1:{port}") + # in this worker's process group (the daemon kills the group on abort or timeout), dying with the worker self.proc = subprocess.Popen(argv, env=env, stdin=subprocess.DEVNULL, stdout=sys.stderr, stderr=sys.stderr, - start_new_session=True) + preexec_fn=server_preexec) self.base = f"http://127.0.0.1:{port}" else: self.base = (self.opts.get("url") or "").rstrip("/") @@ -167,20 +200,15 @@ def stop(self): p, self.proc = self.proc, None if p is None or p.poll() is not None: return - try: - os.killpg(p.pid, signal.SIGTERM) - except ProcessLookupError: - return + # the server and what it started (not the group: that is this worker's too) + signal_tree(tree(p.pid), signal.SIGTERM) deadline = time.monotonic() + float(self.opts.get("stop_timeout_s") or 15) while p.poll() is None and time.monotonic() < deadline: send({"progress": {"phase": "unload", "step": 0, "of": 1}}) # the daemon waits while memory is still held time.sleep(0.5) if p.poll() is None: log("server ignored SIGTERM; killing it") - try: - os.killpg(p.pid, signal.SIGKILL) - except ProcessLookupError: - pass + signal_tree(tree(p.pid), signal.SIGKILL) p.wait() def ensure(self): @@ -232,7 +260,7 @@ def speech(self, s, job_dir, timeout): if s.get("speed") not in (None, 0, 1, 1.0): body["speed"] = s["speed"] seed = int(s.get("seed") or 0) - if self.opts.get("send_seed", True) and seed: + if self.opts.get("send_seed", True) and s.get("seed") is not None: # 0 is a seed too body["seed"] = seed & 0xFFFFFFFF # the daemon's seeds are 64-bit; servers commonly take a uint32 r = self.post("/v1/audio/speech", json.dumps(body).encode(), "application/json", timeout) rate = int(r.headers.get("x-sample-rate") or self.opts.get("sample_rate") or 24000) From 67493a6dd5ba15a081371b0dc2c9fd95ca32b6ea Mon Sep 17 00:00:00 2001 From: smfworks Date: Tue, 17 Nov 2026 07:04:54 -0500 Subject: [PATCH 10/13] gufo: a hard kill of serve.sh's group removes its container With the openai_audio worker's server now in the worker's process group, the daemon's SIGKILL of that group (abort, timeout) kills serve.sh and the podman client, but not the container: conmon runs it outside the group, and the SIGTERM trap never runs. serve.sh starts a watcher in its own session that removes this run's container, by its --cidfile id (never a later run's of the same name), once the script is gone. test_serve.sh (8 checks, stub podman whose container is outside the group): SIGKILL of the group removes the container, by id, and the watcher cleans up; SIGTERM still stops it through the trap; a run started right after a killed one keeps its container. 3 of them fail on the old serve.sh. CI runs it. --- .github/workflows/ci.yml | 2 ++ tools/gufo/README.md | 6 ++++- tools/gufo/serve.sh | 13 +++++++--- tools/gufo/test_serve.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100755 tools/gufo/test_serve.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a190c84c..530fa3fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,8 @@ jobs: python3 -I tools/install/test_hf_pinned.py - name: the Strix Halo unit passes the pinned Gufo image to its workers (no GPU, stub systemd-run and podman) run: bash deploy/strix-halo/test_start.sh + - name: a hard kill of serve.sh's process group removes its Gufo container (stub podman; no GPU) + run: bash tools/gufo/test_serve.sh - run: zig build - run: zig build test timeout-minutes: 20 diff --git a/tools/gufo/README.md b/tools/gufo/README.md index 412d3e6d..c0e2909f 100644 --- a/tools/gufo/README.md +++ b/tools/gufo/README.md @@ -8,7 +8,11 @@ supervise it: the `openai_server` engine for chat, `tools/speech/openai_audio` f - The container is `lr-gufo-NAME`, published on `127.0.0.1:PORT` only; `--host 0.0.0.0 --port 8080` are added after `serve` inside the container. - SIGTERM or SIGINT (the worker unloading) runs `podman stop` and waits, so the GPU memory is free when the script exits. - `--replace` removes a container left by a worker that was killed outright; `deploy/strix-halo/stop.sh` also stops any + A SIGKILL of the worker's process group (the daemon's, on abort or timeout) skips that trap, and conmon keeps the + container running outside the group, so a watcher in its own session removes this run's container (by its + `--cidfile` id, never a later run's of the same name) once the script is gone (`test_serve.sh`, stub podman; checked + with real rootless Podman on the Strix Halo box: removed within the stop timeout). + `--replace` removes a container left by anything else; `deploy/strix-halo/stop.sh` also stops any `lr-gufo-*` left over. - `/dev/kfd` and `/dev/dri` are passed with the `video` and `render` groups by name: Gufo's docs use `--group-add keep-groups`, which needs the crun runtime, and many hosts run runc. diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh index b277717a..50b5121d 100755 --- a/tools/gufo/serve.sh +++ b/tools/gufo/serve.sh @@ -3,8 +3,10 @@ # foreground, for LocalRouter's `openai_server` engine and the openai_audio `cmd` worker: # tools/gufo/serve.sh NAME PORT [podman options...] -- gufo serve ... [--port 8080 is added] # The container listens on 127.0.0.1:PORT only. SIGTERM/SIGINT (the daemon unloading the tool) stops the container and -# waits until it is gone, so its GPU memory is free before this script exits. `--replace` clears a container left over -# from a worker that was killed outright. +# waits until it is gone, so its GPU memory is free before this script exits. A SIGKILL of this script's process group +# (the daemon's, on abort or timeout: the trap never runs, and conmon keeps the container going outside the group) is +# covered by a watcher in its own session, which removes this run's container (by id) once the script is gone. +# `--replace` clears a container left over from anything else. # Environment: GUFO_IMAGE (default: tools/gufo/IMAGE, the runtime pinned by digest), GUFO_STOP_TIMEOUT (default 10 s). # An image named without @sha256: is refused unless GUFO_ALLOW_UNPINNED=1: a tag can move between two installs. # Devices: /dev/kfd and /dev/dri; the video and render groups are passed by name, since keep-groups needs crun and @@ -26,7 +28,12 @@ trap stop TERM INT # "gufo serve [global opts] KIND ...": insert host/port right after "serve" args=(); placed=0 for a in "$@"; do args+=("$a"); if [ $placed = 0 ] && [ "$a" = serve ]; then args+=(--host 0.0.0.0 --port 8080); placed=1; fi; done -podman run --rm --replace --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ +run_dir=$(mktemp -d "${TMPDIR:-/tmp}/lr-gufo-$name.XXXXXX") +# the watcher: polls this script; when it is gone, removes the container this run made (not a later run's of the name) +setsid -f sh -c 'while kill -0 "$1" 2> /dev/null; do sleep 0.5; done + [ -s "$2/cid" ] && podman rm -f -t "$3" "$(cat "$2/cid")" > /dev/null 2>&1; rm -rf "$2"' \ + gufo-watch "$$" "$run_dir" "${GUFO_STOP_TIMEOUT:-10}" < /dev/null > /dev/null 2>&1 +podman run --rm --replace --cidfile "$run_dir/cid" --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ --device /dev/kfd --device /dev/dri --group-add video --group-add render --ulimit memlock=-1 \ -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & pid=$! diff --git a/tools/gufo/test_serve.sh b/tools/gufo/test_serve.sh new file mode 100755 index 00000000..a572fa95 --- /dev/null +++ b/tools/gufo/test_serve.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# serve.sh without a GPU: a stub podman whose "container" runs outside the caller's process group, as conmon's does. +# A SIGKILL of serve.sh's group (the daemon's, on abort or timeout) must not leave the container running; SIGTERM +# stops it through the trap; a later run of the same name is not removed by an earlier run's watcher. +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd) +t=$(mktemp -d); trap 'pkill -KILL -f "stub-container $t" 2> /dev/null; rm -rf "$t"' EXIT +pass=0 fail=0 +check() { if eval "$2"; then pass=$((pass + 1)); else fail=$((fail + 1)); echo "FAIL: $1" >&2; fi; } +mkdir -p "$t/bin" "$t/state" +cat > "$t/bin/podman" < /dev/null 2>&1 & + echo \$! > "\$S/\$cid"; echo "\$cid" > "\$S/name-\$name"; echo "\$cid" > "\$cidfile" + wait ;; # the client waits; it dies with the group, the container does not + stop) for a in "\$@"; do f=\$S/\$(cat "\$S/name-\$a" 2> /dev/null); [ -f "\$f" ] && kill "\$(cat "\$f")" 2> /dev/null; done; exit 0 ;; + rm) shift; for a in "\$@"; do [ -f "\$S/\$a" ] && kill "\$(cat "\$S/\$a")" 2> /dev/null; echo "\$a" >> "\$S/removed"; done; exit 0 ;; +esac +STUB +chmod +x "$t/bin/podman" +export PATH="$t/bin:$PATH" GUFO_IMAGE="x@sha256:$(printf '0%.0s' {1..64})" GUFO_STOP_TIMEOUT=1 TMPDIR="$t" +container() { local c; c=$(cat "$t/state/name-lr-gufo-$1" 2> /dev/null) && cat "$t/state/$c" 2> /dev/null; } +alive() { [ -n "$1" ] && kill -0 "$1" 2> /dev/null; } +start() { setsid bash "$here/serve.sh" "$1" 18080 -- gufo serve llm > /dev/null 2>&1 & echo $!; } # its own group, as a worker's +waitfor() { local i; for i in $(seq 100); do eval "$1" && return 0; sleep 0.1; done; return 1; } + +# a hard kill of the group: the container goes too +s=$(start a); waitfor '[ -n "$(container a)" ]'; c=$(container a) +check "the container runs" 'alive "$c"' +kill -KILL -- "-$s" +check "SIGKILL of serve.sh's group: the container is removed" 'waitfor "! alive $c"' +check "by its id" 'grep -q "$(cat "$t/state/name-lr-gufo-a")" "$t/state/removed"' +check "the watcher cleans up after itself" 'waitfor "[ -z \"\$(ls -d "$t"/lr-gufo-a.* 2> /dev/null)\" ]"' + +# SIGTERM (an unload): the trap stops the container and the script exits +s=$(start b); waitfor '[ -n "$(container b)" ]'; c=$(container b) +kill -TERM "$s" +check "SIGTERM: the container stops" 'waitfor "! alive $c"' +check "SIGTERM: serve.sh exits" 'waitfor "! alive $s"' + +# a run killed, then the same name started at once: the first run's watcher leaves the new container alone +s=$(start c); waitfor '[ -n "$(container c)" ]'; c1=$(container c) +kill -KILL -- "-$s"; s2=$(start c); waitfor '[ "$(container c)" != "$c1" ] && [ -n "$(container c)" ]'; c2=$(container c) +check "the first container is removed" 'waitfor "! alive $c1"' +sleep 1.5 +check "the second is not" 'alive "$c2"' +kill -KILL -- "-$s2"; waitfor "! alive $c2" + +echo "gufo serve.sh: $pass passed, $fail failed" +[ "$fail" -eq 0 ] From 279fd409c075ff01905f3bdfa3d53d128c22e09f Mon Sep 17 00:00:00 2001 From: smfworks Date: Tue, 17 Nov 2026 15:51:11 -0500 Subject: [PATCH 11/13] gufo: the container's logs use the host zone serve.sh passes the host zone into the Gufo container ($TZ, else /etc/timezone, else the /etc/localtime link; anything but a zone name falls back to UTC). The image has no zone database, so TZ alone leaves its logs on UTC: when the host has /usr/share/zoneinfo, it is mounted read-only (GUFO_ZONEINFO overrides the host path). --- tools/gufo/README.md | 4 +++- tools/gufo/serve.sh | 28 ++++++++++++++++++++++++++-- tools/gufo/test_serve.sh | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/tools/gufo/README.md b/tools/gufo/README.md index c0e2909f..69884d53 100644 --- a/tools/gufo/README.md +++ b/tools/gufo/README.md @@ -6,7 +6,9 @@ and 27B, Qwen3-TTS, Qwen3-ASR, Qwen-Image, MiniMax H3 and more behind OpenAI-com supervise it: the `openai_server` engine for chat, `tools/speech/openai_audio` for speech and transcription. - The container is `lr-gufo-NAME`, published on `127.0.0.1:PORT` only; `--host 0.0.0.0 --port 8080` are added after - `serve` inside the container. + `serve` inside the container. `TZ` is the host's zone (`$TZ`, else `/etc/timezone`, else the `/etc/localtime` + link). The image has no zoneinfo, so when the host has `/usr/share/zoneinfo` it is mounted read-only there; + otherwise the container stays on UTC. - SIGTERM or SIGINT (the worker unloading) runs `podman stop` and waits, so the GPU memory is free when the script exits. A SIGKILL of the worker's process group (the daemon's, on abort or timeout) skips that trap, and conmon keeps the container running outside the group, so a watcher in its own session removes this run's container (by its diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh index 50b5121d..03b844b0 100755 --- a/tools/gufo/serve.sh +++ b/tools/gufo/serve.sh @@ -7,7 +7,9 @@ # (the daemon's, on abort or timeout: the trap never runs, and conmon keeps the container going outside the group) is # covered by a watcher in its own session, which removes this run's container (by id) once the script is gone. # `--replace` clears a container left over from anything else. -# Environment: GUFO_IMAGE (default: tools/gufo/IMAGE, the runtime pinned by digest), GUFO_STOP_TIMEOUT (default 10 s). +# Environment: GUFO_IMAGE (default: tools/gufo/IMAGE, the runtime pinned by digest), GUFO_STOP_TIMEOUT (default 10 s), +# TZ (the host zone passed into the container; unset: read from the host). The image has no zoneinfo of its own, so +# when the host has one it is mounted read-only at /usr/share/zoneinfo (GUFO_ZONEINFO overrides that host path). # An image named without @sha256: is refused unless GUFO_ALLOW_UNPINNED=1: a tag can move between two installs. # Devices: /dev/kfd and /dev/dri; the video and render groups are passed by name, since keep-groups needs crun and # many hosts run runc. @@ -22,6 +24,28 @@ case $image in *@sha256:????????????????????????????????????????????????????????????????) ;; *) [ "${GUFO_ALLOW_UNPINNED:-0}" = 1 ] || { echo "serve.sh: GUFO_IMAGE '$image' is not pinned by digest (name@sha256:...); GUFO_ALLOW_UNPINNED=1 runs it anyway" >&2; exit 2; } ;; esac +# A zone name only (Area/City, UTC, ...): the container's clock matches the host's, and a value with a newline or a +# shell metacharacter cannot become another podman argument. +host_tz() { + local tz="${TZ:-}" + if [ -z "$tz" ] && [ -r /etc/timezone ]; then tz=$(tr -d ' \t\r\n' < /etc/timezone); fi + if [ -z "$tz" ]; then + local link + link=$(readlink /etc/localtime 2> /dev/null || true) + case $link in + */zoneinfo/*) tz=${link#*/zoneinfo/} ;; + esac + fi + case ${tz:-UTC} in + *[!A-Za-z0-9_+/-]*) printf '%s' UTC ;; + *) printf '%s' "${tz:-UTC}" ;; + esac +} +tz=$(host_tz) +# TZ alone leaves the container on UTC: the image ships neither /usr/share/zoneinfo nor /etc/localtime. +zoneinfo=${GUFO_ZONEINFO:-/usr/share/zoneinfo} +zi=() +if [ -d "$zoneinfo" ]; then zi=(-v "${zoneinfo}:/usr/share/zoneinfo:ro"); fi cname="lr-gufo-$name" stop() { podman stop -t "${GUFO_STOP_TIMEOUT:-10}" "$cname" > /dev/null 2>&1 || true; wait "$pid" 2> /dev/null || true; exit 0; } trap stop TERM INT @@ -35,6 +59,6 @@ setsid -f sh -c 'while kill -0 "$1" 2> /dev/null; do sleep 0.5; done gufo-watch "$$" "$run_dir" "${GUFO_STOP_TIMEOUT:-10}" < /dev/null > /dev/null 2>&1 podman run --rm --replace --cidfile "$run_dir/cid" --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ --device /dev/kfd --device /dev/dri --group-add video --group-add render --ulimit memlock=-1 \ - -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & + -e "TZ=$tz" ${zi[@]+"${zi[@]}"} -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & pid=$! wait "$pid" diff --git a/tools/gufo/test_serve.sh b/tools/gufo/test_serve.sh index a572fa95..4488f36a 100755 --- a/tools/gufo/test_serve.sh +++ b/tools/gufo/test_serve.sh @@ -14,7 +14,9 @@ cat > "$t/bin/podman" < "\$S/last-args" + cid=\$(date +%s%N); name=; cidfile= while [ \$# -gt 0 ]; do case "\$1" in --cidfile) cidfile=\$2; shift ;; --name) name=\$2; shift ;; esac; shift; done setsid bash -c 'exec -a "stub-container $t \$0" sleep 300' "\$cid" < /dev/null > /dev/null 2>&1 & echo \$! > "\$S/\$cid"; echo "\$cid" > "\$S/name-\$name"; echo "\$cid" > "\$cidfile" @@ -52,5 +54,34 @@ sleep 1.5 check "the second is not" 'alive "$c2"' kill -KILL -- "-$s2"; waitfor "! alive $c2" +# the host zone is an argument of podman run, so container logs use the host clock +export TZ=Europe/Helsinki +s=$(start tz); waitfor '[ -n "$(container tz)" ]' +check "podman run receives the host TZ" 'grep -qx "TZ=Europe/Helsinki" "$t/state/last-args"' +if [ -d /usr/share/zoneinfo ]; then + check "the host zoneinfo is mounted read-only" 'grep -qx "/usr/share/zoneinfo:/usr/share/zoneinfo:ro" "$t/state/last-args"' +fi +kill -KILL -- "-$s"; waitfor '! alive "$(container tz)"' + +# TZ cannot resolve without the zone database. A directory that exists is mounted; one that does not is left off. +mkdir -p "$t/zoneinfo" +export GUFO_ZONEINFO="$t/zoneinfo" +rm -f "$t/state/last-args" +s=$(start zi); waitfor '[ -n "$(container zi)" ]' +check "a present zoneinfo directory is mounted read-only" "grep -qx '$t/zoneinfo:/usr/share/zoneinfo:ro' '$t/state/last-args'" +kill -KILL -- "-$s"; waitfor '! alive "$(container zi)"' +export GUFO_ZONEINFO="$t/no-such-zoneinfo" +rm -f "$t/state/last-args" +s=$(start zn); waitfor '[ -n "$(container zn)" ]' +check "a missing zoneinfo directory is not mounted" '! grep -q zoneinfo "$t/state/last-args"' +kill -KILL -- "-$s"; waitfor '! alive "$(container zn)"' +unset GUFO_ZONEINFO + +rm -f "$t/state/last-args" +unset TZ +s=$(start zu); waitfor 'grep -q "^TZ=" "$t/state/last-args" 2>/dev/null' +check "without TZ, a zone name is still passed" 'grep -Eq "^TZ=[A-Za-z0-9_+/-]+$" "$t/state/last-args"' +kill -KILL -- "-$s"; waitfor '! alive "$s"' + echo "gufo serve.sh: $pass passed, $fail failed" [ "$fail" -eq 0 ] From f51e46956c3405669d77ab9e648f25f6b860e124 Mon Sep 17 00:00:00 2001 From: smfworks Date: Wed, 18 Nov 2026 10:51:59 -0500 Subject: [PATCH 12/13] gufo: the container logs nowhere but the tool's log serve.sh runs podman attached, so the container's output already reaches the daemon, which copies it into the tool's log. On a systemd host podman's default log driver (journald) also wrote every line to the journal, stderr at priority 3: each worker message showed twice, and as an error. --log-driver=none keeps the attached output and drops the journal copy. A --log-driver passed to serve.sh comes later and wins. Checked on a Strix Halo host: with the default driver an attached container's stderr line lands in the journal at priority 3 and is printed; with --log-driver=none it is printed and the journal has none. --- tools/gufo/serve.sh | 7 ++++++- tools/gufo/test_serve.sh | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh index 03b844b0..366385cc 100755 --- a/tools/gufo/serve.sh +++ b/tools/gufo/serve.sh @@ -13,6 +13,11 @@ # An image named without @sha256: is refused unless GUFO_ALLOW_UNPINNED=1: a tag can move between two installs. # Devices: /dev/kfd and /dev/dri; the video and render groups are passed by name, since keep-groups needs crun and # many hosts run runc. +# Logs: the container's output reaches the daemon through this script's stdout and stderr, which it copies into the +# tool's log. podman's default log driver on a systemd host (journald) also wrote every line to the journal, stderr at +# priority 3, so each worker message appeared twice and as an error. --log-driver=none keeps the attached output and +# drops the journal copy (`podman logs` then has nothing; the tool's log has it all). A --log-driver among the podman +# options given to this script comes later on the command line and wins. set -euo pipefail name=${1:?usage: serve.sh NAME PORT [podman options...] -- gufo serve ...}; port=${2:?port}; shift 2 popts=() @@ -59,6 +64,6 @@ setsid -f sh -c 'while kill -0 "$1" 2> /dev/null; do sleep 0.5; done gufo-watch "$$" "$run_dir" "${GUFO_STOP_TIMEOUT:-10}" < /dev/null > /dev/null 2>&1 podman run --rm --replace --cidfile "$run_dir/cid" --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ --device /dev/kfd --device /dev/dri --group-add video --group-add render --ulimit memlock=-1 \ - -e "TZ=$tz" ${zi[@]+"${zi[@]}"} -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & + --log-driver=none -e "TZ=$tz" ${zi[@]+"${zi[@]}"} -p "127.0.0.1:$port:8080" ${popts[@]+"${popts[@]}"} "$image" "${args[@]}" & pid=$! wait "$pid" diff --git a/tools/gufo/test_serve.sh b/tools/gufo/test_serve.sh index 4488f36a..486c1e77 100755 --- a/tools/gufo/test_serve.sh +++ b/tools/gufo/test_serve.sh @@ -29,7 +29,7 @@ chmod +x "$t/bin/podman" export PATH="$t/bin:$PATH" GUFO_IMAGE="x@sha256:$(printf '0%.0s' {1..64})" GUFO_STOP_TIMEOUT=1 TMPDIR="$t" container() { local c; c=$(cat "$t/state/name-lr-gufo-$1" 2> /dev/null) && cat "$t/state/$c" 2> /dev/null; } alive() { [ -n "$1" ] && kill -0 "$1" 2> /dev/null; } -start() { setsid bash "$here/serve.sh" "$1" 18080 -- gufo serve llm > /dev/null 2>&1 & echo $!; } # its own group, as a worker's +start() { local name=$1; shift; setsid bash "$here/serve.sh" "$name" 18080 "$@" -- gufo serve llm > /dev/null 2>&1 & echo $!; } # its own group, as a worker's waitfor() { local i; for i in $(seq 100); do eval "$1" && return 0; sleep 0.1; done; return 1; } # a hard kill of the group: the container goes too @@ -83,5 +83,15 @@ s=$(start zu); waitfor 'grep -q "^TZ=" "$t/state/last-args" 2>/dev/null' check "without TZ, a zone name is still passed" 'grep -Eq "^TZ=[A-Za-z0-9_+/-]+$" "$t/state/last-args"' kill -KILL -- "-$s"; waitfor '! alive "$s"' +# the container's output goes to the attached stdout/stderr only: no journald copy at error priority +rm -f "$t/state/last-args" +s=$(start ld); waitfor '[ -s "$t/state/last-args" ]' +check "podman run gets --log-driver=none" 'grep -qx -- "--log-driver=none" "$t/state/last-args"' +kill -KILL -- "-$s"; waitfor '! alive "$s"' +rm -f "$t/state/last-args" +s=$(start lo --log-driver=k8s-file); waitfor '[ -s "$t/state/last-args" ]' +check "a caller's --log-driver comes after it, so it wins" '[ "$(grep -n -- "^--log-driver" "$t/state/last-args" | tail -1 | cut -d: -f2)" = "--log-driver=k8s-file" ]' +kill -KILL -- "-$s"; waitfor '! alive "$s"' + echo "gufo serve.sh: $pass passed, $fail failed" [ "$fail" -eq 0 ] From 555c77c2ec5c1e8d699c8de723172a96bf710cce Mon Sep 17 00:00:00 2001 From: smfworks Date: Wed, 18 Nov 2026 19:22:25 -0500 Subject: [PATCH 13/13] gufo: the watcher treats a zombie serve.sh as gone, so a slow reaper cannot keep the container The watcher polled serve.sh with kill -0, which succeeds on a zombie. If a subreaper left serve.sh unreaped after a SIGKILL of the worker's group, the container kept running until the reap. The watcher now reads the State: line in /proc//status and stops waiting on Z (or X); kill -0 remains only where /proc is not mounted. test_serve.sh: a parent that does not reap serve.sh for 60 s; after the group SIGKILL serve.sh is a zombie and the container must be removed (by its id) while it still is. 3 new checks; the old watcher fails 2 of them. --- tools/gufo/serve.sh | 15 ++++++++++++--- tools/gufo/test_serve.sh | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/tools/gufo/serve.sh b/tools/gufo/serve.sh index 50b5121d..1905df60 100755 --- a/tools/gufo/serve.sh +++ b/tools/gufo/serve.sh @@ -5,7 +5,8 @@ # The container listens on 127.0.0.1:PORT only. SIGTERM/SIGINT (the daemon unloading the tool) stops the container and # waits until it is gone, so its GPU memory is free before this script exits. A SIGKILL of this script's process group # (the daemon's, on abort or timeout: the trap never runs, and conmon keeps the container going outside the group) is -# covered by a watcher in its own session, which removes this run's container (by id) once the script is gone. +# covered by a watcher in its own session, which removes this run's container (by id) once the script is gone: exited, +# or a zombie its parent has not reaped yet. # `--replace` clears a container left over from anything else. # Environment: GUFO_IMAGE (default: tools/gufo/IMAGE, the runtime pinned by digest), GUFO_STOP_TIMEOUT (default 10 s). # An image named without @sha256: is refused unless GUFO_ALLOW_UNPINNED=1: a tag can move between two installs. @@ -29,8 +30,16 @@ trap stop TERM INT args=(); placed=0 for a in "$@"; do args+=("$a"); if [ $placed = 0 ] && [ "$a" = serve ]; then args+=(--host 0.0.0.0 --port 8080); placed=1; fi; done run_dir=$(mktemp -d "${TMPDIR:-/tmp}/lr-gufo-$name.XXXXXX") -# the watcher: polls this script; when it is gone, removes the container this run made (not a later run's of the name) -setsid -f sh -c 'while kill -0 "$1" 2> /dev/null; do sleep 0.5; done +# the watcher: polls this script; when it is gone, removes the container this run made (not a later run's of the name). +# A zombie counts as gone: `kill -0` succeeds on one, so a parent that is slow to reap this script (a subreaper) kept the +# container running after a group SIGKILL. Where /proc is mounted the watcher reads the State: line instead. +setsid -f sh -c 'running() { + if [ -d /proc/self ]; then + st=$(sed -n "s/^State:[[:space:]]*\([A-Za-z]\).*/\1/p" "/proc/$1/status" 2> /dev/null) + [ -n "$st" ] && [ "$st" != Z ] && [ "$st" != X ] + else kill -0 "$1" 2> /dev/null; fi + } + while running "$1"; do sleep 0.5; done [ -s "$2/cid" ] && podman rm -f -t "$3" "$(cat "$2/cid")" > /dev/null 2>&1; rm -rf "$2"' \ gufo-watch "$$" "$run_dir" "${GUFO_STOP_TIMEOUT:-10}" < /dev/null > /dev/null 2>&1 podman run --rm --replace --cidfile "$run_dir/cid" --name "$cname" --userns=keep-id:uid="$(id -u)",gid="$(id -g)" \ diff --git a/tools/gufo/test_serve.sh b/tools/gufo/test_serve.sh index a572fa95..d3a943c3 100755 --- a/tools/gufo/test_serve.sh +++ b/tools/gufo/test_serve.sh @@ -52,5 +52,29 @@ sleep 1.5 check "the second is not" 'alive "$c2"' kill -KILL -- "-$s2"; waitfor "! alive $c2" +# a parent slow to reap (a subreaper): after the group SIGKILL serve.sh stays a zombie, and the container must still go +cat > "$t/holder.py" <<'PY' +import os, sys, time +serve, name, pidfile = sys.argv[1:4] +pid = os.fork() +if pid == 0: + os.setsid() # its own group, as a worker's; this parent is outside it and survives the group kill + fd = os.open(os.devnull, os.O_RDWR) + for n in (0, 1, 2): + os.dup2(fd, n) + os.execvp("bash", ["bash", serve, name, "18080", "--", "gufo", "serve", "llm"]) +open(pidfile, "w").write(str(pid)) +time.sleep(60) # does not reap the child until then +os.waitpid(pid, 0) +PY +state() { sed -n 's/^State:[[:space:]]*\([A-Za-z]\).*/\1/p' "/proc/$1/status" 2> /dev/null; } +python3 "$t/holder.py" "$here/serve.sh" d "$t/d.pid" & h=$! +waitfor '[ -s "$t/d.pid" ] && [ -n "$(container d)" ]'; s=$(cat "$t/d.pid"); c=$(container d) +kill -KILL -- "-$s" +check "an unreaped serve.sh is a zombie" 'waitfor "[ \"\$(state $s)\" = Z ]"' +check "a zombie serve.sh: the container is removed before it is reaped" 'waitfor "! alive $c" && [ "$(state "$s")" = Z ]' +check "by its id, while unreaped" 'grep -q "$(cat "$t/state/name-lr-gufo-d")" "$t/state/removed"' +kill -KILL "$h" 2> /dev/null; wait "$h" 2> /dev/null + echo "gufo serve.sh: $pass passed, $fail failed" [ "$fail" -eq 0 ]