phosphor-harness 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +134 -2
- package/bin/phosphor.cjs +24 -0
- package/ornith-profile.example.json +7 -0
- package/package.json +16 -4
- package/profile.example.json +11 -0
- package/pyproject.toml +15 -0
- package/quickstart.sh +310 -0
- package/requirements-orin-voice.txt +16 -0
- package/scripts/fetch_ornith_weights.py +40 -0
- package/scripts/fetch_phosphor.py +50 -0
- package/scripts/fetch_sources.py +45 -0
- package/scripts/phosphor-weights.sha256 +11 -0
- package/scripts/run_service.sh +75 -0
- package/sophon_harness/__init__.py +1 -0
- package/sophon_harness/cli.py +76 -0
- package/sophon_harness/news.py +96 -0
- package/sophon_harness/ornith.py +377 -0
- package/sophon_harness/playback_rearm.py +21 -0
- package/sophon_harness/portal_server.py +229 -0
- package/sophon_harness/talker.py +57 -0
- package/sophon_harness/terminal_input.py +124 -0
- package/sophon_harness/tools.py +288 -0
- package/sophon_harness/voice.py +371 -0
- package/sources.lock.json +79 -0
package/quickstart.sh
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Prepare Phosphor in the current Linux user's session and run it as a user service.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
umask 077
|
|
5
|
+
here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
6
|
+
root="${XDG_DATA_HOME:-$HOME/.local/share}/phosphor-harness"
|
|
7
|
+
inspect=no
|
|
8
|
+
prepare=no
|
|
9
|
+
manual=no
|
|
10
|
+
camera=(--camera)
|
|
11
|
+
usage() {
|
|
12
|
+
cat <<'USAGE'
|
|
13
|
+
Usage: phosphor [--doctor | --prepare-only] [--manual OPTIONS]
|
|
14
|
+
phosphor {status|logs|stop}
|
|
15
|
+
|
|
16
|
+
Without options, install dependencies and the verified model, select the default
|
|
17
|
+
microphone and speaker, and start the Phosphor user service.
|
|
18
|
+
|
|
19
|
+
--doctor Show detected hardware and audio devices without installing.
|
|
20
|
+
--prepare-only Prepare the runtime and download weights without starting it.
|
|
21
|
+
--manual Allow explicit overrides.
|
|
22
|
+
--root DIR --microphone NAME --speaker NAME --channels COUNT --channel INDEX
|
|
23
|
+
--gpu UUID --python PATH --voice-python PATH --talker-python PATH
|
|
24
|
+
--tools-python PATH --llama-server PATH --weights DIR --profile FILE
|
|
25
|
+
--camera-device /dev/videoN (repeatable) --no-camera --context TOKENS
|
|
26
|
+
USAGE
|
|
27
|
+
}
|
|
28
|
+
fail() { printf 'Phosphor: %s\n' "$*" >&2; exit 1; }
|
|
29
|
+
need() { command -v "$1" >/dev/null 2>&1; }
|
|
30
|
+
|
|
31
|
+
case "${1:-}" in
|
|
32
|
+
status|stop|logs)
|
|
33
|
+
[[ $# -eq 1 ]] || fail "use phosphor $1 without extra options"
|
|
34
|
+
case "$1" in
|
|
35
|
+
status) exec systemctl --user status phosphor.service ;;
|
|
36
|
+
stop) exec systemctl --user disable --now phosphor.service ;;
|
|
37
|
+
logs) exec journalctl --user-unit phosphor.service -f ;;
|
|
38
|
+
esac ;;
|
|
39
|
+
esac
|
|
40
|
+
|
|
41
|
+
python=python3
|
|
42
|
+
voice_python='' talker_python='' tools_python='' llama='' weights='' profile=''
|
|
43
|
+
microphone='' speaker='' channels='' channel=0 gpu='' context=8192
|
|
44
|
+
overrides=no
|
|
45
|
+
while (($#)); do
|
|
46
|
+
case "$1" in
|
|
47
|
+
-h|--help) usage; exit 0 ;;
|
|
48
|
+
--doctor) inspect=yes ;;
|
|
49
|
+
--prepare-only) prepare=yes ;;
|
|
50
|
+
--manual) manual=yes ;;
|
|
51
|
+
--no-camera) overrides=yes; camera=() ;;
|
|
52
|
+
--root|--microphone|--speaker|--channels|--channel|--gpu|--python|--voice-python|--talker-python|--tools-python|--llama-server|--weights|--profile|--camera-device|--context)
|
|
53
|
+
(($# >= 2)) && [[ -n "$2" && "$2" != --* ]] || fail "$1 requires a value"
|
|
54
|
+
overrides=yes
|
|
55
|
+
case "$1" in
|
|
56
|
+
--root) root=$2 ;; --microphone) microphone=$2 ;; --speaker) speaker=$2 ;;
|
|
57
|
+
--channels) channels=$2 ;; --channel) channel=$2 ;; --gpu) gpu=$2 ;;
|
|
58
|
+
--python) python=$2 ;; --voice-python) voice_python=$2 ;;
|
|
59
|
+
--talker-python) talker_python=$2 ;; --tools-python) tools_python=$2 ;;
|
|
60
|
+
--llama-server) llama=$2 ;; --weights) weights=$2 ;; --profile) profile=$2 ;;
|
|
61
|
+
--camera-device) [[ ${#camera[@]} -gt 0 ]] || camera=(--camera); camera+=(--camera-device "$2") ;;
|
|
62
|
+
--context) context=$2 ;;
|
|
63
|
+
esac
|
|
64
|
+
shift ;;
|
|
65
|
+
*) fail "unknown option $1. Run phosphor --help." ;;
|
|
66
|
+
esac
|
|
67
|
+
shift
|
|
68
|
+
done
|
|
69
|
+
[[ "$overrides" == no || "$manual" == yes ]] || fail "explicit overrides require --manual"
|
|
70
|
+
[[ $(uname -s) == Linux ]] || fail "Linux is required"
|
|
71
|
+
case $(uname -m) in x86_64|aarch64) ;; *) fail "unsupported CPU architecture $(uname -m)" ;; esac
|
|
72
|
+
[[ $EUID -ne 0 ]] || [[ "$inspect" == yes ]] || fail "run as the desktop user so Phosphor can use its audio session"
|
|
73
|
+
ram_mib=$(awk '/^MemTotal:/ {print int($2 / 1024)}' /proc/meminfo)
|
|
74
|
+
jetson_args=()
|
|
75
|
+
if [[ -r /etc/nv_tegra_release ]]; then
|
|
76
|
+
[[ -r /proc/device-tree/compatible ]] && grep -aq tegra234 /proc/device-tree/compatible ||
|
|
77
|
+
fail "the Jetson profile requires an Orin"
|
|
78
|
+
jetson_args=(--orin)
|
|
79
|
+
l4t=$(sed -nE 's/^# R([0-9]+).*REVISION: ([0-9]+).*/\1.\2/p' /etc/nv_tegra_release)
|
|
80
|
+
fi
|
|
81
|
+
gpu_rows=""
|
|
82
|
+
if [[ ${#jetson_args[@]} -eq 0 ]] && need nvidia-smi; then
|
|
83
|
+
gpu_rows=$(nvidia-smi --query-gpu=uuid,memory.total,compute_cap --format=csv,noheader,nounits 2>/dev/null || :)
|
|
84
|
+
fi
|
|
85
|
+
printf 'Linux %s · %s CPU threads · %s MiB RAM\n' "$(uname -m)" "$(nproc)" "$ram_mib"
|
|
86
|
+
if [[ ${#jetson_args[@]} -gt 0 ]]; then printf 'Jetson Orin · L4T %s · unified memory\n' "$l4t"; fi
|
|
87
|
+
if [[ -n "$gpu_rows" ]]; then printf '%s\n' "$gpu_rows"; fi
|
|
88
|
+
if [[ "$inspect" == yes ]]; then
|
|
89
|
+
if need pactl; then
|
|
90
|
+
printf 'Microphone: '; pactl get-default-source || :
|
|
91
|
+
printf 'Speaker: '; pactl get-default-sink || :
|
|
92
|
+
else
|
|
93
|
+
printf 'PulseAudio utilities are not installed.\n'
|
|
94
|
+
fi
|
|
95
|
+
exit 0
|
|
96
|
+
fi
|
|
97
|
+
[[ "$context" =~ ^[1-9][0-9]{3,5}$ ]] || fail "provide a context size from 1000 to 999999 tokens"
|
|
98
|
+
if [[ ${#jetson_args[@]} -gt 0 ]]; then
|
|
99
|
+
((ram_mib >= 22528)) || fail "the Orin profile needs at least 24 GB of unified memory"
|
|
100
|
+
gpu=${gpu:-0}
|
|
101
|
+
[[ "$gpu" == 0 ]] || fail "Orin has one integrated GPU"
|
|
102
|
+
else
|
|
103
|
+
selected=$(awk -F ', *' -v wanted="$gpu" '$1 ~ /^GPU-/ && $2 >= 16000 && $3 >= 8 && (wanted == "" || $1 == wanted) {print $1, $3; exit}' <<< "$gpu_rows")
|
|
104
|
+
[[ -n "$selected" ]] || fail "one NVIDIA Ampere or newer GPU with at least 16 GB is required"
|
|
105
|
+
read -r gpu capability <<< "$selected"
|
|
106
|
+
export OMNI_CUDA_ARCHITECTURES=${capability/./}
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
use_broker=no
|
|
110
|
+
if need docker; then
|
|
111
|
+
if broker_status=$(docker gpu discover 2>&1); then
|
|
112
|
+
printf '%s\n' "$broker_status"
|
|
113
|
+
[[ "$gpu" == GPU-* ]] || fail "the GPU broker requires a physical GPU UUID"
|
|
114
|
+
use_broker=yes
|
|
115
|
+
elif [[ -d /usr/local/share/ollama-unify || ( "$broker_status" != *'unknown command: docker gpu'* &&
|
|
116
|
+
"$broker_status" != *"'gpu' is not a docker command"* ) ]]; then
|
|
117
|
+
fail "GPU broker discovery failed: $broker_status"
|
|
118
|
+
fi
|
|
119
|
+
elif [[ -d /usr/local/share/ollama-unify ]]; then
|
|
120
|
+
fail "this host requires docker gpu and its broker"
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
packages=()
|
|
124
|
+
for requirement in git:git curl:curl cmake:cmake g++:build-essential pkg-config:pkg-config \
|
|
125
|
+
ffmpeg:ffmpeg pactl:pulseaudio-utils v4l2-ctl:v4l-utils tmux:tmux flock:util-linux; do
|
|
126
|
+
need "${requirement%%:*}" || packages+=("${requirement#*:}")
|
|
127
|
+
done
|
|
128
|
+
check_python() { "$1" -c 'import sys, venv, ensurepip; assert (3,10) <= sys.version_info[:2] <= (3,12)'; }
|
|
129
|
+
if ! check_python "$python" 2>/dev/null; then
|
|
130
|
+
if [[ "$python" == python3 ]]; then
|
|
131
|
+
for candidate in python3.12 python3.11 python3.10; do
|
|
132
|
+
if check_python "$candidate" 2>/dev/null; then python=$candidate; break; fi
|
|
133
|
+
done
|
|
134
|
+
fi
|
|
135
|
+
fi
|
|
136
|
+
if ! check_python "$python" 2>/dev/null; then
|
|
137
|
+
[[ "$python" == python3 ]] || fail "provide Python 3.10–3.12 with venv"
|
|
138
|
+
packages+=(python3 python3-venv)
|
|
139
|
+
fi
|
|
140
|
+
if ! pkg-config --exists libssl 2>/dev/null; then packages+=(libssl-dev); fi
|
|
141
|
+
if (( ${#packages[@]} )); then
|
|
142
|
+
need apt-get && need sudo || fail "install missing system packages: ${packages[*]}"
|
|
143
|
+
sudo apt-get update
|
|
144
|
+
sudo apt-get install -y "${packages[@]}"
|
|
145
|
+
fi
|
|
146
|
+
check_python "$python" || fail "Python 3.10–3.12 with venv is required"
|
|
147
|
+
|
|
148
|
+
if [[ "$prepare" == no ]]; then
|
|
149
|
+
systemctl --user list-units --no-legend >/dev/null || fail "log in to a Linux session with a systemd user manager"
|
|
150
|
+
microphone=${microphone:-$(pactl get-default-source)}
|
|
151
|
+
speaker=${speaker:-$(pactl get-default-sink)}
|
|
152
|
+
[[ -n "$microphone" && "$microphone" != *.monitor && -n "$speaker" ]] ||
|
|
153
|
+
fail "choose a microphone and speaker in system audio settings, or specify them with --manual"
|
|
154
|
+
if [[ -z "$channels" ]]; then
|
|
155
|
+
channels=$(pactl -f json list sources | "$python" -c '
|
|
156
|
+
import json, sys
|
|
157
|
+
for source in json.load(sys.stdin):
|
|
158
|
+
if source["name"] == sys.argv[1]:
|
|
159
|
+
print(len(source["channel_map"].split(",")))
|
|
160
|
+
break
|
|
161
|
+
' "$microphone")
|
|
162
|
+
fi
|
|
163
|
+
[[ "$channels" =~ ^[1-9][0-9]?$ && "$channel" =~ ^(0|[1-9][0-9]?)$ ]] &&
|
|
164
|
+
(( channels <= 32 && channel < channels )) || fail "could not determine an input channel for $microphone"
|
|
165
|
+
printf 'Using microphone %s, channel %s of %s, and speaker %s\n' "$microphone" "$channel" "$channels" "$speaker"
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
mkdir -p "$root"
|
|
169
|
+
root=$(realpath "$root")
|
|
170
|
+
exec 9>"$root/setup.lock"
|
|
171
|
+
flock -n 9 || fail "another setup is already running for $root"
|
|
172
|
+
sources=$root/sources
|
|
173
|
+
state=$root/state
|
|
174
|
+
runtime_version=$("$python" -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$here/package.json")
|
|
175
|
+
code=$root/releases/$runtime_version
|
|
176
|
+
mkdir -p "$code/sophon_harness" "$code/scripts" "$state"
|
|
177
|
+
cp "$here"/sophon_harness/*.py "$code/sophon_harness/"
|
|
178
|
+
cp "$here/scripts/run_service.sh" "$code/scripts/"
|
|
179
|
+
cp "$here/ornith-profile.example.json" "$code/"
|
|
180
|
+
profile=$(realpath "${profile:-$code/ornith-profile.example.json}")
|
|
181
|
+
[[ -f "$profile" ]] || fail "profile file is missing"
|
|
182
|
+
"$python" "$here/scripts/fetch_sources.py" "$sources"
|
|
183
|
+
|
|
184
|
+
if [[ -z "$tools_python" ]]; then
|
|
185
|
+
[[ -x "$root/tools/bin/python" ]] || "$python" -m venv "$root/tools"
|
|
186
|
+
tools_python=$root/tools/bin/python
|
|
187
|
+
if [[ ! -f "$root/tools/.ready-$runtime_version" ]]; then
|
|
188
|
+
"$tools_python" -m pip install "huggingface-hub==0.36.0" "$sources/qwen_omni_adapters[pdf]"
|
|
189
|
+
touch "$root/tools/.ready-$runtime_version"
|
|
190
|
+
fi
|
|
191
|
+
fi
|
|
192
|
+
tools_python=$(command -v "$tools_python") || fail "tool Python is missing"
|
|
193
|
+
if [[ -n "$weights" ]]; then
|
|
194
|
+
weights=$(realpath "$weights")
|
|
195
|
+
"$tools_python" "$here/scripts/fetch_phosphor.py" "$weights" --verify-only
|
|
196
|
+
else
|
|
197
|
+
weights=$root/weights
|
|
198
|
+
"$tools_python" "$here/scripts/fetch_phosphor.py" "$weights"
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
if [[ -z "$voice_python" ]]; then
|
|
202
|
+
voice_python=$root/voice/bin/python
|
|
203
|
+
if [[ ! -x "$voice_python" ]]; then
|
|
204
|
+
"$python" -m venv --system-site-packages "$root/voice"
|
|
205
|
+
fi
|
|
206
|
+
if [[ ! -f "$root/voice/.ready-$runtime_version" ]]; then
|
|
207
|
+
"$voice_python" -m pip install -r "$here/requirements-orin-voice.txt" \
|
|
208
|
+
'aiohttp==3.12.15' 'librosa==0.11.0' 'x-transformers==2.31.7' 'einops==0.8.1'
|
|
209
|
+
if ! "$voice_python" -c 'import torch; assert torch.version.cuda' 2>/dev/null; then
|
|
210
|
+
if [[ ${#jetson_args[@]} -eq 0 ]]; then
|
|
211
|
+
torch_version=2.7.1
|
|
212
|
+
torch_index=https://download.pytorch.org/whl/cu126
|
|
213
|
+
if (( ${capability%%.*} >= 10 )); then torch_index=https://download.pytorch.org/whl/cu128; fi
|
|
214
|
+
"$voice_python" -m pip install --index-url "$torch_index" "torch==$torch_version" "torchaudio==$torch_version"
|
|
215
|
+
else
|
|
216
|
+
case "$l4t" in
|
|
217
|
+
36.3*) jetpack=v60; torch_wheel='torch-2.4.0a0+07cecf4168.nv24.05.14710581-cp310-cp310-linux_aarch64.whl' ;;
|
|
218
|
+
36.4*) jetpack=v61; torch_wheel='torch-2.5.0a0+872d972e41.nv24.08.17622132-cp310-cp310-linux_aarch64.whl' ;;
|
|
219
|
+
*) fail "install NVIDIA CUDA PyTorch for L4T $l4t and use --manual --voice-python" ;;
|
|
220
|
+
esac
|
|
221
|
+
"$voice_python" -m pip install "https://developer.download.nvidia.com/compute/redist/jp/$jetpack/pytorch/$torch_wheel"
|
|
222
|
+
fi
|
|
223
|
+
fi
|
|
224
|
+
if [[ -z "$talker_python" ]] && ! "$voice_python" -c 'import torchaudio' 2>/dev/null; then
|
|
225
|
+
torch_version=$("$voice_python" -c 'import re,torch; print(re.match(r"\d+\.\d+\.\d+",torch.__version__)[0])')
|
|
226
|
+
if [[ ${#jetson_args[@]} -gt 0 ]]; then
|
|
227
|
+
"$voice_python" -m pip install 'wheel==0.45.1' 'ninja==1.11.1.4'
|
|
228
|
+
USE_CUDA=0 USE_FFMPEG=0 USE_SOX=0 BUILD_SOX=0 MAX_JOBS=2 \
|
|
229
|
+
"$voice_python" -m pip install --no-build-isolation --no-deps "git+https://github.com/pytorch/audio.git@v$torch_version"
|
|
230
|
+
else
|
|
231
|
+
"$voice_python" -m pip install --index-url https://download.pytorch.org/whl/cu126 --no-deps "torchaudio==$torch_version"
|
|
232
|
+
fi
|
|
233
|
+
fi
|
|
234
|
+
touch "$root/voice/.ready-$runtime_version"
|
|
235
|
+
fi
|
|
236
|
+
fi
|
|
237
|
+
voice_python=$(command -v "$voice_python") || fail "voice Python is missing"
|
|
238
|
+
talker_python=$(command -v "${talker_python:-$voice_python}") || fail "Talker Python is missing"
|
|
239
|
+
"$voice_python" -c 'import torch, onnxruntime, soundfile, scipy; assert torch.version.cuda' ||
|
|
240
|
+
fail "the voice Python needs CUDA PyTorch and the pinned audio dependencies"
|
|
241
|
+
"$talker_python" -c 'import torch, torchaudio, aiohttp, librosa, x_transformers, einops, transformers; assert torch.version.cuda' ||
|
|
242
|
+
fail "the Talker Python needs CUDA PyTorch and matching torchaudio"
|
|
243
|
+
|
|
244
|
+
if [[ -z "$llama" ]]; then
|
|
245
|
+
llama=$sources/llama_cpp/build/bin/llama-server
|
|
246
|
+
if [[ ! -x "$llama" ]]; then
|
|
247
|
+
jobs=$(nproc)
|
|
248
|
+
if (( jobs > 4 )); then jobs=4; fi
|
|
249
|
+
OMNI_MODEL='' LLAMA_CPP_BUILD_DIR="$sources/llama_cpp/build" LLAMA_CPP_BUILD_JOBS="$jobs" \
|
|
250
|
+
bash "$sources/qwen_omni_adapters/scripts/build_llama_cpp.sh" "$sources/llama_cpp"
|
|
251
|
+
fi
|
|
252
|
+
fi
|
|
253
|
+
llama=$(command -v "$llama") || fail "llama-server is missing"
|
|
254
|
+
if [[ "$prepare" == yes ]]; then
|
|
255
|
+
printf 'Phosphor is prepared at %s\n' "$root"
|
|
256
|
+
exit 0
|
|
257
|
+
fi
|
|
258
|
+
|
|
259
|
+
config=$root/service.env
|
|
260
|
+
unit_dir=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user
|
|
261
|
+
unit=$unit_dir/phosphor.service
|
|
262
|
+
mkdir -p "$unit_dir"
|
|
263
|
+
generated=$(mktemp "$root/service.env.XXXXXX")
|
|
264
|
+
for key in code sources state profile microphone speaker channels channel context gpu use_broker \
|
|
265
|
+
llama tools_python voice_python talker_python weights; do
|
|
266
|
+
printf '%s=%q\n' "$key" "${!key}"
|
|
267
|
+
done > "$generated"
|
|
268
|
+
declare -p jetson_args camera >> "$generated"
|
|
269
|
+
changed=no
|
|
270
|
+
if ! cmp -s "$generated" "$config"; then mv -T "$generated" "$config"; changed=yes
|
|
271
|
+
else unlink "$generated"; fi
|
|
272
|
+
systemd_arg() {
|
|
273
|
+
local value=${1//\\/\\\\}
|
|
274
|
+
value=${value//\"/\\\"}
|
|
275
|
+
value=${value//%/%%}
|
|
276
|
+
value=${value//\$/\$\$}
|
|
277
|
+
printf '"%s"' "$value"
|
|
278
|
+
}
|
|
279
|
+
generated=$(mktemp "$unit_dir/.phosphor.XXXXXX")
|
|
280
|
+
cat > "$generated" <<UNIT
|
|
281
|
+
[Unit]
|
|
282
|
+
Description=Phosphor voice and tool harness
|
|
283
|
+
After=pipewire-pulse.service pulseaudio.service
|
|
284
|
+
|
|
285
|
+
[Service]
|
|
286
|
+
Type=exec
|
|
287
|
+
ExecStart=/bin/bash $(systemd_arg "$code/scripts/run_service.sh") $(systemd_arg "$config")
|
|
288
|
+
Restart=on-failure
|
|
289
|
+
RestartSec=5
|
|
290
|
+
|
|
291
|
+
[Install]
|
|
292
|
+
WantedBy=default.target
|
|
293
|
+
UNIT
|
|
294
|
+
if ! cmp -s "$generated" "$unit"; then mv -T "$generated" "$unit"; changed=yes
|
|
295
|
+
else unlink "$generated"; fi
|
|
296
|
+
systemctl --user daemon-reload
|
|
297
|
+
if [[ "$changed" == yes ]] && systemctl --user is-active --quiet phosphor.service; then
|
|
298
|
+
systemctl --user restart phosphor.service
|
|
299
|
+
fi
|
|
300
|
+
systemctl --user enable --now phosphor.service
|
|
301
|
+
for ((attempt=0; attempt<780; attempt++)); do
|
|
302
|
+
if [[ -f "$state/voice.ready" ]] && systemctl --user is-active --quiet phosphor.service; then
|
|
303
|
+
printf 'Phosphor is listening. Speak into your microphone. Run phosphor logs to watch the service.\n'
|
|
304
|
+
exit 0
|
|
305
|
+
fi
|
|
306
|
+
if systemctl --user is-failed --quiet phosphor.service; then break; fi
|
|
307
|
+
sleep 1
|
|
308
|
+
done
|
|
309
|
+
journalctl --user-unit phosphor.service -n 30 --no-pager >&2
|
|
310
|
+
fail "the voice service did not reach microphone readiness. Run phosphor logs for details."
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Install platform-matched PyTorch separately.
|
|
2
|
+
numpy==1.26.1
|
|
3
|
+
scipy==1.15.3
|
|
4
|
+
soundfile==0.13.1
|
|
5
|
+
onnxruntime==1.23.2
|
|
6
|
+
transformers==4.57.6
|
|
7
|
+
accelerate==1.10.1
|
|
8
|
+
tokenizers==0.22.2
|
|
9
|
+
huggingface-hub==0.36.0
|
|
10
|
+
gguf==0.17.1
|
|
11
|
+
safetensors==0.6.2
|
|
12
|
+
httpx==0.28.1
|
|
13
|
+
num2words==0.5.14
|
|
14
|
+
jsonschema==4.26.0
|
|
15
|
+
websockets==15.0.1
|
|
16
|
+
flask==3.1.2
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Download the pinned Ornith backplane and original Sophon speech weights."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from huggingface_hub import hf_hub_download
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def verify(path, expected):
|
|
12
|
+
if path.stat().st_size != expected["size"]:
|
|
13
|
+
raise ValueError(f"{path}: unexpected size")
|
|
14
|
+
with path.open("rb") as stream:
|
|
15
|
+
digest = hashlib.sha256()
|
|
16
|
+
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
|
17
|
+
digest.update(block)
|
|
18
|
+
if digest.hexdigest() != expected["sha256"]:
|
|
19
|
+
raise ValueError(f"{path}: SHA-256 verification failed")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
24
|
+
parser.add_argument("destination", type=Path)
|
|
25
|
+
parser.add_argument("--verify-only", action="store_true")
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
pins = json.loads((Path(__file__).resolve().parents[1] / "sources.lock.json").read_text())
|
|
28
|
+
for component in ("ornith_weights", "sophon_speech"):
|
|
29
|
+
spec = pins[component]
|
|
30
|
+
dest = args.destination / component
|
|
31
|
+
for filename, expected in spec["files"].items():
|
|
32
|
+
path = dest / filename
|
|
33
|
+
if not args.verify_only and not path.exists():
|
|
34
|
+
hf_hub_download(spec["hub_repository"], filename, revision=spec["revision"], local_dir=dest)
|
|
35
|
+
verify(path, expected)
|
|
36
|
+
print(f"{expected['sha256']} {path}", flush=True)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Download the qualified Phosphor bundle and verify every model component."""
|
|
2
|
+
import argparse
|
|
3
|
+
import hashlib
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
REPO = "cudabenchmarktest/Phosphor"
|
|
8
|
+
REVISION = "4ed4e90776be8785ee3faa92d9dc80f62ddee2e0"
|
|
9
|
+
CHECKSUMS = Path(__file__).with_name("phosphor-weights.sha256")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def verify(directory):
|
|
13
|
+
for line in CHECKSUMS.read_text().splitlines():
|
|
14
|
+
expected, filename = line.split()
|
|
15
|
+
digest = hashlib.sha256()
|
|
16
|
+
with (directory / filename).open("rb") as handle:
|
|
17
|
+
for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""):
|
|
18
|
+
digest.update(chunk)
|
|
19
|
+
if digest.hexdigest() != expected:
|
|
20
|
+
raise SystemExit(f"Phosphor checksum mismatch: {directory / filename}")
|
|
21
|
+
print(f"Verified Phosphor weights at {directory}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
26
|
+
parser.add_argument("directory", type=Path)
|
|
27
|
+
parser.add_argument("--verify-only", action="store_true")
|
|
28
|
+
args = parser.parse_args()
|
|
29
|
+
if not args.verify_only:
|
|
30
|
+
from huggingface_hub import HfApi, snapshot_download
|
|
31
|
+
|
|
32
|
+
if not args.directory.exists() or not (args.directory / ".verified").is_file():
|
|
33
|
+
names = [line.split()[1] for line in CHECKSUMS.read_text().splitlines()]
|
|
34
|
+
files = HfApi().model_info(REPO, revision=REVISION, files_metadata=True, token=False).siblings
|
|
35
|
+
missing = sum(item.size for item in files
|
|
36
|
+
if item.rfilename in names and not (args.directory / item.rfilename).exists())
|
|
37
|
+
if shutil.disk_usage(args.directory.parent).free < missing + 1024 ** 3:
|
|
38
|
+
raise SystemExit(f"Not enough disk space at {args.directory.parent} to download Phosphor")
|
|
39
|
+
snapshot_download(REPO, revision=REVISION, local_dir=args.directory, token=False,
|
|
40
|
+
allow_patterns=names + ["LICENSE.md", "NOTICE.md", "licenses/*"])
|
|
41
|
+
verify(args.directory)
|
|
42
|
+
(args.directory / ".verified").touch()
|
|
43
|
+
else:
|
|
44
|
+
verify(args.directory)
|
|
45
|
+
return
|
|
46
|
+
verify(args.directory)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
main()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Fetch the exact source revisions into a new runtime source directory."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def git(*args):
|
|
10
|
+
return subprocess.check_output(["git", *map(str, args)], text=True).strip()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
15
|
+
parser.add_argument("destination", type=Path)
|
|
16
|
+
args = parser.parse_args()
|
|
17
|
+
pins = json.loads((Path(__file__).resolve().parents[1] / "sources.lock.json").read_text())
|
|
18
|
+
args.destination.mkdir(parents=True, exist_ok=True)
|
|
19
|
+
for name, spec in pins.items():
|
|
20
|
+
if "repository" not in spec:
|
|
21
|
+
continue
|
|
22
|
+
target = args.destination / name
|
|
23
|
+
revision = spec["commit"]
|
|
24
|
+
if not target.exists():
|
|
25
|
+
target.mkdir()
|
|
26
|
+
git("-C", target, "init", "--quiet")
|
|
27
|
+
git("-C", target, "remote", "add", "origin", spec["repository"])
|
|
28
|
+
try:
|
|
29
|
+
head = git("-C", target, "rev-parse", "--verify", "--quiet", "HEAD")
|
|
30
|
+
except subprocess.CalledProcessError:
|
|
31
|
+
head = ""
|
|
32
|
+
if head != revision:
|
|
33
|
+
if head or git("-C", target, "status", "--porcelain"):
|
|
34
|
+
raise SystemExit(f"{target} already contains work at a different revision")
|
|
35
|
+
if git("-C", target, "remote", "get-url", "origin") != spec["repository"]:
|
|
36
|
+
raise SystemExit(f"{target} has an unexpected upstream")
|
|
37
|
+
git("-C", target, "fetch", "--quiet", "--depth=1", "origin", revision)
|
|
38
|
+
git("-C", target, "checkout", "--quiet", "--detach", revision)
|
|
39
|
+
if git("-C", target, "rev-parse", "HEAD") != revision:
|
|
40
|
+
raise SystemExit(f"{target} failed revision verification")
|
|
41
|
+
print(f"{name} {revision}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
7e2d6fe7e80c4538e961e592d954d1c47d64e087139db03043741a0238af2c1c backplane/mmproj-bf16.gguf
|
|
2
|
+
852922174ee4f76621df26105333f1dfe2171cdfb60ebe5a4b013836681a8a77 backplane/model-q4_k_m.gguf
|
|
3
|
+
131f49c60d20891cd98cac166b45be4e4ec5b4806459faac505b9017c25ff62c speech/e2/config.json
|
|
4
|
+
53d028ecf0f6b46da3c006f6a38f6ca3597eab71f32f1f6fcf730f2c9b0e8dc9 speech/e2/hift.safetensors
|
|
5
|
+
f7cea4a8843b2c808dd26de962717eda37856dd764631f076aee832d44770872 speech/e2/model.safetensors
|
|
6
|
+
1b3ea7e508b63fecbda6a44f25351a5231daf731a70799a439a218066952571d speech/talker220/config.json
|
|
7
|
+
d902bd8cdcfc739af06809ac557b6bef25102c319ff7676d74f00331b81aa8be speech/talker220/embed.safetensors
|
|
8
|
+
2c852d43e7fdf216b8328ab1f62906941d5fbc97f803cdcfa4da2ee8361ce8c2 speech/talker220/model.safetensors
|
|
9
|
+
d67088bc18cf6eb2220bc2f163ef76b9f4fecd6076069719cf01b6b854392901 speech/talker220/tokenizer.json
|
|
10
|
+
2091fcab26e2f0e214ffcbd3cd2dc83ac4c4dd9b27dd75a8ce974b8f03843dee speech/talker220/tokenizer_config.json
|
|
11
|
+
6bf3e9ba66d9a542eb9cdd356bd7f909118dd9aba05c3d7ecd4ddfbab91b4b82 speech/voices/chelsie.safetensors
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
umask 077
|
|
4
|
+
|
|
5
|
+
source "$1"
|
|
6
|
+
if [[ ${2:-} != --scoped ]]; then
|
|
7
|
+
if [[ "$use_broker" == yes ]]; then
|
|
8
|
+
docker gpu discover
|
|
9
|
+
exec docker gpu run --owner "phosphor-$(id -un)" --justification "Phosphor voice service" \
|
|
10
|
+
--gpu "$gpu" --ready-command 'curl -fsS http://127.0.0.1:18215/health >/dev/null && curl -fsS http://127.0.0.1:18213/health >/dev/null' \
|
|
11
|
+
-- bash "$0" "$1" --scoped
|
|
12
|
+
fi
|
|
13
|
+
export CUDA_VISIBLE_DEVICES="$gpu"
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
export PYTHONPATH="$code${PYTHONPATH:+:$PYTHONPATH}"
|
|
17
|
+
export PYTHONUNBUFFERED=1
|
|
18
|
+
pids=()
|
|
19
|
+
cleanup() {
|
|
20
|
+
unlink "$state/voice.ready" 2>/dev/null || :
|
|
21
|
+
for pid in "${pids[@]}"; do kill "$pid" 2>/dev/null || :; done
|
|
22
|
+
wait || :
|
|
23
|
+
}
|
|
24
|
+
trap cleanup EXIT
|
|
25
|
+
trap 'exit 0' TERM INT HUP
|
|
26
|
+
|
|
27
|
+
unlink "$state/voice.ready" 2>/dev/null || :
|
|
28
|
+
start() {
|
|
29
|
+
"$@" &
|
|
30
|
+
pids+=("$!")
|
|
31
|
+
}
|
|
32
|
+
ready() {
|
|
33
|
+
local url=$1 pid=$2
|
|
34
|
+
for ((attempt=0; attempt<360; attempt++)); do
|
|
35
|
+
kill -0 "$pid" 2>/dev/null || break
|
|
36
|
+
if [[ $(curl --max-time 2 -s -o /dev/null -w '%{http_code}' "$url") == "${3:-200}" ]]; then return 0; fi
|
|
37
|
+
sleep 1
|
|
38
|
+
done
|
|
39
|
+
printf 'Phosphor worker failed to become ready at %s\n' "$url" >&2
|
|
40
|
+
return 1
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
"$voice_python" - <<'PY'
|
|
44
|
+
import socket
|
|
45
|
+
from contextlib import ExitStack
|
|
46
|
+
with ExitStack() as stack:
|
|
47
|
+
for port in (18213, 18214, 18215):
|
|
48
|
+
probe = stack.enter_context(socket.socket())
|
|
49
|
+
probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
50
|
+
try:
|
|
51
|
+
probe.bind(("127.0.0.1", port))
|
|
52
|
+
except OSError as error:
|
|
53
|
+
raise SystemExit(f"Phosphor needs free loopback port {port}: {error}")
|
|
54
|
+
PY
|
|
55
|
+
mkdir -p "$state/workspace"
|
|
56
|
+
start "$tools_python" -m sophon_harness.portal_server \
|
|
57
|
+
--adapters "$sources/qwen_omni_adapters" --state "$state" --workspace "$state/workspace" "${camera[@]}"
|
|
58
|
+
ready http://127.0.0.1:18214/api/status "${pids[-1]}" 401
|
|
59
|
+
if (( ${#jetson_args[@]} )); then export GGML_CUDA_DISABLE_GRAPHS=1; fi
|
|
60
|
+
start "$llama" --model "$weights/backplane/model-q4_k_m.gguf" --mmproj "$weights/backplane/mmproj-bf16.gguf" \
|
|
61
|
+
--alias phosphor --host 127.0.0.1 --port 18215 --no-webui --jinja \
|
|
62
|
+
--cors-origins http://127.0.0.1:18215 --no-cors-credentials --reasoning-format deepseek \
|
|
63
|
+
--device CUDA0 --mmproj-device CUDA0 --gpu-layers 99 --fit off --ctx-size "$context" \
|
|
64
|
+
--parallel 1 --cache-type-k q8_0 --cache-type-v q8_0 --flash-attn on
|
|
65
|
+
ready http://127.0.0.1:18215/health "${pids[-1]}"
|
|
66
|
+
start "$talker_python" -m sophon_harness.talker --source "$sources/sophon_realtime" \
|
|
67
|
+
--speech-weights "$weights/speech" "${jetson_args[@]}"
|
|
68
|
+
ready http://127.0.0.1:18213/health "${pids[-1]}"
|
|
69
|
+
start "$voice_python" -m sophon_harness.cli --token-file "$state/portal.token" \
|
|
70
|
+
voice --suite "$sources/fine_tuning_suite" --profile "$profile" --ornith-url http://127.0.0.1:18215 \
|
|
71
|
+
--ornith-model phosphor --vad "$sources/sophon_realtime/e2e/config/silero_vad.onnx" \
|
|
72
|
+
--source "$microphone" --sink "$speaker" --channels "$channels" --channel "$channel" --ready-file "$state/voice.ready"
|
|
73
|
+
wait -n
|
|
74
|
+
# A worker exiting normally is also a service failure when it was meant to stay up.
|
|
75
|
+
exit 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Standalone native-acoustic Sophon speech and tools."""
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Operate the standalone Sophon harness and local tools."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from .tools import CORE_TOOLS, PortalTools
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
15
|
+
parser.add_argument("--tools-url", default="http://127.0.0.1:18214")
|
|
16
|
+
parser.add_argument("--token-file", type=Path, required=True)
|
|
17
|
+
parser.add_argument("--reviews", type=Path, help=argparse.SUPPRESS)
|
|
18
|
+
actions = parser.add_subparsers(dest="command", required=True)
|
|
19
|
+
actions.add_parser("tools", help="List the exact tool catalog")
|
|
20
|
+
attach = actions.add_parser("attach", help="Index an operator-selected document for the voice session")
|
|
21
|
+
attach.add_argument("path", type=Path)
|
|
22
|
+
location = actions.add_parser("location", help="Supply or clear approximate location for the current session")
|
|
23
|
+
location_source = location.add_mutually_exclusive_group(required=True)
|
|
24
|
+
location_source.add_argument("--file", type=Path, help="Operator-provided geolocation JSON")
|
|
25
|
+
location_source.add_argument("--clear", action="store_true")
|
|
26
|
+
run = actions.add_parser("voice", help="Run local audio capture and playback")
|
|
27
|
+
run.add_argument("--suite", type=Path, required=True, help="Pinned Fine-Tuning Suite source checkout")
|
|
28
|
+
run.add_argument("--profile", type=Path, required=True)
|
|
29
|
+
run.add_argument("--vad", type=Path, required=True)
|
|
30
|
+
run.add_argument("--memory-mib", type=int, help="CUDA memory reservation for the native Qwen 4B loader")
|
|
31
|
+
run.add_argument("--ornith-url", help="Loopback address of the Ornith llama-server")
|
|
32
|
+
run.add_argument("--ornith-model", default="ornith-1.5-9b")
|
|
33
|
+
run.add_argument("--image", type=Path, help="Attach this JPEG or PNG to each committed voice or probe turn")
|
|
34
|
+
run.add_argument("--orin", action="store_true")
|
|
35
|
+
run.add_argument("--channels", type=int, default=1)
|
|
36
|
+
run.add_argument("--channel", type=int, default=0)
|
|
37
|
+
run.add_argument("--source")
|
|
38
|
+
run.add_argument("--sink")
|
|
39
|
+
run.add_argument("--ready-file", type=Path, help=argparse.SUPPRESS)
|
|
40
|
+
run.add_argument("--probe", type=Path, action="append", default=[])
|
|
41
|
+
run.add_argument("--probe-only", action="store_true")
|
|
42
|
+
run.add_argument("--probe-history", action="store_true", help="Retain conversation state across WAV replays")
|
|
43
|
+
args = parser.parse_args()
|
|
44
|
+
|
|
45
|
+
if args.command == "voice":
|
|
46
|
+
if not 0 <= args.channel < args.channels <= 32:
|
|
47
|
+
parser.error("choose a valid PulseAudio capture channel")
|
|
48
|
+
if args.probe_only and not args.probe:
|
|
49
|
+
parser.error("supply at least one WAV with --probe-only")
|
|
50
|
+
if args.ornith_url is None and args.memory_mib is None:
|
|
51
|
+
parser.error("supply --memory-mib for Qwen 4B or --ornith-url for Ornith 9B")
|
|
52
|
+
if args.image is not None and args.ornith_url is None:
|
|
53
|
+
parser.error("--image requires the 9B backplane")
|
|
54
|
+
sys.path.insert(0, str(args.suite.resolve(strict=True)))
|
|
55
|
+
from .voice import start
|
|
56
|
+
start(args)
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
if args.command == "attach":
|
|
60
|
+
with PortalTools(args.tools_url, args.token_file) as tools:
|
|
61
|
+
value = tools.attach(args.path)
|
|
62
|
+
elif args.command == "location":
|
|
63
|
+
supplied = None if args.clear else json.loads(args.file.read_text(encoding="utf-8"))
|
|
64
|
+
with PortalTools(args.tools_url, args.token_file) as tools:
|
|
65
|
+
value = tools.set_location(supplied)
|
|
66
|
+
else:
|
|
67
|
+
with PortalTools(args.tools_url, args.token_file) as tools:
|
|
68
|
+
value = [
|
|
69
|
+
{**item, "shown_initially": item["function"]["name"] in CORE_TOOLS}
|
|
70
|
+
for item in tools.definitions
|
|
71
|
+
]
|
|
72
|
+
print(json.dumps(value, ensure_ascii=False, indent=2))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|