@simplexai/localmodels-darwin-x64 0.1.0-dev.64 → 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 +125 -121
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +2 -2
- package/modules/localmodels/approval.py +5 -3
- package/modules/localmodels/auth_proxy.py +34 -2
- package/modules/localmodels/bifrost_checks.py +2 -1
- package/modules/localmodels/catalog.json +504 -18
- package/modules/localmodels/catalog.py +2 -1
- package/modules/localmodels/catalog_recipes.py +3 -0
- package/modules/localmodels/component.py +1 -1
- package/modules/localmodels/context_policy.py +1 -1
- package/modules/localmodels/custom_hub.py +54 -6
- package/modules/localmodels/custom_probe.py +33 -5
- package/modules/localmodels/debug_stub_server.py +34 -1
- package/modules/localmodels/deploy.py +45 -285
- package/modules/localmodels/deployment_lifecycle.py +167 -0
- package/modules/localmodels/download-mirrors.json +43 -3
- package/modules/localmodels/draft_spec.py +43 -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/gateway.py +124 -13
- package/modules/localmodels/gateway_accept.py +1 -6
- package/modules/localmodels/gateway_cli.py +13 -24
- package/modules/localmodels/gateway_ops.py +185 -0
- package/modules/localmodels/gateway_server.py +3 -2
- package/modules/localmodels/harness.py +13 -16
- package/modules/localmodels/harness_core.py +4 -9
- package/modules/localmodels/harness_gateway.py +18 -6
- package/modules/localmodels/harness_probe.py +64 -3
- package/modules/localmodels/hosts.py +22 -34
- package/modules/localmodels/library_convert.py +3 -3
- package/modules/localmodels/library_custom.py +15 -13
- package/modules/localmodels/library_elastic.py +27 -13
- package/modules/localmodels/library_jobs.py +151 -28
- package/modules/localmodels/library_model.py +22 -2
- package/modules/localmodels/library_order.py +5 -4
- package/modules/localmodels/library_poly.py +2 -2
- package/modules/localmodels/library_pricing.py +34 -318
- package/modules/localmodels/library_serve.py +20 -12
- package/modules/localmodels/library_smoke.py +8 -1
- package/modules/localmodels/library_state.py +12 -0
- package/modules/localmodels/library_status.py +26 -16
- package/modules/localmodels/llm_rank.py +1 -1
- package/modules/localmodels/magpie_legacy.py +160 -0
- package/modules/localmodels/magpie_setup.py +6 -1
- package/modules/localmodels/pi_profile.py +3 -7
- package/modules/localmodels/plan_envelope.py +1 -1
- package/modules/localmodels/{budget.py → planning/budget.py} +56 -33
- package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
- package/modules/localmodels/planning/memory_pools.py +403 -0
- package/modules/localmodels/recommend.py +1 -1
- package/modules/localmodels/recommend_cli.py +3 -4
- package/modules/localmodels/remote_ops_mirrors.py +55 -19
- package/modules/localmodels/residency_host.py +1 -1
- package/modules/localmodels/service_control.py +4 -4
- package/modules/localmodels/service_deployment.py +4 -4
- package/modules/localmodels/service_wiring.py +17 -19
- package/modules/localmodels/setup_inspection.py +29 -2
- package/modules/localmodels/setup_inspection_harness.py +5 -2
- package/modules/localmodels/setup_text.py +6 -0
- package/modules/localmodels/setup_upgrade.py +3 -12
- package/modules/localmodels/slot_cache.py +1 -3
- package/modules/localmodels/speech_admission.py +17 -5
- package/modules/localmodels/speech_catalog.py +5 -1
- package/modules/localmodels/speech_cli.py +5 -5
- package/modules/localmodels/speech_jobs.py +103 -20
- package/modules/localmodels/speech_model.py +2 -0
- package/modules/localmodels/speech_server.py +132 -9
- package/modules/localmodels/speech_state.py +11 -0
- package/modules/localmodels/speech_worker_sensevoice.py +215 -19
- package/modules/localmodels/speech_workers.py +79 -7
- package/modules/localmodels/stack.py +15 -6
- package/modules/localmodels/stack_auto.py +10 -4
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_binding.py +24 -143
- package/modules/localmodels/stack_capacity.py +4 -4
- package/modules/localmodels/stack_card.py +1 -1
- package/modules/localmodels/stack_cleanup.py +3 -3
- package/modules/localmodels/stack_cli.py +3 -0
- package/modules/localmodels/stack_client_settings.py +9 -2
- package/modules/localmodels/stack_compose.py +42 -9
- package/modules/localmodels/stack_console.py +2 -2
- package/modules/localmodels/stack_debug.py +1 -1
- package/modules/localmodels/stack_decision.py +1 -1
- package/modules/localmodels/stack_doctor.py +10 -7
- package/modules/localmodels/stack_down.py +3 -3
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +3 -3
- package/modules/localmodels/stack_hardware_text.py +1 -1
- package/modules/localmodels/stack_lifecycle.py +7 -7
- package/modules/localmodels/stack_memory.py +1 -1
- package/modules/localmodels/stack_mlx.py +1 -1
- package/modules/localmodels/stack_plan.py +18 -13
- package/modules/localmodels/stack_ports.py +60 -29
- package/modules/localmodels/stack_preflight.py +4 -3
- package/modules/localmodels/stack_remove.py +13 -6
- package/modules/localmodels/stack_review.py +3 -5
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_route.py +5 -4
- package/modules/localmodels/stack_suite.py +17 -4
- package/modules/localmodels/stack_summary.py +1 -1
- package/modules/localmodels/stack_try.py +8 -13
- package/modules/localmodels/stack_up.py +10 -9
- package/modules/localmodels/stack_update.py +2 -1
- package/modules/localmodels/stack_verify.py +4 -30
- package/modules/localmodels/stack_view.py +6 -4
- package/modules/localmodels/stack_view_apply.py +2 -2
- package/modules/localmodels/stack_view_text.py +2 -6
- package/modules/localmodels/stack_view_tick.py +2 -2
- package/modules/localmodels/stack_view_words.py +5 -2
- package/modules/localmodels/stack_warm.py +1 -1
- package/modules/localmodels/suite.py +1 -1
- package/modules/localmodels/tui_views.py +11 -5
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/RECORD +122 -118
- package/modules/{simplex_localmodels-0.1.0.dev64.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/localmodels/library_vram.py +0 -123
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -202,9 +202,12 @@ def normalize_whisper_language(raw: str) -> str:
|
|
|
202
202
|
class WorkerError(RuntimeError):
|
|
203
203
|
"""Raised when an isolated speech engine child fails to start or process audio."""
|
|
204
204
|
|
|
205
|
-
def __init__(self, message: str, *, detail: str = "") -> None:
|
|
205
|
+
def __init__(self, message: str, *, detail: str = "", exit_status: int | None = None) -> None:
|
|
206
206
|
super().__init__(message)
|
|
207
207
|
self.detail = detail or message
|
|
208
|
+
# Set when the child exited on its own (before readiness or mid-request); a timeout or a
|
|
209
|
+
# launch failure leaves it None. The sidecar uses it to spot deterministic crash loops.
|
|
210
|
+
self.exit_status = exit_status
|
|
208
211
|
|
|
209
212
|
|
|
210
213
|
def is_gpu_oom_error(message: str) -> bool:
|
|
@@ -360,6 +363,59 @@ def sensevoice_argv(
|
|
|
360
363
|
]
|
|
361
364
|
|
|
362
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
|
+
|
|
363
419
|
class ChildWatchdog:
|
|
364
420
|
"""Binds a child worker's lifetime to this sidecar via POSIX pipe guard or Windows Job."""
|
|
365
421
|
|
|
@@ -474,6 +530,7 @@ def wait_worker_ready(
|
|
|
474
530
|
raise WorkerError(
|
|
475
531
|
f"{engine} worker exited with status {code}",
|
|
476
532
|
detail=tail or f"exit code {code}",
|
|
533
|
+
exit_status=code,
|
|
477
534
|
)
|
|
478
535
|
for path in paths:
|
|
479
536
|
req = urllib.request.Request(
|
|
@@ -621,7 +678,12 @@ def spawn_simulated_worker(
|
|
|
621
678
|
"PYTHONNOUSERSITE": "1",
|
|
622
679
|
"PYTHONDONTWRITEBYTECODE": "1",
|
|
623
680
|
}
|
|
624
|
-
|
|
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"
|
|
625
687
|
argv = [
|
|
626
688
|
sys.executable,
|
|
627
689
|
"-P",
|
|
@@ -657,15 +719,18 @@ def spawn_real_worker(
|
|
|
657
719
|
elif decision.effective_device == "cpu":
|
|
658
720
|
env["CUDA_VISIBLE_DEVICES"] = ""
|
|
659
721
|
|
|
660
|
-
model_root = speech_jobs.model_dir(base_dir, spec.id)
|
|
661
722
|
if spec.engine == "whisper.cpp":
|
|
662
723
|
binary = resolve_whisper_binary(spec, decision, base_dir, state_dir)
|
|
663
|
-
model_file = str(
|
|
724
|
+
model_file = str(speech_jobs.model_file_dest(base_dir, spec.id, spec.files[0].path))
|
|
664
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)
|
|
665
730
|
else:
|
|
666
731
|
python_bin = resolve_sensevoice_python(base_dir)
|
|
667
|
-
model_file = str(
|
|
668
|
-
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))
|
|
669
734
|
argv = sensevoice_argv(python_bin, model_file, tokens_file, port)
|
|
670
735
|
|
|
671
736
|
return _launch_worker_process(spec, decision, argv, env, port, state_dir)
|
|
@@ -775,7 +840,14 @@ def call_sensevoice_worker(
|
|
|
775
840
|
parsed = _post_worker(url, wav_data, "audio/wav", worker)
|
|
776
841
|
raw_text = str(parsed.get("text") or "")
|
|
777
842
|
raw_lang = str(parsed.get("language") or "")
|
|
778
|
-
|
|
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
|
+
)
|
|
779
851
|
lang_out = detected or ("" if language == "auto" else language)
|
|
780
852
|
dur_raw = parsed.get("duration")
|
|
781
853
|
dur_out = round(float(dur_raw), 3) if isinstance(dur_raw, int | float) else round(duration, 3)
|
|
@@ -20,8 +20,10 @@ from localmodels import (
|
|
|
20
20
|
frontend,
|
|
21
21
|
gateway,
|
|
22
22
|
harness,
|
|
23
|
+
harness_probe,
|
|
23
24
|
hosts,
|
|
24
25
|
library_convert,
|
|
26
|
+
magpie_legacy,
|
|
25
27
|
stack_events,
|
|
26
28
|
stack_journal,
|
|
27
29
|
stack_preflight,
|
|
@@ -82,7 +84,18 @@ def build(
|
|
|
82
84
|
"""Probe this computer now, or take ``facts`` saved earlier, and compose the plan (read-only
|
|
83
85
|
apart from cached facts). With ``offline`` in the options every file's commit and SHA256 come
|
|
84
86
|
from the catalog and the Hub is asked nothing, at plan and at apply alike; a file the catalog
|
|
85
|
-
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:
|
|
86
99
|
if (sys.platform == "win32" or facts is None) and (error := platform_error(sys.platform)):
|
|
87
100
|
raise StackError(error)
|
|
88
101
|
seen = app.probe(hosts.LOCAL_ID) if facts is None else facts
|
|
@@ -512,11 +525,7 @@ def _run_components(
|
|
|
512
525
|
wired = do.wire(
|
|
513
526
|
plan["harness"], keys["llm"], keys.get("decision") if decision_ok else None, served
|
|
514
527
|
)
|
|
515
|
-
name = (
|
|
516
|
-
"Bifrost"
|
|
517
|
-
if harness.gateway_kind(plan["harness"]["gateway"]) == "bifrost"
|
|
518
|
-
else "Magpie"
|
|
519
|
-
)
|
|
528
|
+
name = magpie_legacy.of(plan["harness"]["gateway"]).label
|
|
520
529
|
parts["gateway"] = _ok("gateway", f"{name} gateway ({state}): " + "; ".join(wired))
|
|
521
530
|
except harness.HarnessError as exc:
|
|
522
531
|
parts["gateway"] = _failed("gateway", str(exc))
|
|
@@ -22,7 +22,6 @@ from localmodels import (
|
|
|
22
22
|
preparation,
|
|
23
23
|
reuse,
|
|
24
24
|
stack_capacity,
|
|
25
|
-
stack_llm_ram,
|
|
26
25
|
stack_ports,
|
|
27
26
|
stack_suite,
|
|
28
27
|
stack_warm_store,
|
|
@@ -31,10 +30,11 @@ from localmodels import (
|
|
|
31
30
|
from localmodels import stack_aux_gpu as aux_gpu
|
|
32
31
|
from localmodels import stack_decision as decide
|
|
33
32
|
from localmodels import stack_gpu_memory as gpu_memory
|
|
34
|
-
from localmodels.budget import HARNESS_RAM, RAM_FLOOR, gpu_conflicts, host_ram
|
|
35
33
|
from localmodels.context_policy import AgentPosture
|
|
36
34
|
from localmodels.estimator import HardwareBudget
|
|
37
35
|
from localmodels.plan_envelope import PlanError
|
|
36
|
+
from localmodels.planning import llm_ram
|
|
37
|
+
from localmodels.planning.budget import HARNESS_RAM, RAM_FLOOR, gpu_conflicts, host_ram
|
|
38
38
|
from localmodels.probe import HostFacts
|
|
39
39
|
from localmodels.records import PinnedFile, Plan
|
|
40
40
|
from localmodels.stack_plan import (
|
|
@@ -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
|
|
|
@@ -354,7 +358,7 @@ def llama_ram_fits(
|
|
|
354
358
|
hf_download_endpoint=merged["hf_endpoint"],
|
|
355
359
|
hf_api_endpoint=merged["hf_endpoint"],
|
|
356
360
|
engine_path="llama-server",
|
|
357
|
-
agent=posture if mtp else replace(posture, mtp_draft_depth=0),
|
|
361
|
+
agent=posture if mtp else replace(posture, mtp_draft_depth=0, draft="off"),
|
|
358
362
|
quant=str(merged.get("quant") or ""),
|
|
359
363
|
),
|
|
360
364
|
entries=entries,
|
|
@@ -385,12 +389,14 @@ 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)
|
|
391
397
|
min_cache_bytes = (posture.prompt_cache_min_mib << 20) if posture.prompt_cache_mib > 0 else 0
|
|
392
398
|
needed = (
|
|
393
|
-
|
|
399
|
+
llm_ram.own_bytes(final_llm, entries, running=False, metal=False)
|
|
394
400
|
+ min_cache_bytes
|
|
395
401
|
+ decision_ram
|
|
396
402
|
+ HARNESS_RAM
|
|
@@ -14,9 +14,9 @@ from dataclasses import replace
|
|
|
14
14
|
|
|
15
15
|
from localmodels import component, hosts, metal, suite
|
|
16
16
|
from localmodels import stack_decision as decide
|
|
17
|
-
from localmodels.budget import gib
|
|
18
17
|
from localmodels.engine_adapters import suite_plan
|
|
19
18
|
from localmodels.plan_envelope import PlanError
|
|
19
|
+
from localmodels.planning.budget import gib
|
|
20
20
|
from localmodels.probe import GPU, HostFacts
|
|
21
21
|
from localmodels.records import Plan
|
|
22
22
|
from localmodels.stack_plan import HARNESS_RAM, DecisionChoice, ram_floor
|
|
@@ -9,7 +9,16 @@ import sys
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import TypedDict, cast
|
|
11
11
|
|
|
12
|
-
from localmodels import
|
|
12
|
+
from localmodels import (
|
|
13
|
+
deployment_lifecycle,
|
|
14
|
+
gateway_ops,
|
|
15
|
+
harness,
|
|
16
|
+
harness_core,
|
|
17
|
+
hosts,
|
|
18
|
+
runtime_discovery,
|
|
19
|
+
stack,
|
|
20
|
+
stack_run,
|
|
21
|
+
)
|
|
13
22
|
from localmodels import stack_lifecycle as lifecycle
|
|
14
23
|
from localmodels.setup_text import Lang, text
|
|
15
24
|
from localmodels.stack_plan import StackPlan, deployments
|
|
@@ -44,22 +53,6 @@ def _windows() -> bool:
|
|
|
44
53
|
return os.name == "nt"
|
|
45
54
|
|
|
46
55
|
|
|
47
|
-
def _same_path(left: str | Path, right: str | Path) -> bool:
|
|
48
|
-
return os.path.normcase(os.path.normpath(os.path.expanduser(str(left)))) == os.path.normcase(
|
|
49
|
-
os.path.normpath(os.path.expanduser(str(right)))
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def _same_real_path(left: str | Path, right: str | Path) -> bool:
|
|
54
|
-
return os.path.normcase(os.path.realpath(left)) == os.path.normcase(os.path.realpath(right))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _with_path(env: dict[str, str], prefixes: list[str]) -> dict[str, str]:
|
|
58
|
-
merged = {key: value for key, value in env.items() if key.upper() != "PATH"}
|
|
59
|
-
merged["PATH"] = os.pathsep.join([*prefixes, os.environ.get("PATH", "")])
|
|
60
|
-
return merged
|
|
61
|
-
|
|
62
|
-
|
|
63
56
|
def _reparse_point(info: os.stat_result) -> bool:
|
|
64
57
|
return bool(getattr(info, "st_file_attributes", 0) & _REPARSE_POINT)
|
|
65
58
|
|
|
@@ -175,107 +168,30 @@ def _deployments_ready(
|
|
|
175
168
|
service = part["service"]
|
|
176
169
|
if (
|
|
177
170
|
not entry
|
|
178
|
-
or entry
|
|
171
|
+
or deployment_lifecycle.is_removed(entry)
|
|
179
172
|
or entry["service"] != service["name"]
|
|
180
173
|
or entry["kind"] != service["kind"]
|
|
181
174
|
# The manifest records the expanded directory (hosts.own_deployment); a plan on
|
|
182
175
|
# the default base directory names it under "~".
|
|
183
|
-
or not
|
|
176
|
+
or not gateway_ops.same_path(entry["deploy_dir"], service["deploy_dir"])
|
|
184
177
|
or entry["port"] != service["port"]
|
|
185
178
|
):
|
|
186
179
|
return False
|
|
187
180
|
return True
|
|
188
181
|
|
|
189
182
|
|
|
190
|
-
def _bifrost_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBinding | Reason:
|
|
191
|
-
from localmodels import bifrost_pi, gateway_bifrost
|
|
192
|
-
|
|
193
|
-
gateway = plan["harness"]["gateway"]
|
|
194
|
-
record = owned["gateway"].get("bifrost")
|
|
195
|
-
if (
|
|
196
|
-
not record
|
|
197
|
-
or record["addr"] != gateway["addr"]
|
|
198
|
-
# an instance still on an earlier pinned binary is not the approved plan until apply
|
|
199
|
-
# restarts it
|
|
200
|
-
or not _same_path(record["binary"], harness.tool_path(plan["harness"], "bifrost"))
|
|
201
|
-
or not owned["pi"]
|
|
202
|
-
or owned["pi"]["model"] != gateway["pi_model"]
|
|
203
|
-
):
|
|
204
|
-
return _reason("gateway-ownership", lang)
|
|
205
|
-
try:
|
|
206
|
-
if gateway_bifrost.require_target(plan["harness"]) != record:
|
|
207
|
-
raise harness.HarnessError("Bifrost record changed")
|
|
208
|
-
except harness.HarnessError:
|
|
209
|
-
return _reason("gateway-ownership", lang, "gateway-record")
|
|
210
|
-
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
211
|
-
profile = bifrost_pi.pi_profile(harness_core.gateway_environment(plan["harness"]))
|
|
212
|
-
if not executable.is_absolute() or not profile.is_absolute():
|
|
213
|
-
raise ValueError("Pi paths must be absolute")
|
|
214
|
-
fingerprint = _profile_fingerprint(executable, profile)
|
|
215
|
-
if (
|
|
216
|
-
not gateway_bifrost.owned_listener(record)
|
|
217
|
-
or not gateway_bifrost.healthy(gateway["addr"])
|
|
218
|
-
or bifrost_pi.pi_model(profile) != (gateway["pi_model"])
|
|
219
|
-
):
|
|
220
|
-
return _reason("gateway-unavailable", lang)
|
|
221
|
-
env = {**harness_core.gateway_environment(plan["harness"]), "PI_CODING_AGENT_DIR": str(profile)}
|
|
222
|
-
listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
|
|
223
|
-
expected = gateway["pi_model"].split("/", 1)
|
|
224
|
-
if listed.returncode != 0 or not any(
|
|
225
|
-
len(fields) >= 2 and fields[:2] == expected
|
|
226
|
-
for fields in (line.split() for line in listed.stdout.splitlines())
|
|
227
|
-
):
|
|
228
|
-
return _reason("pi-model-unavailable", lang)
|
|
229
|
-
if _profile_fingerprint(executable, profile) != fingerprint:
|
|
230
|
-
return _reason("pi-config-changed", lang)
|
|
231
|
-
return {
|
|
232
|
-
"executable": str(executable),
|
|
233
|
-
"environment": {"PI_CODING_AGENT_DIR": str(profile)},
|
|
234
|
-
"configFingerprint": fingerprint,
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
183
|
def _pi_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBinding | Reason:
|
|
239
184
|
gateway = plan["harness"]["gateway"]
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
owned["gateway"]["group"] != gateway["group"]
|
|
244
|
-
or not owned["pi"]
|
|
245
|
-
or owned["pi"]["model"] != gateway["pi_model"]
|
|
246
|
-
):
|
|
247
|
-
return _reason("gateway-ownership", lang)
|
|
185
|
+
ops = gateway_ops.of(gateway)
|
|
186
|
+
if refusal := ops.pi_owner(plan["harness"], owned):
|
|
187
|
+
return _reason(refusal[0], lang, refusal[1])
|
|
248
188
|
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
249
|
-
profile =
|
|
250
|
-
harness_core.gateway_environment(plan["harness"])["PI_CODING_AGENT_DIR"]
|
|
251
|
-
).expanduser()
|
|
189
|
+
profile = ops.pi_profile(plan["harness"])
|
|
252
190
|
if not executable.is_absolute() or not profile.is_absolute():
|
|
253
191
|
raise ValueError("Pi paths must be absolute")
|
|
254
192
|
fingerprint = _profile_fingerprint(executable, profile)
|
|
255
|
-
|
|
256
|
-
env
|
|
257
|
-
**_with_path(
|
|
258
|
-
harness.checked_gateway_environment(plan["harness"]),
|
|
259
|
-
[str(executable.parent), str(Path(magpie).parent)],
|
|
260
|
-
),
|
|
261
|
-
"MAGPIE_ADDR": gateway["addr"],
|
|
262
|
-
"PI_CODING_AGENT_DIR": str(profile),
|
|
263
|
-
}
|
|
264
|
-
state = harness.inspect(
|
|
265
|
-
env=env,
|
|
266
|
-
tools_dir=plan["harness"]["tools_dir"],
|
|
267
|
-
approved=plan["harness"],
|
|
268
|
-
private_clients=True,
|
|
269
|
-
)
|
|
270
|
-
if (
|
|
271
|
-
not state["gateway_up"]
|
|
272
|
-
or state.get("gateway_other_user")
|
|
273
|
-
or not state["pi"]
|
|
274
|
-
or not state["magpie"]
|
|
275
|
-
or not _same_real_path(state["magpie"], magpie)
|
|
276
|
-
or not _same_real_path(state["pi"], executable)
|
|
277
|
-
or state["pi_model"] != gateway["pi_model"]
|
|
278
|
-
):
|
|
193
|
+
env = ops.pi_env(plan["harness"], owned, executable, profile)
|
|
194
|
+
if env is None:
|
|
279
195
|
return _reason("gateway-unavailable", lang)
|
|
280
196
|
listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
|
|
281
197
|
expected = gateway["pi_model"].split("/", 1)
|
|
@@ -316,55 +232,20 @@ def _library_binding(
|
|
|
316
232
|
unpoints pi when the last stack LLM leaves, so pi's selection is not checked. The gateway
|
|
317
233
|
still is while anything the library did not adopt (the decision model, foundation
|
|
318
234
|
services, the other LLM) routes through it."""
|
|
319
|
-
from localmodels import
|
|
235
|
+
from localmodels import stack_verify
|
|
320
236
|
|
|
321
237
|
if not _stack_installed(plan, owned):
|
|
322
238
|
return _reason("deployment-unavailable", lang)
|
|
323
|
-
|
|
239
|
+
ops = gateway_ops.of(plan["harness"]["gateway"])
|
|
324
240
|
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
325
|
-
|
|
326
|
-
# The profile the stack's own binding reads: a Magpie plan on a shared daemon has none
|
|
327
|
-
# (KeyError, unavailable), never the user's ~/.pi/agent.
|
|
328
|
-
profile = (
|
|
329
|
-
bifrost_pi.pi_profile(environment)
|
|
330
|
-
if harness.gateway_kind(gateway) == "bifrost"
|
|
331
|
-
else Path(environment["PI_CODING_AGENT_DIR"]).expanduser()
|
|
332
|
-
)
|
|
241
|
+
profile = ops.pi_profile(plan["harness"])
|
|
333
242
|
if not executable.is_absolute() or not profile.is_absolute():
|
|
334
243
|
raise ValueError("Pi paths must be absolute")
|
|
335
244
|
fingerprint = _profile_fingerprint(executable, profile)
|
|
336
245
|
unadopted = any(component not in adopted for component, _ in stack_verify.parts(plan))
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if unadopted or pi_points_magpie:
|
|
341
|
-
if harness.gateway_kind(gateway) == "bifrost":
|
|
342
|
-
record = owned["gateway"].get("bifrost")
|
|
343
|
-
if not record or record["addr"] != gateway["addr"]:
|
|
344
|
-
return _reason("gateway-ownership", lang)
|
|
345
|
-
if not gateway_bifrost.owned_listener(record) or not gateway_bifrost.healthy(
|
|
346
|
-
gateway["addr"]
|
|
347
|
-
):
|
|
348
|
-
return _reason("gateway-unavailable", lang)
|
|
349
|
-
else:
|
|
350
|
-
if unadopted and owned["gateway"]["group"] != gateway["group"]:
|
|
351
|
-
return _reason("gateway-ownership", lang)
|
|
352
|
-
magpie = harness.tool_path(plan["harness"], "magpie")
|
|
353
|
-
env = {
|
|
354
|
-
**_with_path(
|
|
355
|
-
harness.checked_gateway_environment(plan["harness"]),
|
|
356
|
-
[str(Path(magpie).parent)],
|
|
357
|
-
),
|
|
358
|
-
"MAGPIE_ADDR": gateway["addr"],
|
|
359
|
-
}
|
|
360
|
-
state = harness.inspect(
|
|
361
|
-
env=env,
|
|
362
|
-
tools_dir=plan["harness"]["tools_dir"],
|
|
363
|
-
approved=plan["harness"],
|
|
364
|
-
private_clients=True,
|
|
365
|
-
)
|
|
366
|
-
if not state["gateway_up"] or state.get("gateway_other_user"):
|
|
367
|
-
return _reason("gateway-unavailable", lang)
|
|
246
|
+
if unadopted or ops.pi_on_previous(profile):
|
|
247
|
+
if refusal := ops.library_refusal(plan["harness"], owned, unadopted):
|
|
248
|
+
return _reason(refusal, lang)
|
|
368
249
|
if _profile_fingerprint(executable, profile) != fingerprint:
|
|
369
250
|
return _reason("pi-config-changed", lang)
|
|
370
251
|
return {
|
|
@@ -11,8 +11,9 @@ from dataclasses import replace
|
|
|
11
11
|
|
|
12
12
|
from localmodels import catalog as cat
|
|
13
13
|
from localmodels import component, context_policy, gpu_specs, llm_rank, metal
|
|
14
|
-
from localmodels.budget import gib
|
|
15
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
|
|
16
17
|
from localmodels.estimator import (
|
|
17
18
|
AGENT_VRAM_RESERVE_BYTES,
|
|
18
19
|
METAL_VRAM_RESERVE_BYTES,
|
|
@@ -20,6 +21,7 @@ from localmodels.estimator import (
|
|
|
20
21
|
PhysicsRefusal,
|
|
21
22
|
)
|
|
22
23
|
from localmodels.plan_envelope import PlanError
|
|
24
|
+
from localmodels.planning.budget import gib
|
|
23
25
|
from localmodels.probe import GPU, HostFacts
|
|
24
26
|
from localmodels.stack_plan import CapacityFit, Hardware, StackOptions
|
|
25
27
|
|
|
@@ -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]
|
|
@@ -14,7 +14,7 @@ from html import escape
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
|
|
16
16
|
from localmodels import cli_help, stack_run, stack_up, stack_view_llm, stack_warm, suite
|
|
17
|
-
from localmodels.budget import gib
|
|
17
|
+
from localmodels.planning.budget import gib
|
|
18
18
|
from localmodels.stack_plan import StackError, StackPlan
|
|
19
19
|
|
|
20
20
|
|
|
@@ -21,8 +21,8 @@ import sys
|
|
|
21
21
|
from collections.abc import Callable, Iterable, Iterator
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
|
|
24
|
-
from localmodels import deploy, hosts
|
|
25
|
-
from localmodels.budget import gib
|
|
24
|
+
from localmodels import deploy, deployment_lifecycle, hosts
|
|
25
|
+
from localmodels.planning.budget import gib
|
|
26
26
|
from localmodels.stack_plan import StackError, platform_error
|
|
27
27
|
|
|
28
28
|
Out = Callable[[str], None]
|
|
@@ -293,7 +293,7 @@ def without_others_archives(doc: hosts.Owned, taken: set[str], out: Out) -> host
|
|
|
293
293
|
theirs = {
|
|
294
294
|
Path(os.path.expanduser(d["deploy_dir"])).parent.parent
|
|
295
295
|
for name, d in doc["deployments"].items()
|
|
296
|
-
if name not in taken and
|
|
296
|
+
if name not in taken and deployment_lifecycle.holds_service(d)
|
|
297
297
|
}
|
|
298
298
|
kept = [a for a in doc["archives"] if any(base in Path(a).parents for base in theirs)]
|
|
299
299
|
if not kept:
|
|
@@ -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
|
|
@@ -12,7 +12,14 @@ import argparse
|
|
|
12
12
|
import json
|
|
13
13
|
import urllib.parse
|
|
14
14
|
|
|
15
|
-
from localmodels import
|
|
15
|
+
from localmodels import (
|
|
16
|
+
bifrost_models,
|
|
17
|
+
gateway_bifrost,
|
|
18
|
+
hosts,
|
|
19
|
+
magpie_legacy,
|
|
20
|
+
stack_update,
|
|
21
|
+
vision,
|
|
22
|
+
)
|
|
16
23
|
from localmodels.bifrost_models import StackClients
|
|
17
24
|
from localmodels.stack_plan import StackError, command
|
|
18
25
|
|
|
@@ -36,7 +43,7 @@ def settings(base: str | None = None) -> StackClients:
|
|
|
36
43
|
f" {command()} install"
|
|
37
44
|
)
|
|
38
45
|
gw = plan["harness"]["gateway"]
|
|
39
|
-
if
|
|
46
|
+
if magpie_legacy.of(gw).legacy:
|
|
40
47
|
raise StackError(
|
|
41
48
|
f"the installed stack (plan {plan['plan_id'][:12]}) runs on Magpie; stack clients"
|
|
42
49
|
" describes a stack on this tool's Bifrost (plan it with --gateway bifrost)"
|