phosphor-harness 0.0.0-stage → 0.4.0

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/quickstart.sh ADDED
@@ -0,0 +1,305 @@
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 && docker gpu --help >/dev/null 2>&1; then
111
+ docker gpu discover
112
+ [[ "$gpu" == GPU-* ]] || fail "the GPU broker requires a physical GPU UUID"
113
+ use_broker=yes
114
+ elif [[ -d /usr/local/share/ollama-unify ]]; then
115
+ fail "this host requires docker gpu and its broker"
116
+ fi
117
+
118
+ packages=()
119
+ for requirement in git:git curl:curl cmake:cmake g++:build-essential pkg-config:pkg-config \
120
+ ffmpeg:ffmpeg pactl:pulseaudio-utils v4l2-ctl:v4l-utils tmux:tmux flock:util-linux; do
121
+ need "${requirement%%:*}" || packages+=("${requirement#*:}")
122
+ done
123
+ check_python() { "$1" -c 'import sys, venv, ensurepip; assert (3,10) <= sys.version_info[:2] <= (3,12)'; }
124
+ if ! check_python "$python" 2>/dev/null; then
125
+ if [[ "$python" == python3 ]]; then
126
+ for candidate in python3.12 python3.11 python3.10; do
127
+ if check_python "$candidate" 2>/dev/null; then python=$candidate; break; fi
128
+ done
129
+ fi
130
+ fi
131
+ if ! check_python "$python" 2>/dev/null; then
132
+ [[ "$python" == python3 ]] || fail "provide Python 3.10–3.12 with venv"
133
+ packages+=(python3 python3-venv)
134
+ fi
135
+ if ! pkg-config --exists libssl 2>/dev/null; then packages+=(libssl-dev); fi
136
+ if (( ${#packages[@]} )); then
137
+ need apt-get && need sudo || fail "install missing system packages: ${packages[*]}"
138
+ sudo apt-get update
139
+ sudo apt-get install -y "${packages[@]}"
140
+ fi
141
+ check_python "$python" || fail "Python 3.10–3.12 with venv is required"
142
+
143
+ if [[ "$prepare" == no ]]; then
144
+ systemctl --user list-units --no-legend >/dev/null || fail "log in to a Linux session with a systemd user manager"
145
+ microphone=${microphone:-$(pactl get-default-source)}
146
+ speaker=${speaker:-$(pactl get-default-sink)}
147
+ [[ -n "$microphone" && "$microphone" != *.monitor && -n "$speaker" ]] ||
148
+ fail "choose a microphone and speaker in system audio settings, or specify them with --manual"
149
+ if [[ -z "$channels" ]]; then
150
+ channels=$(pactl -f json list sources | "$python" -c '
151
+ import json, sys
152
+ for source in json.load(sys.stdin):
153
+ if source["name"] == sys.argv[1]:
154
+ print(len(source["channel_map"].split(",")))
155
+ break
156
+ ' "$microphone")
157
+ fi
158
+ [[ "$channels" =~ ^[1-9][0-9]?$ && "$channel" =~ ^(0|[1-9][0-9]?)$ ]] &&
159
+ (( channels <= 32 && channel < channels )) || fail "could not determine an input channel for $microphone"
160
+ printf 'Using microphone %s, channel %s of %s, and speaker %s\n' "$microphone" "$channel" "$channels" "$speaker"
161
+ fi
162
+
163
+ mkdir -p "$root"
164
+ root=$(realpath "$root")
165
+ exec 9>"$root/setup.lock"
166
+ flock -n 9 || fail "another setup is already running for $root"
167
+ sources=$root/sources
168
+ state=$root/state
169
+ runtime_version=$("$python" -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$here/package.json")
170
+ code=$root/releases/$runtime_version
171
+ mkdir -p "$code/sophon_harness" "$code/scripts" "$state"
172
+ cp "$here"/sophon_harness/*.py "$code/sophon_harness/"
173
+ cp "$here/scripts/run_service.sh" "$code/scripts/"
174
+ cp "$here/ornith-profile.example.json" "$code/"
175
+ profile=$(realpath "${profile:-$code/ornith-profile.example.json}")
176
+ [[ -f "$profile" ]] || fail "profile file is missing"
177
+ "$python" "$here/scripts/fetch_sources.py" "$sources"
178
+
179
+ if [[ -z "$tools_python" ]]; then
180
+ [[ -x "$root/tools/bin/python" ]] || "$python" -m venv "$root/tools"
181
+ tools_python=$root/tools/bin/python
182
+ if [[ ! -f "$root/tools/.ready-$runtime_version" ]]; then
183
+ "$tools_python" -m pip install "huggingface-hub==0.36.0" "$sources/qwen_omni_adapters[pdf]"
184
+ touch "$root/tools/.ready-$runtime_version"
185
+ fi
186
+ fi
187
+ tools_python=$(command -v "$tools_python") || fail "tool Python is missing"
188
+ if [[ -n "$weights" ]]; then
189
+ weights=$(realpath "$weights")
190
+ "$tools_python" "$here/scripts/fetch_phosphor.py" "$weights" --verify-only
191
+ else
192
+ weights=$root/weights
193
+ "$tools_python" "$here/scripts/fetch_phosphor.py" "$weights"
194
+ fi
195
+
196
+ if [[ -z "$voice_python" ]]; then
197
+ voice_python=$root/voice/bin/python
198
+ if [[ ! -x "$voice_python" ]]; then
199
+ "$python" -m venv --system-site-packages "$root/voice"
200
+ fi
201
+ if [[ ! -f "$root/voice/.ready-$runtime_version" ]]; then
202
+ "$voice_python" -m pip install -r "$here/requirements-orin-voice.txt" \
203
+ 'aiohttp==3.12.15' 'librosa==0.11.0' 'x-transformers==2.31.7' 'einops==0.8.1'
204
+ if ! "$voice_python" -c 'import torch; assert torch.version.cuda' 2>/dev/null; then
205
+ if [[ ${#jetson_args[@]} -eq 0 ]]; then
206
+ torch_version=2.7.1
207
+ torch_index=https://download.pytorch.org/whl/cu126
208
+ if (( ${capability%%.*} >= 10 )); then torch_index=https://download.pytorch.org/whl/cu128; fi
209
+ "$voice_python" -m pip install --index-url "$torch_index" "torch==$torch_version" "torchaudio==$torch_version"
210
+ else
211
+ case "$l4t" in
212
+ 36.3*) jetpack=v60; torch_wheel='torch-2.4.0a0+07cecf4168.nv24.05.14710581-cp310-cp310-linux_aarch64.whl' ;;
213
+ 36.4*) jetpack=v61; torch_wheel='torch-2.5.0a0+872d972e41.nv24.08.17622132-cp310-cp310-linux_aarch64.whl' ;;
214
+ *) fail "install NVIDIA CUDA PyTorch for L4T $l4t and use --manual --voice-python" ;;
215
+ esac
216
+ "$voice_python" -m pip install "https://developer.download.nvidia.com/compute/redist/jp/$jetpack/pytorch/$torch_wheel"
217
+ fi
218
+ fi
219
+ if [[ -z "$talker_python" ]] && ! "$voice_python" -c 'import torchaudio' 2>/dev/null; then
220
+ torch_version=$("$voice_python" -c 'import re,torch; print(re.match(r"\d+\.\d+\.\d+",torch.__version__)[0])')
221
+ if [[ ${#jetson_args[@]} -gt 0 ]]; then
222
+ "$voice_python" -m pip install 'wheel==0.45.1' 'ninja==1.11.1.4'
223
+ USE_CUDA=0 USE_FFMPEG=0 USE_SOX=0 BUILD_SOX=0 MAX_JOBS=2 \
224
+ "$voice_python" -m pip install --no-build-isolation --no-deps "git+https://github.com/pytorch/audio.git@v$torch_version"
225
+ else
226
+ "$voice_python" -m pip install --index-url https://download.pytorch.org/whl/cu126 --no-deps "torchaudio==$torch_version"
227
+ fi
228
+ fi
229
+ touch "$root/voice/.ready-$runtime_version"
230
+ fi
231
+ fi
232
+ voice_python=$(command -v "$voice_python") || fail "voice Python is missing"
233
+ talker_python=$(command -v "${talker_python:-$voice_python}") || fail "Talker Python is missing"
234
+ "$voice_python" -c 'import torch, onnxruntime, soundfile, scipy; assert torch.version.cuda' ||
235
+ fail "the voice Python needs CUDA PyTorch and the pinned audio dependencies"
236
+ "$talker_python" -c 'import torch, torchaudio, aiohttp, librosa, x_transformers, einops, transformers; assert torch.version.cuda' ||
237
+ fail "the Talker Python needs CUDA PyTorch and matching torchaudio"
238
+
239
+ if [[ -z "$llama" ]]; then
240
+ llama=$sources/llama_cpp/build/bin/llama-server
241
+ if [[ ! -x "$llama" ]]; then
242
+ jobs=$(nproc)
243
+ if (( jobs > 4 )); then jobs=4; fi
244
+ OMNI_MODEL='' LLAMA_CPP_BUILD_DIR="$sources/llama_cpp/build" LLAMA_CPP_BUILD_JOBS="$jobs" \
245
+ bash "$sources/qwen_omni_adapters/scripts/build_llama_cpp.sh" "$sources/llama_cpp"
246
+ fi
247
+ fi
248
+ llama=$(command -v "$llama") || fail "llama-server is missing"
249
+ if [[ "$prepare" == yes ]]; then
250
+ printf 'Phosphor is prepared at %s\n' "$root"
251
+ exit 0
252
+ fi
253
+
254
+ config=$root/service.env
255
+ unit_dir=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user
256
+ unit=$unit_dir/phosphor.service
257
+ mkdir -p "$unit_dir"
258
+ generated=$(mktemp "$root/service.env.XXXXXX")
259
+ for key in code sources state profile microphone speaker channels channel context gpu use_broker \
260
+ llama tools_python voice_python talker_python weights; do
261
+ printf '%s=%q\n' "$key" "${!key}"
262
+ done > "$generated"
263
+ declare -p jetson_args camera >> "$generated"
264
+ changed=no
265
+ if ! cmp -s "$generated" "$config"; then mv -T "$generated" "$config"; changed=yes
266
+ else unlink "$generated"; fi
267
+ systemd_arg() {
268
+ local value=${1//\\/\\\\}
269
+ value=${value//\"/\\\"}
270
+ value=${value//%/%%}
271
+ value=${value//\$/\$\$}
272
+ printf '"%s"' "$value"
273
+ }
274
+ generated=$(mktemp "$unit_dir/.phosphor.XXXXXX")
275
+ cat > "$generated" <<UNIT
276
+ [Unit]
277
+ Description=Phosphor voice and tool harness
278
+ After=pipewire-pulse.service pulseaudio.service
279
+
280
+ [Service]
281
+ Type=exec
282
+ ExecStart=/bin/bash $(systemd_arg "$code/scripts/run_service.sh") $(systemd_arg "$config")
283
+ Restart=on-failure
284
+ RestartSec=5
285
+
286
+ [Install]
287
+ WantedBy=default.target
288
+ UNIT
289
+ if ! cmp -s "$generated" "$unit"; then mv -T "$generated" "$unit"; changed=yes
290
+ else unlink "$generated"; fi
291
+ systemctl --user daemon-reload
292
+ if [[ "$changed" == yes ]] && systemctl --user is-active --quiet phosphor.service; then
293
+ systemctl --user restart phosphor.service
294
+ fi
295
+ systemctl --user enable --now phosphor.service
296
+ for ((attempt=0; attempt<780; attempt++)); do
297
+ if [[ -f "$state/voice.ready" ]] && systemctl --user is-active --quiet phosphor.service; then
298
+ printf 'Phosphor is listening. Speak into your microphone. Run phosphor logs to watch the service.\n'
299
+ exit 0
300
+ fi
301
+ if systemctl --user is-failed --quiet phosphor.service; then break; fi
302
+ sleep 1
303
+ done
304
+ journalctl --user-unit phosphor.service -n 30 --no-pager >&2
305
+ 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,74 @@
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
+ for pid in "${pids[@]}"; do kill "$pid" 2>/dev/null || :; done
21
+ wait || :
22
+ }
23
+ trap cleanup EXIT
24
+ trap 'exit 0' TERM INT HUP
25
+
26
+ start() {
27
+ "$@" &
28
+ pids+=("$!")
29
+ }
30
+ ready() {
31
+ local url=$1 pid=$2
32
+ for ((attempt=0; attempt<360; attempt++)); do
33
+ kill -0 "$pid" 2>/dev/null || break
34
+ if [[ $(curl --max-time 2 -s -o /dev/null -w '%{http_code}' "$url") == "${3:-200}" ]]; then return 0; fi
35
+ sleep 1
36
+ done
37
+ printf 'Phosphor worker failed to become ready at %s\n' "$url" >&2
38
+ return 1
39
+ }
40
+
41
+ "$voice_python" - <<'PY'
42
+ import socket
43
+ from contextlib import ExitStack
44
+ with ExitStack() as stack:
45
+ for port in (18213, 18214, 18215):
46
+ probe = stack.enter_context(socket.socket())
47
+ probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
48
+ try:
49
+ probe.bind(("127.0.0.1", port))
50
+ except OSError as error:
51
+ raise SystemExit(f"Phosphor needs free loopback port {port}: {error}")
52
+ PY
53
+ mkdir -p "$state/workspace"
54
+ unlink "$state/voice.ready" 2>/dev/null || :
55
+ start "$tools_python" -m sophon_harness.portal_server \
56
+ --adapters "$sources/qwen_omni_adapters" --state "$state" --workspace "$state/workspace" "${camera[@]}"
57
+ ready http://127.0.0.1:18214/api/status "${pids[-1]}" 401
58
+ if (( ${#jetson_args[@]} )); then export GGML_CUDA_DISABLE_GRAPHS=1; fi
59
+ start "$llama" --model "$weights/backplane/model-q4_k_m.gguf" --mmproj "$weights/backplane/mmproj-bf16.gguf" \
60
+ --alias phosphor --host 127.0.0.1 --port 18215 --no-webui --jinja \
61
+ --cors-origins http://127.0.0.1:18215 --no-cors-credentials --reasoning-format deepseek \
62
+ --device CUDA0 --mmproj-device CUDA0 --gpu-layers 99 --fit off --ctx-size "$context" \
63
+ --parallel 1 --cache-type-k q8_0 --cache-type-v q8_0 --flash-attn on
64
+ ready http://127.0.0.1:18215/health "${pids[-1]}"
65
+ start "$talker_python" -m sophon_harness.talker --source "$sources/sophon_realtime" \
66
+ --speech-weights "$weights/speech" "${jetson_args[@]}"
67
+ ready http://127.0.0.1:18213/health "${pids[-1]}"
68
+ start "$voice_python" -m sophon_harness.cli --token-file "$state/portal.token" \
69
+ voice --suite "$sources/fine_tuning_suite" --profile "$profile" --ornith-url http://127.0.0.1:18215 \
70
+ --ornith-model phosphor --vad "$sources/sophon_realtime/e2e/config/silero_vad.onnx" \
71
+ --source "$microphone" --sink "$speaker" --channels "$channels" --channel "$channel" --ready-file "$state/voice.ready"
72
+ wait -n
73
+ # A worker exiting normally is also a service failure when it was meant to stay up.
74
+ 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()