@simplexai/localmodels-darwin-x64 0.1.0-dev.59 → 0.1.0-dev.60

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.
Files changed (87) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +79 -73
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +104 -43
  5. package/modules/localmodels/apple_sensors.py +431 -0
  6. package/modules/localmodels/bifrost_admin.py +30 -0
  7. package/modules/localmodels/bifrost_checks.py +2 -2
  8. package/modules/localmodels/bifrost_config.py +132 -9
  9. package/modules/localmodels/bifrost_models.py +1 -1
  10. package/modules/localmodels/catalog.json +146 -54
  11. package/modules/localmodels/catalog.py +20 -3
  12. package/modules/localmodels/catalog_add.py +42 -11
  13. package/modules/localmodels/custom_hub.py +983 -0
  14. package/modules/localmodels/custom_hub_http.py +579 -0
  15. package/modules/localmodels/custom_probe.py +451 -0
  16. package/modules/localmodels/deploy.py +27 -5
  17. package/modules/localmodels/deploy_steps.py +5 -0
  18. package/modules/localmodels/download-mirrors.json +8 -0
  19. package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
  20. package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
  21. package/modules/localmodels/engines.py +38 -8
  22. package/modules/localmodels/estimator.py +60 -7
  23. package/modules/localmodels/gateway.py +48 -3
  24. package/modules/localmodels/gateway_app_bifrost.py +4 -4
  25. package/modules/localmodels/gateway_bifrost.py +98 -15
  26. package/modules/localmodels/gguf.py +6 -0
  27. package/modules/localmodels/host_sensors.py +704 -0
  28. package/modules/localmodels/library_cli.py +181 -3
  29. package/modules/localmodels/library_custom.py +831 -0
  30. package/modules/localmodels/library_elastic.py +35 -7
  31. package/modules/localmodels/library_gateway.py +94 -32
  32. package/modules/localmodels/library_jobs.py +76 -11
  33. package/modules/localmodels/library_kept.py +50 -6
  34. package/modules/localmodels/library_model.py +254 -2
  35. package/modules/localmodels/library_pricing.py +83 -4
  36. package/modules/localmodels/library_serve.py +112 -50
  37. package/modules/localmodels/library_smoke.py +315 -0
  38. package/modules/localmodels/library_state.py +77 -1
  39. package/modules/localmodels/library_status.py +126 -4
  40. package/modules/localmodels/nvml_ctypes.py +431 -0
  41. package/modules/localmodels/plan_envelope.py +14 -6
  42. package/modules/localmodels/records.py +1 -0
  43. package/modules/localmodels/remote_ops.py +53 -5
  44. package/modules/localmodels/remote_ops_download.py +168 -29
  45. package/modules/localmodels/remote_ops_ranges.py +2 -5
  46. package/modules/localmodels/remote_ops_service.py +2 -1
  47. package/modules/localmodels/remote_ops_verify.py +22 -5
  48. package/modules/localmodels/runtime-lock.json +19 -19
  49. package/modules/localmodels/service_control.py +32 -1
  50. package/modules/localmodels/service_wiring.py +2 -3
  51. package/modules/localmodels/service_worker.py +6 -2
  52. package/modules/localmodels/services_cli.py +35 -27
  53. package/modules/localmodels/source_byok.py +3 -5
  54. package/modules/localmodels/stack_lifecycle.py +2 -2
  55. package/modules/localmodels/stack_memory.py +1 -0
  56. package/modules/localmodels/stack_view.py +77 -53
  57. package/modules/localmodels/stack_view_demo.py +36 -5
  58. package/modules/localmodels/stack_view_events.py +147 -12
  59. package/modules/localmodels/stack_view_gpu.py +97 -17
  60. package/modules/localmodels/stack_view_llm.py +15 -0
  61. package/modules/localmodels/stack_view_measure.py +4 -1
  62. package/modules/localmodels/stack_view_schema.py +54 -8
  63. package/modules/localmodels/stack_view_serve.py +40 -3
  64. package/modules/localmodels/stack_view_slots.py +89 -10
  65. package/modules/localmodels/stack_view_telemetry.py +163 -0
  66. package/modules/localmodels/stack_view_text.py +5 -2
  67. package/modules/localmodels/stack_view_tick.py +658 -0
  68. package/modules/localmodels/stack_view_words.py +4 -0
  69. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.5.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
  70. package/modules/localmodels/suite.py +3 -1
  71. package/modules/localmodels/telemetry_math.py +538 -0
  72. package/modules/localmodels/web/view/view.js +1 -1
  73. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
  74. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +76 -70
  75. package/package.json +1 -1
  76. package/tool.json +1 -1
  77. package/modules/localmodels/bifrost_datasheet.py +0 -53
  78. package/modules/localmodels/bifrost_provider.py +0 -88
  79. package/modules/localmodels/bifrost_unit.py +0 -99
  80. package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +0 -94
  81. package/modules/localmodels/gateway_switch.py +0 -51
  82. package/modules/localmodels/library_floor.py +0 -78
  83. package/modules/localmodels/service_stop.py +0 -52
  84. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
  85. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
  86. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
  87. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1,53 +0,0 @@
1
- """The model datasheets of the stack's Bifrost, written beside its config at each wiring.
2
-
3
- Bifrost states a listed model's window (``/v1/models`` ``context_length``) only from a row of its
4
- pricing datasheet. On an empty config store, which every config change leaves, it loads that
5
- sheet and the model-parameters sheet before it answers, and exits when either cannot be read.
6
- Its defaults live on getbifrost.ai, describe cloud models only and need the network, so the
7
- stack's Bifrost reads both from these files instead: the LLM's names with the window this
8
- deployment launches it with, and no per-model parameters (nothing is dropped from a request).
9
- Nor does it fetch its MCP server library, which only the admin UI's catalog shows.
10
- """
11
-
12
- from __future__ import annotations
13
-
14
- import os
15
- from collections.abc import Iterable
16
- from pathlib import Path
17
- from typing import Any
18
-
19
- DATASHEET = "datasheet.json"
20
- PARAMETERS = "model-parameters.json"
21
- FILES = (DATASHEET, PARAMETERS)
22
-
23
-
24
- def file_url(app: Path, name: str, windows: bool = os.name == "nt") -> str:
25
- """A file URL for a sheet in ``app`` that Bifrost can open. Bifrost reads a file URL's path
26
- as it stands, so ``file:///C:/x/datasheet.json`` is ``/C:/x/...`` on Windows, which does
27
- not open, and Bifrost exits at start (dev38 Windows library load). On Windows the URL is
28
- relative to its working directory, ``app`` (gateway_bifrost._start, the only way Bifrost
29
- runs there); elsewhere absolute, as a systemd unit's working directory is not ``app``."""
30
- return f"file:./{name}" if windows else (app / name).as_uri()
31
-
32
-
33
- def framework(app: Path) -> dict[str, Any]:
34
- """config.json's ``framework``: the datasheets from ``app``, and no MCP library sync (0 is
35
- Bifrost's off switch; any other interval fetches it)."""
36
- return {
37
- "pricing": {
38
- "pricing_url": file_url(app, DATASHEET),
39
- "model_parameters_url": file_url(app, PARAMETERS),
40
- "mcp_library_sync_interval": 0,
41
- }
42
- }
43
-
44
-
45
- def sheets(provider: str, names: Iterable[str], context: int | None) -> dict[str, Any]:
46
- """The files ``framework`` names. One pricing row per name the LLM's key lists, keyed as
47
- Bifrost looks rows up (provider, the name after the first slash, a mode), with the window the
48
- LLM launches with (``-c``; one request may fill it); a plan without a window has none."""
49
- row = {"provider": provider, "mode": "chat", "context_length": context}
50
- return {
51
- DATASHEET: {f"{provider}/{name}": row for name in names} if context else {},
52
- PARAMETERS: {},
53
- }
@@ -1,88 +0,0 @@
1
- """Bifrost provider configuration shared by stack and standalone app gateways."""
2
-
3
- from __future__ import annotations
4
-
5
- import ipaddress
6
- import urllib.parse
7
- from typing import Any
8
-
9
- from localmodels import harness
10
-
11
- # Loopback upstreams (llama-server uses cpp-httplib's 5 s keep-alive timeout; auth_proxy fronts
12
- # local services) sit on 127.0.0.1 where a fresh dial costs microseconds, while Bifrost's
13
- # fasthttp pool defaults to a 30 s idle timeout and its StaleConnectionRetryIfErr only matches
14
- # POSIX "broken pipe" / "connection reset by peer", not Windows Winsock WSAECONNABORTED (10053)
15
- # or WSAECONNRESET (10054). Closing loopback connections after each response, capping idle
16
- # keep-alive below 5 s, and allowing 2 fast retries on pre-response transport failures prevents
17
- # Windows 502 wsasend aborts (evidence/2026-11-19-linger-agentic-batch1/REPORT.md, Issue #3).
18
- LOOPBACK_KEEP_ALIVE_S = 2
19
- LOOPBACK_MAX_RETRIES = 2
20
- LOOPBACK_RETRY_INITIAL_MS = 100
21
- LOOPBACK_RETRY_MAX_MS = 500
22
-
23
- # What each provider may be asked: everything else Bifrost refuses before it reaches the
24
- # service. The LLM speaks chat only, so Bifrost turns Responses (Codex) and Anthropic Messages
25
- # (Claude Code) requests into chat completions instead of calling /v1/responses upstream.
26
- _ALLOWED = {
27
- "llm": {"list_models": True, "chat_completion": True, "chat_completion_stream": True},
28
- "decision": {"list_models": True, "decisions": True},
29
- "embedding": {"list_models": True, "embedding": True},
30
- # Bifrost's openai-type rerank sends documents as {"text": ...} objects, which llama-server
31
- # refuses; its cohere type sends the plain strings llama-server reads.
32
- "rerank": {"rerank": True},
33
- "stt": {"list_models": True, "transcription": True, "transcription_stream": True},
34
- }
35
- _BASE_TYPE = {"decision": "typesafe", "rerank": "cohere"}
36
-
37
-
38
- def _is_loopback(url: str) -> bool:
39
- host = (urllib.parse.urlsplit(url).hostname or "").strip().lower()
40
- if host == "localhost":
41
- return True
42
- try:
43
- return ipaddress.ip_address(host).is_loopback
44
- except ValueError:
45
- return False
46
-
47
-
48
- def render(role: str, url: str, model: str, key: str, pid: str) -> dict[str, Any]:
49
- custom: dict[str, Any] = {
50
- "base_provider_type": _BASE_TYPE.get(role, "openai"),
51
- "allowed_requests": _ALLOWED[role],
52
- }
53
- if role == "rerank":
54
- custom["request_path_overrides"] = {"rerank": "/v1/rerank"}
55
- entry: dict[str, Any] = {"id": pid, "name": pid, "value": key, "models": [model], "weight": 1}
56
- if role == "llm":
57
- # Bifrost v2.3.0 lists (/v1/models as <pid>/<name>, /anthropic/v1/models bare) and routes
58
- # a name only when the key has it in both ``models`` and ``aliases``; either alone does not.
59
- entry["models"] = [model, harness.GROUP]
60
- entry["aliases"] = {harness.GROUP: model}
61
- network_config: dict[str, Any] = {
62
- "base_url": origin(url),
63
- "allow_private_network": True,
64
- "max_retries": 0,
65
- "default_request_timeout_in_seconds": 600,
66
- "stream_idle_timeout_in_seconds": 600,
67
- }
68
- if _is_loopback(url):
69
- network_config.update(
70
- {
71
- "max_retries": LOOPBACK_MAX_RETRIES,
72
- "retry_backoff_initial": LOOPBACK_RETRY_INITIAL_MS,
73
- "retry_backoff_max": LOOPBACK_RETRY_MAX_MS,
74
- "keep_alive_timeout_in_seconds": LOOPBACK_KEEP_ALIVE_S,
75
- "extra_headers": {"Connection": "close"},
76
- }
77
- )
78
- return {
79
- "keys": [entry],
80
- "network_config": network_config,
81
- "custom_provider_config": custom,
82
- }
83
-
84
-
85
- def origin(url: str) -> str:
86
- """Bifrost appends the API path (/v1/...) to a provider's base URL itself."""
87
- url = url.rstrip("/")
88
- return url[: -len("/v1")] if url.endswith("/v1") else url
@@ -1,99 +0,0 @@
1
- """The systemd --user unit of the stack's Bifrost instance: its name, text and the retirement of
2
- the untagged unit every install shared before 2026-11-10."""
3
-
4
- from __future__ import annotations
5
-
6
- import os
7
- import subprocess
8
- from collections.abc import Callable
9
- from pathlib import Path
10
-
11
- from localmodels import harness, hosts, plan_envelope
12
- from localmodels.harness import HarnessError
13
-
14
- LEGACY_UNIT = "localmodels-gateway" # the one name every install shared before 2026-11-10
15
- UNIT_DIR = harness.UNIT_DIR
16
-
17
- Systemctl = Callable[..., "subprocess.CompletedProcess[str]"]
18
-
19
-
20
- def unit_for(app: Path) -> str:
21
- """``localmodels-<tag>-gateway``, the tag naming the directory the instance runs from."""
22
- return f"localmodels-{plan_envelope.root_tag(str(app))}-gateway"
23
-
24
-
25
- def unit(record: hosts.OwnedBifrost) -> str:
26
- """The unit a record's instance runs under; records from before the tag name the old one."""
27
- return record.get("unit") or LEGACY_UNIT
28
-
29
-
30
- def unit_file(name: str) -> Path:
31
- return Path(os.path.expanduser(UNIT_DIR)) / f"{name}.service"
32
-
33
-
34
- def text(binary: str, app: Path, addr: str) -> str:
35
- host, _, port = addr.rpartition(":")
36
- return (
37
- "# localmodels: Bifrost gateway of the local stack; stack remove deletes this unit\n"
38
- "[Unit]\n"
39
- "Description=localmodels Bifrost gateway\n"
40
- "After=network.target\n\n"
41
- "[Service]\n"
42
- f"WorkingDirectory={app}\n"
43
- "Environment=NO_PROXY=127.0.0.1,localhost no_proxy=127.0.0.1,localhost\n"
44
- f"ExecStart={binary} -app-dir {app} -host {host} -port {port} -log-style json "
45
- "-log-level warn\n"
46
- "Restart=on-failure\n"
47
- "RestartSec=5\n"
48
- "UMask=0077\n\n"
49
- "[Install]\n"
50
- "WantedBy=default.target\n"
51
- )
52
-
53
-
54
- def retire_legacy(name: str, app: Path, systemctl: Systemctl) -> None:
55
- """Stop, disable and delete the untagged unit when it runs this instance's directory; a unit
56
- of that name running any other directory belongs to another install and is kept."""
57
- old = unit_file(LEGACY_UNIT)
58
- if name == LEGACY_UNIT or old.is_symlink() or not old.is_file():
59
- return
60
- try:
61
- body = old.read_text(encoding="utf-8")
62
- except (OSError, UnicodeDecodeError):
63
- return
64
- if old.stat().st_uid != os.getuid() or f" -app-dir {app} -host " not in body:
65
- return
66
- if systemctl("disable", "--now", f"{LEGACY_UNIT}.service").returncode != 0:
67
- raise HarnessError(f"systemctl --user disable --now {LEGACY_UNIT} failed")
68
- old.unlink()
69
- systemctl("daemon-reload")
70
-
71
-
72
- def require_owned(record: hosts.OwnedBifrost, path: Path, systemctl: Systemctl) -> None:
73
- """Require both the private unit's exact content and systemd's loaded fragment."""
74
- try:
75
- info = path.lstat()
76
- expected = text(record["binary"], Path(record["app_dir"]), record["addr"])
77
- fragment = systemctl("show", "-p", "FragmentPath", "--value", unit(record) + ".service")
78
- if (
79
- path.is_symlink()
80
- or info.st_uid != os.getuid()
81
- or info.st_mode & 0o022
82
- or path.read_text() != expected
83
- or fragment.returncode
84
- or os.path.realpath(fragment.stdout.strip()) != os.path.realpath(path)
85
- ):
86
- raise HarnessError("cannot verify ownership of the Bifrost unit; left untouched")
87
- except OSError:
88
- raise HarnessError("cannot verify ownership of the Bifrost unit; left untouched") from None
89
-
90
-
91
- def pause(record: hosts.OwnedBifrost, path: Path, systemctl: Systemctl) -> None:
92
- """Stop the verified unit and confirm that systemd no longer has its process."""
93
- require_owned(record, path, systemctl)
94
- name = unit(record) + ".service"
95
- if systemctl("stop", name).returncode:
96
- raise HarnessError("Bifrost unit could not stop")
97
- pid = systemctl("show", "-p", "MainPID", "--value", name)
98
- if pid.returncode or pid.stdout.strip() != "0":
99
- raise HarnessError("Bifrost unit did not stop")
@@ -1,94 +0,0 @@
1
- {
2
- "schema": "localmodels.engine-lock/v1",
3
- "tag": "strata-poly-0.2.20-poly.5",
4
- "commit": "v0.2.20-poly.5",
5
- "source": "https://github.com/simplexai-labs/PolyStrata/releases/tag/v0.2.20-poly.5",
6
- "note": "PolyStrata 0.2.20-poly.5 (MIT, commit d62dfacbe, strata-poly engine 0.1.66) for CUDA 13 NVIDIA Linux and Windows recipes (Inkling 2 Mini). Adds fused CUDA decode/verify kernels, q5_k default --attn-requant fixing tool-call JSON token drops on small cards (#318), vram_ahead() staging race fix, OOM recovery during CUDA graph capture (#301), and strata_pin prefix pinning (#343). Linux: strata-poly and strata-vision from the release archive with NVIDIA CUDA 13.0.3 runtime libraries (libcublas, libcublasLt, libcudart) reused from 0.1.45-poly.9 under NVIDIA's licence; needs NVIDIA driver for CUDA 13.0 (580 or newer), glibc 2.34, and libstdc++ 12. Windows: strata-poly.exe and strata-vision.exe (CUDA 13.0) paired with NVIDIA's cuBLAS 13.0.2.14 wheel (nvidia/cu13/bin/x86_64 on lib_dirs). On both platforms the tag archive supplies PolyStrata's Python server and tokenizer tools under terminal/ (terminal/serve/, terminal/tools/, terminal/strata_control/, terminal/strata_cli/, and LICENSE).",
7
- "builds": [
8
- {
9
- "platform": "linux",
10
- "arch": "x64",
11
- "backend": "cuda",
12
- "min_cuda": "13.0",
13
- "min_glibc": "2.34",
14
- "binary": "strata-poly",
15
- "assets": [
16
- {
17
- "name": "strata-poly-linux-x64-cuda13-f05645dc3b8f77a0.tar.gz",
18
- "url": "https://github.com/simplexai-labs/PolyStrata/releases/download/v0.2.20-poly.5/strata-poly-linux-x64-cuda13-f05645dc3b8f77a0.tar.gz",
19
- "sha256": "780bf3d2314dae06e9f42d459e7dfe2a2e476a0459a766fc8ac2410932df98bc",
20
- "size_bytes": 81212258,
21
- "npm_copy": {
22
- "package": "@simplexai/engine-strata-poly-linux-x64-cuda13-f05645dc3b8f77a0",
23
- "version": "0.0.0-sha256-780bf3d2314dae06"
24
- }
25
- },
26
- {
27
- "name": "polystrata-0.2.20-poly.5-source.tar.gz",
28
- "url": "https://github.com/simplexai-labs/PolyStrata/archive/refs/tags/v0.2.20-poly.5.tar.gz",
29
- "sha256": "96e53351aae2de1b369da7d0ff3e44e31de1e4fc81ec19804f8f38130af1559a",
30
- "size_bytes": 50429019,
31
- "members": [
32
- "terminal/serve/",
33
- "terminal/tools/",
34
- "terminal/strata_control/",
35
- "terminal/strata_cli/",
36
- "LICENSE"
37
- ],
38
- "npm_copy": {
39
- "package": "@simplexai/engine-polystrata-0.2.20-poly.5-source",
40
- "version": "0.0.0-sha256-96e53351aae2de1b"
41
- }
42
- },
43
- {
44
- "name": "cudart-strata-poly-linux-x64-cuda13.0.3.tar.gz",
45
- "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/strata-poly/0.1.45-poly.9/cudart-strata-poly-linux-x64-cuda13.0.3.tar.gz",
46
- "sha256": "189c3a9fb5fd5f87331ffcedf03d5469c2a9c91f46379299ee6ea277364f05d2",
47
- "size_bytes": 422462968
48
- }
49
- ]
50
- },
51
- {
52
- "platform": "win32",
53
- "arch": "x64",
54
- "backend": "cuda",
55
- "min_cuda": "13.0",
56
- "binary": "strata-poly.exe",
57
- "assets": [
58
- {
59
- "name": "strata-poly-windows-x64-adf95bbb55348db7.zip",
60
- "url": "https://github.com/simplexai-labs/PolyStrata/releases/download/v0.2.20-poly.5/strata-poly-windows-x64-adf95bbb55348db7.zip",
61
- "sha256": "e019563d6945737b75228b6e04d5cde5a33730c7ebfbd791a0d8f368688f5724",
62
- "size_bytes": 81166456,
63
- "npm_copy": {
64
- "package": "@simplexai/engine-strata-poly-windows-x64-adf95bbb55348db7",
65
- "version": "0.0.0-sha256-e019563d6945737b"
66
- }
67
- },
68
- {
69
- "name": "polystrata-0.2.20-poly.5-source.tar.gz",
70
- "url": "https://github.com/simplexai-labs/PolyStrata/archive/refs/tags/v0.2.20-poly.5.tar.gz",
71
- "sha256": "96e53351aae2de1b369da7d0ff3e44e31de1e4fc81ec19804f8f38130af1559a",
72
- "size_bytes": 50429019,
73
- "members": [
74
- "terminal/serve/",
75
- "terminal/tools/",
76
- "terminal/strata_control/",
77
- "terminal/strata_cli/",
78
- "LICENSE"
79
- ],
80
- "npm_copy": {
81
- "package": "@simplexai/engine-polystrata-0.2.20-poly.5-source",
82
- "version": "0.0.0-sha256-96e53351aae2de1b"
83
- }
84
- },
85
- {
86
- "name": "nvidia_cublas-13.0.2.14-py3-none-win_amd64.whl",
87
- "url": "https://files.pythonhosted.org/packages/f3/91/bda39230b7a4c102bb724c21b50823efc63544490a885fea0b604911c0ab/nvidia_cublas-13.0.2.14-py3-none-win_amd64.whl",
88
- "sha256": "5f7a90456b1392db60e28719547ba6e00696bfa81304b6887cf287f9edf2c1d7",
89
- "size_bytes": 401887280
90
- }
91
- ]
92
- }
93
- ]
94
- }
@@ -1,51 +0,0 @@
1
- """Moving a stack between its two gateways: before wiring one, undo what this tool wired into
2
- the other (``gateway.wire`` calls these). Split from ``gateway_bifrost``, which owns the instance.
3
- """
4
-
5
- from __future__ import annotations
6
-
7
- from localmodels import gateway_bifrost, hosts
8
- from localmodels.harness import HarnessError
9
-
10
-
11
- def leave_magpie(tools_dir: str) -> list[str]:
12
- """Before a Bifrost wiring: undo what this tool wired into Magpie (the stack moved). The
13
- plan being wired is already the latest run record, so both the unwiring and the shutdown are
14
- checked against the earlier approved plan that ran Magpie (``magpie_target``); without one
15
- they fail closed and leave Magpie and its records as they are."""
16
- from localmodels import bifrost_clients, gateway, harness_gateway
17
-
18
- doc = hosts.load_owned(tools_dir)
19
- started = doc["gateway"]["started"]
20
- if not bifrost_clients.magpie_wired(doc) and not started:
21
- return []
22
- if started: # a restored handoff receipt can precede a failed Magpie shutdown
23
- bifrost_clients.refuse_changed_handoff(doc, tools_dir)
24
- magpie = gateway.magpie_binary(doc)
25
- previous = harness_gateway.magpie_target(tools_dir)
26
- results = gateway._unwire_magpie(magpie, tools_dir, plan=previous)
27
- if all(r["ok"] for r in results) and started:
28
- results.append(
29
- gateway.stop_gateway(magpie, started, tools_dir, plan=previous)
30
- if magpie is not None
31
- else {"check": "magpie", "ok": False, "detail": "no Magpie started by this tool"}
32
- )
33
- if any(not r["ok"] for r in results):
34
- raise HarnessError(
35
- "undoing this tool's wiring in Magpie failed, not switched to Bifrost: "
36
- + "; ".join(r["check"] for r in results if not r["ok"])
37
- )
38
- return [f"Magpie wiring undone ({len(results)} items)"]
39
-
40
-
41
- def leave(tools_dir: str) -> list[str]:
42
- """Before a Magpie wiring: stop this tool's Bifrost and give pi and the clients back."""
43
- if not hosts.load_owned(tools_dir)["gateway"].get("bifrost"):
44
- return []
45
- results = gateway_bifrost.unwire(tools_dir)
46
- if any(not r["ok"] for r in results):
47
- raise HarnessError(
48
- "undoing this tool's Bifrost gateway failed, not switched to Magpie: "
49
- + "; ".join(r["check"] for r in results if not r["ok"])
50
- )
51
- return ["Bifrost gateway stopped, pi and the clients restored"]
@@ -1,78 +0,0 @@
1
- """Floor metadata for library models that do not fit this computer's pools."""
2
-
3
- from __future__ import annotations
4
-
5
- from localmodels import budget, context_policy, library_kept, library_pricing, metal, suite, vision
6
- from localmodels.estimator import agent_footprint_bytes, eager
7
- from localmodels.library_pricing import Model
8
- from localmodels.probe import HostFacts
9
-
10
-
11
- def floor_metadata(
12
- facts: HostFacts,
13
- model: Model,
14
- shortfall_bytes: int = 0,
15
- *,
16
- memory_kind: str = "",
17
- ) -> tuple[int, int, bool, int]:
18
- """Estimated floor memory, context window, vision flag and download bytes when a model does
19
- not fit this computer's pools (``plan is None``), using the same agent posture.
20
-
21
- Honors per-entry posture overrides (such as ``ubatch``), accounts for Metal and CUDA UMA
22
- unified memory, and avoids mixing host RAM shortfalls (``memory_kind == "ram"``) into VRAM
23
- floor bytes.
24
- """
25
- if library_kept.retired(model.entry): # no recipe left to price; only what was on disk
26
- return shortfall_bytes, 0, False, sum(f.size_bytes for f in model.variant.files)
27
- if model.entry.runtime == "strata-poly":
28
- recipe = suite.recipe(model.entry.id)
29
- window = int(recipe.get("context") or model.entry.n_ctx_train)
30
- active = model.entry.agent_posture(
31
- context_policy.posture_for(library_pricing.posture(), "cuda")
32
- )
33
- vision_on = bool(recipe.get("vision")) and active.vision != "off"
34
- download = sum(
35
- int(f["size_bytes"]) for f in recipe["files"] if vision_on or not f.get("vision")
36
- )
37
- floor_bytes = int(recipe.get("min_vram_free_bytes") or recipe.get("vram_bytes") or 0)
38
- effective_shortfall = 0 if memory_kind == "ram" else shortfall_bytes
39
- return max(effective_shortfall, floor_bytes), window, vision_on, download
40
- metal_unified = metal.supported(facts)
41
- cuda_uma = not metal_unified and budget.unified_pool_bytes(facts) is not None
42
- active = model.entry.agent_posture(
43
- context_policy.posture_for(library_pricing.posture(), "metal" if metal_unified else "cuda")
44
- )
45
- profile = eager(model.entry.profile(model.variant))
46
- window = profile.n_ctx_train if 0 < profile.n_ctx_train < active.floor else active.floor
47
- vision_on = vision.llama_reader_enabled(model.entry.mmproj, active.vision)
48
- mtp = bool(model.entry.mtp_capable and model.entry.agent_mtp and active.mtp_draft_depth > 0)
49
- core = agent_footprint_bytes(
50
- profile,
51
- window,
52
- slots=active.slots,
53
- kv_types=active.kv_types[-1],
54
- ubatch=active.ubatch,
55
- mtp=mtp,
56
- )
57
- if metal_unified or cuda_uma:
58
- vision_extra = (
59
- vision.llama_device_bytes(model.entry.mmproj, "gpu")
60
- if vision_on and model.entry.mmproj is not None
61
- else 0
62
- )
63
- host_side = (
64
- context_policy.cache_floor_bytes(active, profile)
65
- + context_policy.metal_host_bytes(profile, active)
66
- if metal_unified
67
- else 0
68
- )
69
- floor_bytes = core + vision_extra + host_side
70
- else:
71
- floor_bytes = core
72
- download = sum(f.size_bytes for f in model.variant.files)
73
- if vision_on and model.entry.mmproj is not None:
74
- download += model.entry.mmproj.size_bytes
75
- if model.entry.mtp_head is not None:
76
- download += model.entry.mtp_head.size_bytes
77
- effective_shortfall = 0 if memory_kind == "ram" else shortfall_bytes
78
- return max(effective_shortfall, floor_bytes), window, vision_on, download
@@ -1,52 +0,0 @@
1
- """``foundations stop``: end this root's controller and its autostart, for an uninstaller.
2
-
3
- A controller started by 0.1.0.dev34 or later exits cleanly when asked over its loopback API.
4
- An earlier one has no such request: ``service_upgrade`` signals it only after its lock and exact
5
- command prove it is this root's controller, on Linux, macOS and Windows. Model services the
6
- controller started keep running; it never owned their processes.
7
- """
8
-
9
- from __future__ import annotations
10
-
11
- import subprocess
12
- from pathlib import Path
13
- from typing import Any
14
-
15
- from localmodels import runtime_io, service_autostart, service_upgrade
16
-
17
- SCHEMA = "localmodels.service-controller-stop/v1"
18
-
19
-
20
- def stop(root: Path) -> dict[str, Any]:
21
- """Idempotent: nothing under ``root``, or nothing running, is a successful stop."""
22
- result: dict[str, Any] = {
23
- "schema": SCHEMA,
24
- "root": str(root),
25
- "stopped": False,
26
- "method": None,
27
- "autostart": "none",
28
- }
29
- if not (root / "control.json").is_file():
30
- return result
31
- try:
32
- _stop(root, result)
33
- except (OSError, ValueError, subprocess.SubprocessError) as error:
34
- result.update(ok=False, stopped=False, error=str(error))
35
- if isinstance(error, service_upgrade.ControllerError):
36
- result["code"] = error.code
37
- return result
38
-
39
-
40
- def _stop(root: Path, result: dict[str, Any]) -> None:
41
- from localmodels.services_cli import read_configuration
42
-
43
- with runtime_io.private_lock(root / "ensure.lock"):
44
- config = read_configuration(root)
45
- config["stopped"] = True
46
- runtime_io.write_private_json(root / "control.json", config)
47
- running = not service_upgrade.idle(root)
48
- result["autostart"] = service_autostart.unregister(root)
49
- if not running and service_upgrade.idle(root):
50
- return
51
- result["stopped"] = True
52
- result["method"] = service_upgrade.end_controller(root) or "systemd"