@simplexai/localmodels-win32-x64 0.1.0-dev.65 → 0.1.0-dev.66
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/bootstrap.identity +1 -1
- package/bootstrap.sha256 +56 -55
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/auth_proxy.py +34 -2
- package/modules/localmodels/catalog.json +500 -16
- package/modules/localmodels/custom_hub.py +54 -6
- package/modules/localmodels/custom_probe.py +28 -0
- package/modules/localmodels/debug_stub_server.py +34 -1
- package/modules/localmodels/deploy.py +33 -349
- package/modules/localmodels/download-mirrors.json +43 -3
- package/modules/localmodels/draft_spec.py +1 -1
- package/modules/localmodels/engine_adapters/__init__.py +4 -2
- package/modules/localmodels/engine_adapters/auxiliary.py +4 -1
- package/modules/localmodels/engine_adapters/llama_cpp.py +539 -0
- package/modules/localmodels/engines-b11583.json +9 -5
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +85 -1
- package/modules/localmodels/engines.json +9 -5
- package/modules/localmodels/harness_gateway.py +14 -3
- package/modules/localmodels/harness_probe.py +64 -3
- package/modules/localmodels/library_custom.py +9 -7
- package/modules/localmodels/library_elastic.py +5 -4
- package/modules/localmodels/library_jobs.py +138 -25
- package/modules/localmodels/library_model.py +22 -2
- package/modules/localmodels/library_order.py +1 -1
- package/modules/localmodels/library_serve.py +11 -4
- package/modules/localmodels/library_state.py +12 -0
- package/modules/localmodels/library_status.py +10 -0
- package/modules/localmodels/planning/budget.py +8 -3
- package/modules/localmodels/remote_ops_mirrors.py +55 -19
- package/modules/localmodels/service_deployment.py +3 -3
- package/modules/localmodels/setup_inspection.py +28 -1
- package/modules/localmodels/setup_inspection_harness.py +4 -1
- package/modules/localmodels/setup_text.py +6 -0
- package/modules/localmodels/slot_cache.py +1 -3
- package/modules/localmodels/speech_admission.py +16 -4
- package/modules/localmodels/speech_catalog.py +5 -1
- package/modules/localmodels/speech_cli.py +5 -5
- package/modules/localmodels/speech_jobs.py +101 -19
- package/modules/localmodels/speech_server.py +2 -0
- package/modules/localmodels/speech_worker_sensevoice.py +194 -6
- package/modules/localmodels/speech_workers.py +74 -6
- package/modules/localmodels/stack.py +13 -1
- package/modules/localmodels/stack_auto.py +6 -0
- package/modules/localmodels/stack_capacity.py +3 -3
- package/modules/localmodels/stack_cli.py +3 -0
- package/modules/localmodels/stack_compose.py +7 -3
- package/modules/localmodels/stack_ports.py +58 -27
- package/modules/localmodels/stack_suite.py +7 -1
- package/modules/localmodels/suite.py +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/RECORD +53 -52
- package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/NOTICE +3 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev65.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"""Isolated CPU child HTTP worker serving SenseVoice Small
|
|
1
|
+
"""Isolated CPU child HTTP worker serving sherpa-onnx ASR models (SenseVoice Small & Qwen3-ASR).
|
|
2
2
|
|
|
3
3
|
Run inside the hash-locked Python venv built from ``localmodels/speech-sv.txt``
|
|
4
4
|
(``<base_dir>/frontends/speech-sv/``) as a child of ``localmodels/speech_server.py``.
|
|
5
5
|
``sherpa_onnx`` is imported dynamically at startup so this module remains pure stdlib at
|
|
6
|
-
import time and its WAV framing and
|
|
6
|
+
import time and its WAV framing and output parsing stay unit-testable without
|
|
7
7
|
``sherpa-onnx`` installed.
|
|
8
8
|
"""
|
|
9
9
|
|
|
@@ -32,6 +32,83 @@ MAX_AUDIO_BYTES = 50 << 20 # 50 MiB bounded upload
|
|
|
32
32
|
SENSEVOICE_TAG_RE = re.compile(r"<\|([^|]+)\|>")
|
|
33
33
|
KNOWN_LANGUAGES = frozenset(("zh", "en", "ja", "ko", "yue"))
|
|
34
34
|
NO_SPEECH_TAGS = frozenset(("nospeech", "bgm"))
|
|
35
|
+
QWEN3_ASR_MAX_TOTAL_LEN = 512
|
|
36
|
+
QWEN3_ASR_MAX_NEW_TOKENS = 256
|
|
37
|
+
_LANGUAGE_TAG_RE = re.compile(r"^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$")
|
|
38
|
+
_QWEN3_LANG_PREFIX_RE = re.compile(
|
|
39
|
+
r"(?:^|\b)language\s+([A-Za-z][A-Za-z -]{0,30})\s*$", re.IGNORECASE
|
|
40
|
+
)
|
|
41
|
+
_LANGUAGE_NAME_TO_ISO: dict[str, str] = {
|
|
42
|
+
"arabic": "ar",
|
|
43
|
+
"cantonese": "yue",
|
|
44
|
+
"chinese": "zh",
|
|
45
|
+
"czech": "cs",
|
|
46
|
+
"danish": "da",
|
|
47
|
+
"dutch": "nl",
|
|
48
|
+
"english": "en",
|
|
49
|
+
"finnish": "fi",
|
|
50
|
+
"french": "fr",
|
|
51
|
+
"german": "de",
|
|
52
|
+
"greek": "el",
|
|
53
|
+
"hindi": "hi",
|
|
54
|
+
"hungarian": "hu",
|
|
55
|
+
"indonesian": "id",
|
|
56
|
+
"italian": "it",
|
|
57
|
+
"japanese": "ja",
|
|
58
|
+
"korean": "ko",
|
|
59
|
+
"macedonian": "mk",
|
|
60
|
+
"malay": "ms",
|
|
61
|
+
"mandarin": "zh",
|
|
62
|
+
"norwegian": "no",
|
|
63
|
+
"persian": "fa",
|
|
64
|
+
"polish": "pl",
|
|
65
|
+
"portuguese": "pt",
|
|
66
|
+
"romanian": "ro",
|
|
67
|
+
"russian": "ru",
|
|
68
|
+
"spanish": "es",
|
|
69
|
+
"swedish": "sv",
|
|
70
|
+
"thai": "th",
|
|
71
|
+
"turkish": "tr",
|
|
72
|
+
"ukrainian": "uk",
|
|
73
|
+
"vietnamese": "vi",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def is_valid_language_tag(value: str) -> bool:
|
|
78
|
+
"""Return True when ``value`` conforms to the speech-v1 ISO-639-1 / BCP-47 tag pattern."""
|
|
79
|
+
return bool(_LANGUAGE_TAG_RE.fullmatch(value))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def normalize_qwen3_language(raw: str) -> str:
|
|
83
|
+
"""Normalize a Qwen3-ASR language name (e.g. ``'Chinese'``) or code to ISO-639-1 / BCP-47."""
|
|
84
|
+
cleaned = raw.strip()
|
|
85
|
+
if not cleaned:
|
|
86
|
+
return ""
|
|
87
|
+
mapped = _LANGUAGE_NAME_TO_ISO.get(cleaned.lower())
|
|
88
|
+
if mapped is not None:
|
|
89
|
+
return mapped
|
|
90
|
+
parts = cleaned.split("-")
|
|
91
|
+
parts[0] = parts[0].lower()
|
|
92
|
+
candidate = "-".join(parts)
|
|
93
|
+
return candidate if is_valid_language_tag(candidate) else ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def parse_qwen3_asr_output(raw_text: str, *, raw_lang: str = "") -> tuple[str, str]:
|
|
97
|
+
"""Normalize Qwen3-ASR text and language into ``(clean_text, iso_language)``.
|
|
98
|
+
|
|
99
|
+
Strips any defensive ``language <Name><asr_text>`` prefix if present and normalizes
|
|
100
|
+
language names (such as ``"Chinese"`` or ``"English"``) to ISO-639-1 codes.
|
|
101
|
+
"""
|
|
102
|
+
lang_hint = raw_lang
|
|
103
|
+
body = raw_text
|
|
104
|
+
if "<asr_text>" in raw_text:
|
|
105
|
+
prefix, _, body = raw_text.partition("<asr_text>")
|
|
106
|
+
if not lang_hint:
|
|
107
|
+
match = _QWEN3_LANG_PREFIX_RE.search(prefix.strip())
|
|
108
|
+
if match is not None:
|
|
109
|
+
lang_hint = match.group(1)
|
|
110
|
+
cleaned = " ".join(body.split()).strip()
|
|
111
|
+
return cleaned, normalize_qwen3_language(lang_hint)
|
|
35
112
|
|
|
36
113
|
|
|
37
114
|
def parse_sensevoice_output(raw_text: str, *, raw_lang: str = "") -> tuple[str, str]:
|
|
@@ -186,6 +263,68 @@ class SenseVoiceRecognizer:
|
|
|
186
263
|
}
|
|
187
264
|
|
|
188
265
|
|
|
266
|
+
class Qwen3AsrRecognizer:
|
|
267
|
+
"""Thread-safe sherpa-onnx OfflineRecognizer wrapper for Qwen3-ASR (INT8)."""
|
|
268
|
+
|
|
269
|
+
def __init__(
|
|
270
|
+
self,
|
|
271
|
+
conv_frontend: Path,
|
|
272
|
+
encoder: Path,
|
|
273
|
+
decoder: Path,
|
|
274
|
+
tokenizer: Path,
|
|
275
|
+
*,
|
|
276
|
+
threads: int = 4,
|
|
277
|
+
max_total_len: int = QWEN3_ASR_MAX_TOTAL_LEN,
|
|
278
|
+
max_new_tokens: int = QWEN3_ASR_MAX_NEW_TOKENS,
|
|
279
|
+
) -> None:
|
|
280
|
+
_preload_windows_onnxruntime()
|
|
281
|
+
sherpa_onnx = importlib.import_module("sherpa_onnx")
|
|
282
|
+
self._recognizer: Any = sherpa_onnx.OfflineRecognizer.from_qwen3_asr(
|
|
283
|
+
conv_frontend=str(conv_frontend),
|
|
284
|
+
encoder=str(encoder),
|
|
285
|
+
decoder=str(decoder),
|
|
286
|
+
tokenizer=str(tokenizer),
|
|
287
|
+
num_threads=max(1, threads),
|
|
288
|
+
provider="cpu",
|
|
289
|
+
max_total_len=max(1, max_total_len),
|
|
290
|
+
max_new_tokens=max(1, max_new_tokens),
|
|
291
|
+
)
|
|
292
|
+
self._lock = threading.Lock()
|
|
293
|
+
|
|
294
|
+
def transcribe(
|
|
295
|
+
self,
|
|
296
|
+
samples: list[float],
|
|
297
|
+
sample_rate: int,
|
|
298
|
+
language: str = "auto",
|
|
299
|
+
) -> dict[str, object]:
|
|
300
|
+
duration = len(samples) / float(sample_rate) if sample_rate > 0 else 0.0
|
|
301
|
+
if not samples:
|
|
302
|
+
return {
|
|
303
|
+
"text": "",
|
|
304
|
+
"language": "" if language == "auto" else language,
|
|
305
|
+
"duration": 0.0,
|
|
306
|
+
"segments": [],
|
|
307
|
+
}
|
|
308
|
+
with self._lock:
|
|
309
|
+
stream = self._recognizer.create_stream()
|
|
310
|
+
stream.accept_waveform(sample_rate, samples)
|
|
311
|
+
self._recognizer.decode_stream(stream)
|
|
312
|
+
result = stream.result
|
|
313
|
+
raw_text = str(getattr(result, "text", "") or "")
|
|
314
|
+
raw_lang = str(getattr(result, "lang", "") or "")
|
|
315
|
+
text, detected = parse_qwen3_asr_output(raw_text, raw_lang=raw_lang)
|
|
316
|
+
lang_out = detected or ("" if language == "auto" else language)
|
|
317
|
+
segments: list[dict[str, object]] = (
|
|
318
|
+
[{"start": 0.0, "end": round(duration, 3), "text": text}] if text else []
|
|
319
|
+
)
|
|
320
|
+
return {
|
|
321
|
+
"text": text,
|
|
322
|
+
"language": lang_out,
|
|
323
|
+
"duration": round(duration, 3),
|
|
324
|
+
"segments": segments,
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
|
|
189
328
|
def send_json_response(
|
|
190
329
|
handler: BaseHTTPRequestHandler,
|
|
191
330
|
status: HTTPStatus,
|
|
@@ -265,15 +404,64 @@ def default_threads() -> int:
|
|
|
265
404
|
|
|
266
405
|
|
|
267
406
|
def main(argv: list[str] | None = None) -> int:
|
|
268
|
-
parser = argparse.ArgumentParser(description="
|
|
269
|
-
parser.add_argument(
|
|
270
|
-
|
|
407
|
+
parser = argparse.ArgumentParser(description="sherpa-onnx CPU speech loopback worker")
|
|
408
|
+
parser.add_argument(
|
|
409
|
+
"--arch",
|
|
410
|
+
choices=("sensevoice", "qwen3-asr"),
|
|
411
|
+
default="sensevoice",
|
|
412
|
+
help="sherpa-onnx model architecture (default: sensevoice)",
|
|
413
|
+
)
|
|
414
|
+
parser.add_argument("--model", help="path to SenseVoice model.int8.onnx")
|
|
415
|
+
parser.add_argument("--tokens", help="path to SenseVoice tokens.txt")
|
|
416
|
+
parser.add_argument("--conv-frontend", help="path to Qwen3-ASR conv_frontend.onnx")
|
|
417
|
+
parser.add_argument("--encoder", help="path to Qwen3-ASR encoder.int8.onnx")
|
|
418
|
+
parser.add_argument("--decoder", help="path to Qwen3-ASR decoder.int8.onnx")
|
|
419
|
+
parser.add_argument("--tokenizer", help="path to Qwen3-ASR tokenizer directory")
|
|
420
|
+
parser.add_argument(
|
|
421
|
+
"--max-total-len",
|
|
422
|
+
type=int,
|
|
423
|
+
default=QWEN3_ASR_MAX_TOTAL_LEN,
|
|
424
|
+
help="Qwen3-ASR KV cache sequence limit",
|
|
425
|
+
)
|
|
426
|
+
parser.add_argument(
|
|
427
|
+
"--max-new-tokens",
|
|
428
|
+
type=int,
|
|
429
|
+
default=QWEN3_ASR_MAX_NEW_TOKENS,
|
|
430
|
+
help="Qwen3-ASR max new tokens per utterance",
|
|
431
|
+
)
|
|
271
432
|
parser.add_argument("--host", default="127.0.0.1", help="loopback bind host")
|
|
272
433
|
parser.add_argument("--port", type=int, required=True, help="loopback bind port")
|
|
273
434
|
parser.add_argument("--threads", type=int, default=default_threads(), help="CPU thread count")
|
|
274
435
|
args = parser.parse_args(argv)
|
|
275
436
|
|
|
276
|
-
recognizer
|
|
437
|
+
recognizer: Recognizer
|
|
438
|
+
if args.arch == "qwen3-asr":
|
|
439
|
+
missing = [
|
|
440
|
+
flag
|
|
441
|
+
for flag, value in (
|
|
442
|
+
("--conv-frontend", args.conv_frontend),
|
|
443
|
+
("--encoder", args.encoder),
|
|
444
|
+
("--decoder", args.decoder),
|
|
445
|
+
("--tokenizer", args.tokenizer),
|
|
446
|
+
)
|
|
447
|
+
if not value
|
|
448
|
+
]
|
|
449
|
+
if missing:
|
|
450
|
+
parser.error(f"--arch qwen3-asr requires: {', '.join(missing)}")
|
|
451
|
+
recognizer = Qwen3AsrRecognizer(
|
|
452
|
+
Path(args.conv_frontend),
|
|
453
|
+
Path(args.encoder),
|
|
454
|
+
Path(args.decoder),
|
|
455
|
+
Path(args.tokenizer),
|
|
456
|
+
threads=args.threads,
|
|
457
|
+
max_total_len=args.max_total_len,
|
|
458
|
+
max_new_tokens=args.max_new_tokens,
|
|
459
|
+
)
|
|
460
|
+
else:
|
|
461
|
+
if not args.model or not args.tokens:
|
|
462
|
+
parser.error("--arch sensevoice requires: --model, --tokens")
|
|
463
|
+
recognizer = SenseVoiceRecognizer(Path(args.model), Path(args.tokens), threads=args.threads)
|
|
464
|
+
|
|
277
465
|
server = ThreadingHTTPServer((args.host, args.port), make_handler(recognizer))
|
|
278
466
|
server.daemon_threads = True
|
|
279
467
|
|
|
@@ -363,6 +363,59 @@ def sensevoice_argv(
|
|
|
363
363
|
]
|
|
364
364
|
|
|
365
365
|
|
|
366
|
+
def qwen3_asr_argv(
|
|
367
|
+
python_bin: str,
|
|
368
|
+
conv_frontend: str,
|
|
369
|
+
encoder: str,
|
|
370
|
+
decoder: str,
|
|
371
|
+
tokenizer_dir: str,
|
|
372
|
+
port: int,
|
|
373
|
+
*,
|
|
374
|
+
threads: int | None = None,
|
|
375
|
+
max_total_len: int = speech_worker_sensevoice.QWEN3_ASR_MAX_TOTAL_LEN,
|
|
376
|
+
max_new_tokens: int = speech_worker_sensevoice.QWEN3_ASR_MAX_NEW_TOKENS,
|
|
377
|
+
) -> list[str]:
|
|
378
|
+
"""Build isolated ``speech_worker_sensevoice.py`` child worker argv for Qwen3-ASR."""
|
|
379
|
+
num_threads = threads if threads is not None else min(4, max(1, os.cpu_count() or 1))
|
|
380
|
+
script = str(Path(speech_worker_sensevoice.__file__).resolve())
|
|
381
|
+
return [
|
|
382
|
+
python_bin,
|
|
383
|
+
script,
|
|
384
|
+
"--arch",
|
|
385
|
+
"qwen3-asr",
|
|
386
|
+
"--conv-frontend",
|
|
387
|
+
conv_frontend,
|
|
388
|
+
"--encoder",
|
|
389
|
+
encoder,
|
|
390
|
+
"--decoder",
|
|
391
|
+
decoder,
|
|
392
|
+
"--tokenizer",
|
|
393
|
+
tokenizer_dir,
|
|
394
|
+
"--max-total-len",
|
|
395
|
+
str(max(1, max_total_len)),
|
|
396
|
+
"--max-new-tokens",
|
|
397
|
+
str(max(1, max_new_tokens)),
|
|
398
|
+
"--host",
|
|
399
|
+
"127.0.0.1",
|
|
400
|
+
"--port",
|
|
401
|
+
str(port),
|
|
402
|
+
"--threads",
|
|
403
|
+
str(max(1, num_threads)),
|
|
404
|
+
]
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _resolve_qwen3_asr_paths(spec: SpeechModelSpec, base_dir: str) -> tuple[str, str, str, str]:
|
|
408
|
+
"""Locate ``(conv_frontend, encoder, decoder, tokenizer_dir)`` for a Qwen3-ASR model."""
|
|
409
|
+
dests = {f.path: speech_jobs.model_file_dest(base_dir, spec.id, f.path) for f in spec.files}
|
|
410
|
+
conv = next((p for rel, p in dests.items() if "conv_frontend" in rel), None)
|
|
411
|
+
enc = next((p for rel, p in dests.items() if "encoder" in rel), None)
|
|
412
|
+
dec = next((p for rel, p in dests.items() if "decoder" in rel), None)
|
|
413
|
+
vocab = next((p for rel, p in dests.items() if rel.endswith("vocab.json")), None)
|
|
414
|
+
if conv is None or enc is None or dec is None or vocab is None:
|
|
415
|
+
raise WorkerError(f"incomplete Qwen3-ASR file layout for {spec.id}")
|
|
416
|
+
return str(conv), str(enc), str(dec), str(vocab.parent)
|
|
417
|
+
|
|
418
|
+
|
|
366
419
|
class ChildWatchdog:
|
|
367
420
|
"""Binds a child worker's lifetime to this sidecar via POSIX pipe guard or Windows Job."""
|
|
368
421
|
|
|
@@ -625,7 +678,12 @@ def spawn_simulated_worker(
|
|
|
625
678
|
"PYTHONNOUSERSITE": "1",
|
|
626
679
|
"PYTHONDONTWRITEBYTECODE": "1",
|
|
627
680
|
}
|
|
628
|
-
|
|
681
|
+
if spec.engine == "whisper.cpp":
|
|
682
|
+
mode = "speech-whisper"
|
|
683
|
+
elif spec.id == "qwen3-asr-0.6b":
|
|
684
|
+
mode = "speech-qwen3-asr"
|
|
685
|
+
else:
|
|
686
|
+
mode = "speech-sensevoice"
|
|
629
687
|
argv = [
|
|
630
688
|
sys.executable,
|
|
631
689
|
"-P",
|
|
@@ -661,15 +719,18 @@ def spawn_real_worker(
|
|
|
661
719
|
elif decision.effective_device == "cpu":
|
|
662
720
|
env["CUDA_VISIBLE_DEVICES"] = ""
|
|
663
721
|
|
|
664
|
-
model_root = speech_jobs.model_dir(base_dir, spec.id)
|
|
665
722
|
if spec.engine == "whisper.cpp":
|
|
666
723
|
binary = resolve_whisper_binary(spec, decision, base_dir, state_dir)
|
|
667
|
-
model_file = str(
|
|
724
|
+
model_file = str(speech_jobs.model_file_dest(base_dir, spec.id, spec.files[0].path))
|
|
668
725
|
argv = whisper_argv(binary, model_file, port, decision.effective_device)
|
|
726
|
+
elif spec.id == "qwen3-asr-0.6b":
|
|
727
|
+
python_bin = resolve_sensevoice_python(base_dir)
|
|
728
|
+
conv_frontend, encoder, decoder, tokenizer_dir = _resolve_qwen3_asr_paths(spec, base_dir)
|
|
729
|
+
argv = qwen3_asr_argv(python_bin, conv_frontend, encoder, decoder, tokenizer_dir, port)
|
|
669
730
|
else:
|
|
670
731
|
python_bin = resolve_sensevoice_python(base_dir)
|
|
671
|
-
model_file = str(
|
|
672
|
-
tokens_file = str(
|
|
732
|
+
model_file = str(speech_jobs.model_file_dest(base_dir, spec.id, spec.files[0].path))
|
|
733
|
+
tokens_file = str(speech_jobs.model_file_dest(base_dir, spec.id, spec.files[1].path))
|
|
673
734
|
argv = sensevoice_argv(python_bin, model_file, tokens_file, port)
|
|
674
735
|
|
|
675
736
|
return _launch_worker_process(spec, decision, argv, env, port, state_dir)
|
|
@@ -779,7 +840,14 @@ def call_sensevoice_worker(
|
|
|
779
840
|
parsed = _post_worker(url, wav_data, "audio/wav", worker)
|
|
780
841
|
raw_text = str(parsed.get("text") or "")
|
|
781
842
|
raw_lang = str(parsed.get("language") or "")
|
|
782
|
-
|
|
843
|
+
if worker.model_id == "qwen3-asr-0.6b":
|
|
844
|
+
text, detected = speech_worker_sensevoice.parse_qwen3_asr_output(
|
|
845
|
+
raw_text, raw_lang=raw_lang
|
|
846
|
+
)
|
|
847
|
+
else:
|
|
848
|
+
text, detected = speech_worker_sensevoice.parse_sensevoice_output(
|
|
849
|
+
raw_text, raw_lang=raw_lang
|
|
850
|
+
)
|
|
783
851
|
lang_out = detected or ("" if language == "auto" else language)
|
|
784
852
|
dur_raw = parsed.get("duration")
|
|
785
853
|
dur_out = round(float(dur_raw), 3) if isinstance(dur_raw, int | float) else round(duration, 3)
|
|
@@ -20,6 +20,7 @@ from localmodels import (
|
|
|
20
20
|
frontend,
|
|
21
21
|
gateway,
|
|
22
22
|
harness,
|
|
23
|
+
harness_probe,
|
|
23
24
|
hosts,
|
|
24
25
|
library_convert,
|
|
25
26
|
magpie_legacy,
|
|
@@ -83,7 +84,18 @@ def build(
|
|
|
83
84
|
"""Probe this computer now, or take ``facts`` saved earlier, and compose the plan (read-only
|
|
84
85
|
apart from cached facts). With ``offline`` in the options every file's commit and SHA256 come
|
|
85
86
|
from the catalog and the Hub is asked nothing, at plan and at apply alike; a file the catalog
|
|
86
|
-
does not pin is refused.
|
|
87
|
+
does not pin is refused. Each loopback port is probed once for the whole plan
|
|
88
|
+
(harness_probe.loopback_snapshot)."""
|
|
89
|
+
with harness_probe.loopback_snapshot():
|
|
90
|
+
return _build(options, facts, approved, min_prompt_cache)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _build(
|
|
94
|
+
options: StackOptions,
|
|
95
|
+
facts: HostFacts | None,
|
|
96
|
+
approved: StackPlan | None,
|
|
97
|
+
min_prompt_cache: bool,
|
|
98
|
+
) -> StackPlan:
|
|
87
99
|
if (sys.platform == "win32" or facts is None) and (error := platform_error(sys.platform)):
|
|
88
100
|
raise StackError(error)
|
|
89
101
|
seen = app.probe(hosts.LOCAL_ID) if facts is None else facts
|
|
@@ -131,6 +131,8 @@ def strata_parts(
|
|
|
131
131
|
)
|
|
132
132
|
if check is not None:
|
|
133
133
|
check(parts, candidate_options)
|
|
134
|
+
except stack_ports.PortProbeError:
|
|
135
|
+
raise
|
|
134
136
|
except (StackError, PlanError) as exc: # PlanError: its Strata pack is not on this host
|
|
135
137
|
skipped.append(
|
|
136
138
|
f"LLM: auto passed over the smarter Strata {recipe['id']} "
|
|
@@ -267,6 +269,8 @@ def _probe_port(
|
|
|
267
269
|
) -> int:
|
|
268
270
|
try:
|
|
269
271
|
return stack_ports.llm_port(facts, merged, entry_id, listening, previous)
|
|
272
|
+
except stack_ports.PortProbeError:
|
|
273
|
+
raise
|
|
270
274
|
except (PlanError, StackError):
|
|
271
275
|
return deploy.DEFAULT_PORT
|
|
272
276
|
|
|
@@ -385,6 +389,8 @@ def llama_ram_fits(
|
|
|
385
389
|
previous,
|
|
386
390
|
price_llm,
|
|
387
391
|
)
|
|
392
|
+
except stack_ports.PortProbeError:
|
|
393
|
+
raise
|
|
388
394
|
except (PlanError, StackError):
|
|
389
395
|
return False
|
|
390
396
|
decision_ram = 0 if merged.get("defer_services") else decide.host_ram(choice)
|
|
@@ -12,6 +12,8 @@ from dataclasses import replace
|
|
|
12
12
|
from localmodels import catalog as cat
|
|
13
13
|
from localmodels import component, context_policy, gpu_specs, llm_rank, metal
|
|
14
14
|
from localmodels.context_policy import AGENT, AgentPosture, cache_floor_bytes, posture_for
|
|
15
|
+
from localmodels.deploy import DEFAULT_BASE_DIR
|
|
16
|
+
from localmodels.engine_adapters import llama_cpp
|
|
15
17
|
from localmodels.estimator import (
|
|
16
18
|
AGENT_VRAM_RESERVE_BYTES,
|
|
17
19
|
METAL_VRAM_RESERVE_BYTES,
|
|
@@ -92,8 +94,6 @@ def llm_budget(
|
|
|
92
94
|
def rows(
|
|
93
95
|
facts: HostFacts, index: int, options: StackOptions, posture: AgentPosture
|
|
94
96
|
) -> list[CapacityFit]:
|
|
95
|
-
from localmodels import deploy
|
|
96
|
-
|
|
97
97
|
gpu = device(facts, index)
|
|
98
98
|
if gpu["vendor"] != "nvidia" or gpu.get("mig_mode") == "enabled":
|
|
99
99
|
return []
|
|
@@ -109,7 +109,7 @@ def rows(
|
|
|
109
109
|
if entry.runtime != "llama.cpp" or entry.status not in ("candidate", "validated"):
|
|
110
110
|
continue
|
|
111
111
|
try:
|
|
112
|
-
|
|
112
|
+
llama_cpp.engine_plan(facts, entry, "cuda", [], [], base_dir=DEFAULT_BASE_DIR)
|
|
113
113
|
except PlanError:
|
|
114
114
|
continue
|
|
115
115
|
variant = entry.variants[-1]
|
|
@@ -221,6 +221,7 @@ _PLAN_ERROR_CODES = frozenset(
|
|
|
221
221
|
"MEMORY_INSUFFICIENT",
|
|
222
222
|
"DISK_INSUFFICIENT",
|
|
223
223
|
"GPU_CONFLICT",
|
|
224
|
+
"PORT_PROBE_FAILED",
|
|
224
225
|
}
|
|
225
226
|
)
|
|
226
227
|
_SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
|
|
@@ -229,6 +230,8 @@ _SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,
|
|
|
229
230
|
def _plan_error_payload(exc: BaseException) -> dict[str, object]:
|
|
230
231
|
"""Structured, path-free error document for ``stack plan --json`` failures."""
|
|
231
232
|
raw_code = getattr(exc, "cause_code", None)
|
|
233
|
+
if isinstance(exc, harness.HarnessError) and exc.code == "port-check-failed":
|
|
234
|
+
raw_code = "PORT_PROBE_FAILED" # the automatic Magpie address, as stack_ports ranges
|
|
232
235
|
code = (
|
|
233
236
|
raw_code
|
|
234
237
|
if isinstance(raw_code, str) and raw_code in _PLAN_ERROR_CODES
|
|
@@ -78,9 +78,13 @@ loopback_listening = stack_ports.loopback_listening
|
|
|
78
78
|
def running_record(name: str, port: int, *, finished: bool = True) -> Plan | None:
|
|
79
79
|
"""The plan of a deployment this tool finished and that still listens on its port. With
|
|
80
80
|
``finished`` False also one whose last attempt failed after it started (a retry of the same
|
|
81
|
-
approved plan owns what its first attempt left running).
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
approved plan owns what its first attempt left running). When the loopback probe cannot
|
|
82
|
+
tell, the receipt and the process's own listener (``_native_owned``) still decide."""
|
|
83
|
+
try:
|
|
84
|
+
if not loopback_listening(port):
|
|
85
|
+
return None
|
|
86
|
+
except stack_ports.PortProbeError:
|
|
87
|
+
pass
|
|
84
88
|
return next(
|
|
85
89
|
(
|
|
86
90
|
r["plan"]
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import argparse
|
|
6
6
|
from collections.abc import Callable, Sequence
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from typing import Literal
|
|
8
9
|
|
|
9
10
|
from localmodels import component, deploy, deployment_lifecycle, harness_probe, hosts
|
|
10
11
|
from localmodels.plan_envelope import PlanError
|
|
@@ -25,24 +26,43 @@ class PortUnavailableError(PlanError):
|
|
|
25
26
|
"""A bounded endpoint cannot be admitted from known-free loopback ports."""
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
"""
|
|
29
|
+
class PortProbeError(StackError):
|
|
30
|
+
"""No port of a range could be confirmed free because the loopback probe could not tell
|
|
31
|
+
for some of them (and the rest are in use). It says nothing about the model being planned,
|
|
32
|
+
so ``--llm auto`` refuses with it rather than passing over a candidate, and its cause code
|
|
33
|
+
PORT_PROBE_FAILED tells an installer to check again (setup inspect: ``port-check-failed``,
|
|
34
|
+
blocked-now)."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, message: str) -> None:
|
|
37
|
+
super().__init__(message, cause_code="PORT_PROBE_FAILED")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
PortState = Literal["free", "busy", "unknown"]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def port_state(facts: HostFacts, port: int, listening: Callable[[int], bool]) -> PortState:
|
|
44
|
+
"""Free only on known absence of every observed loopback listener; ``unknown`` when the
|
|
45
|
+
inventory or the probe cannot tell."""
|
|
30
46
|
if any(service["port"] == port for service in facts.get("llama_servers") or []):
|
|
31
|
-
return
|
|
47
|
+
return "busy"
|
|
32
48
|
services = facts.get("services")
|
|
33
49
|
for row in services.get("ports", []) if services else []:
|
|
34
50
|
if row["port"] != port:
|
|
35
51
|
continue
|
|
36
52
|
if row["listening"] is None:
|
|
37
|
-
|
|
38
|
-
f"cannot tell whether port {port} is free (listen state unknown)"
|
|
39
|
-
)
|
|
53
|
+
return "unknown"
|
|
40
54
|
if row["listening"]:
|
|
41
|
-
return
|
|
55
|
+
return "busy"
|
|
42
56
|
try:
|
|
43
|
-
return
|
|
44
|
-
except (OSError, StackError)
|
|
45
|
-
|
|
57
|
+
return "busy" if listening(port) else "free"
|
|
58
|
+
except (OSError, StackError):
|
|
59
|
+
return "unknown"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def available(facts: HostFacts, port: int, listening: Callable[[int], bool]) -> bool:
|
|
63
|
+
"""Only known absence of every observed loopback listener admits a fresh endpoint: a port
|
|
64
|
+
whose state cannot be told is not available."""
|
|
65
|
+
return port_state(facts, port, listening) == "free"
|
|
46
66
|
|
|
47
67
|
|
|
48
68
|
def default_port(
|
|
@@ -53,14 +73,28 @@ def default_port(
|
|
|
53
73
|
offset: int = 0,
|
|
54
74
|
reserved: Sequence[int] = (),
|
|
55
75
|
) -> int:
|
|
56
|
-
"""Admit a bounded single endpoint or an inseparable frontend/backend pair
|
|
76
|
+
"""Admit a bounded single endpoint or an inseparable frontend/backend pair: the first
|
|
77
|
+
candidate whose ports are all known free. A port the probe cannot tell about is skipped like
|
|
78
|
+
a busy one; only when none is known free and some could not be told is it PortProbeError."""
|
|
79
|
+
unknown = False
|
|
57
80
|
for port in candidates:
|
|
58
81
|
ports = (port, port + offset) if offset else (port,)
|
|
59
82
|
if any(value in reserved for value in ports):
|
|
60
83
|
continue
|
|
61
|
-
|
|
84
|
+
for value in ports:
|
|
85
|
+
state = port_state(facts, value, listening)
|
|
86
|
+
if state != "free":
|
|
87
|
+
unknown |= state == "unknown"
|
|
88
|
+
break
|
|
89
|
+
else:
|
|
62
90
|
return port
|
|
63
|
-
|
|
91
|
+
span = f"{candidates[0]}..{candidates[-1]}"
|
|
92
|
+
if unknown:
|
|
93
|
+
raise PortProbeError(
|
|
94
|
+
f"cannot tell whether any of ports {span} is free (the loopback check failed); "
|
|
95
|
+
"check again"
|
|
96
|
+
)
|
|
97
|
+
raise PortUnavailableError(f"default ports {span} are all in use")
|
|
64
98
|
|
|
65
99
|
|
|
66
100
|
def private_previous(
|
|
@@ -114,7 +148,7 @@ def loopback_listening(port: int) -> bool:
|
|
|
114
148
|
try:
|
|
115
149
|
return harness_probe.loopback_listening(port)
|
|
116
150
|
except OSError as exc:
|
|
117
|
-
raise
|
|
151
|
+
raise PortProbeError(str(exc)) from exc
|
|
118
152
|
|
|
119
153
|
|
|
120
154
|
def llm_port(
|
|
@@ -154,22 +188,19 @@ def llm_port(
|
|
|
154
188
|
|
|
155
189
|
if deployment_lifecycle.healthy(*stack_lifecycle.liveness(old)):
|
|
156
190
|
return port
|
|
157
|
-
|
|
158
|
-
services = facts.get("services")
|
|
159
|
-
ports = services.get("ports", []) if services else []
|
|
160
|
-
occupied.update(p["port"] for p in ports if p["listening"] is True)
|
|
161
|
-
unknown = {p["port"] for p in ports if p["listening"] is None}
|
|
191
|
+
unknown = False
|
|
162
192
|
for port in AUTO_PORTS:
|
|
163
|
-
if port in
|
|
193
|
+
if port in reserved:
|
|
164
194
|
continue
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
try:
|
|
168
|
-
busy = listening(port)
|
|
169
|
-
except OSError as exc:
|
|
170
|
-
raise StackError(f"cannot tell whether port {port} is free") from exc
|
|
171
|
-
if not busy:
|
|
195
|
+
state = port_state(facts, port, listening)
|
|
196
|
+
if state == "free":
|
|
172
197
|
return port
|
|
198
|
+
unknown |= state == "unknown"
|
|
199
|
+
if unknown:
|
|
200
|
+
raise PortProbeError(
|
|
201
|
+
"cannot tell whether any of the default LLM ports 18100..18131 is free (the "
|
|
202
|
+
"loopback check failed); check again, or pick a port with --llm-port"
|
|
203
|
+
)
|
|
173
204
|
raise StackError(
|
|
174
205
|
"default LLM ports 18100..18131 are all in use; pick a free port with --llm-port"
|
|
175
206
|
)
|
|
@@ -588,7 +588,13 @@ def aux_plans(
|
|
|
588
588
|
if frozen is not None:
|
|
589
589
|
port = frozen["service"]["port"]
|
|
590
590
|
running = previous(frozen["name"], port)
|
|
591
|
-
|
|
591
|
+
state = stack_ports.port_state(facts, port, listening)
|
|
592
|
+
if running != frozen and state == "unknown":
|
|
593
|
+
raise stack_ports.PortProbeError(
|
|
594
|
+
f"cannot tell whether the approved {label} port {port} is free; "
|
|
595
|
+
"check again"
|
|
596
|
+
)
|
|
597
|
+
if running != frozen and state == "busy":
|
|
592
598
|
raise StackError(
|
|
593
599
|
f"the approved {label} port {port} is taken by another program"
|
|
594
600
|
)
|
|
@@ -204,7 +204,7 @@ def cuda_decision_engine(
|
|
|
204
204
|
) -> ReleaseEngine:
|
|
205
205
|
"""The CUDA build of the decision models' pinned b11583 engine for this host (its Metal
|
|
206
206
|
build on a Mac), else a llama-server already here that is that build with CUDA
|
|
207
|
-
(
|
|
207
|
+
(engines.host_engine)."""
|
|
208
208
|
lock_path = engine_lock_path("b11583")
|
|
209
209
|
backend = "metal" if metal else "cuda"
|
|
210
210
|
try:
|