@simplexai/localmodels-linux-arm64 0.1.0-dev.61 → 0.1.0-dev.63
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 +66 -63
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/bifrost_checks.py +19 -13
- package/modules/localmodels/bifrost_clients.py +38 -36
- package/modules/localmodels/bifrost_config.py +19 -6
- package/modules/localmodels/bifrost_log.py +3 -3
- package/modules/localmodels/bifrost_models.py +9 -8
- package/modules/localmodels/bifrost_pi.py +27 -72
- package/modules/localmodels/catalog.json +51 -58
- package/modules/localmodels/custom_hub.py +10 -1
- package/modules/localmodels/custom_hub_http.py +41 -107
- package/modules/localmodels/debug_mode.py +3 -3
- package/modules/localmodels/gateway.py +56 -55
- package/modules/localmodels/gateway_bifrost.py +70 -83
- package/modules/localmodels/gateway_clients.py +33 -116
- package/modules/localmodels/gateway_home.py +5 -5
- package/modules/localmodels/gateway_keys.py +8 -6
- package/modules/localmodels/gateway_probe.py +4 -4
- package/modules/localmodels/gateway_server.py +4 -4
- package/modules/localmodels/gateway_speed.py +2 -2
- package/modules/localmodels/harness.py +185 -401
- package/modules/localmodels/harness_core.py +409 -0
- package/modules/localmodels/harness_gateway.py +75 -73
- package/modules/localmodels/harness_probe.py +19 -216
- package/modules/localmodels/library_custom.py +51 -16
- package/modules/localmodels/library_elastic.py +1 -1
- package/modules/localmodels/library_gateway.py +59 -176
- package/modules/localmodels/library_jobs.py +4 -0
- package/modules/localmodels/library_model.py +23 -0
- package/modules/localmodels/library_pricing.py +2 -2
- package/modules/localmodels/library_serve.py +5 -3
- package/modules/localmodels/library_smoke.py +33 -21
- package/modules/localmodels/library_status.py +330 -2
- package/modules/localmodels/llm_rank.py +14 -5
- package/modules/localmodels/magpie_setup.py +5 -4
- package/modules/localmodels/magpie_windows.py +1 -1
- package/modules/localmodels/memcalc_load.py +9 -4
- package/modules/localmodels/pi_profile.py +384 -0
- package/modules/localmodels/process_identity.py +3 -3
- package/modules/localmodels/remote_ops_common.py +31 -90
- package/modules/localmodels/remote_ops_download.py +2 -0
- package/modules/localmodels/remote_ops_mirrors.py +1 -1
- package/modules/localmodels/remote_ops_ranges.py +4 -1
- package/modules/localmodels/remote_ops_redirect.py +393 -0
- package/modules/localmodels/runtime_cli.py +32 -46
- package/modules/localmodels/runtime_pi.py +1 -1
- package/modules/localmodels/source_byok.py +9 -16
- package/modules/localmodels/source_cli.py +136 -23
- package/modules/localmodels/speech_jobs.py +4 -0
- package/modules/localmodels/stack_binding.py +9 -7
- package/modules/localmodels/stack_clients.py +137 -21
- package/modules/localmodels/stack_doctor.py +6 -3
- package/modules/localmodels/stack_hardware.py +18 -0
- package/modules/localmodels/stack_lifecycle.py +3 -2
- package/modules/localmodels/stack_remove.py +2 -1
- package/modules/localmodels/stack_verify.py +2 -2
- package/modules/localmodels/stack_view_events.py +2 -2
- package/modules/localmodels/transport.py +1 -0
- package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/RECORD +63 -60
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -5,11 +5,12 @@ probe's; the web formats them and infers nothing."""
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
7
|
import datetime as dt
|
|
8
|
+
import os
|
|
8
9
|
import re
|
|
9
10
|
import urllib.request
|
|
10
|
-
from collections.abc import Mapping
|
|
11
|
+
from collections.abc import Iterable, Mapping
|
|
11
12
|
from dataclasses import dataclass, field
|
|
12
|
-
from typing import cast
|
|
13
|
+
from typing import Any, cast
|
|
13
14
|
|
|
14
15
|
from localmodels import (
|
|
15
16
|
__version__,
|
|
@@ -24,6 +25,7 @@ from localmodels import (
|
|
|
24
25
|
library_vram,
|
|
25
26
|
metal,
|
|
26
27
|
plan_envelope,
|
|
28
|
+
remote_ops_common,
|
|
27
29
|
suite,
|
|
28
30
|
vision,
|
|
29
31
|
)
|
|
@@ -55,6 +57,9 @@ from localmodels.library_model import (
|
|
|
55
57
|
Problem,
|
|
56
58
|
Row,
|
|
57
59
|
Status,
|
|
60
|
+
Storage,
|
|
61
|
+
StorageFile,
|
|
62
|
+
StorageFileRole,
|
|
58
63
|
VerificationFailure,
|
|
59
64
|
VerificationFailureKind,
|
|
60
65
|
VerificationMeta,
|
|
@@ -74,6 +79,85 @@ ARCH = {
|
|
|
74
79
|
"aarch64": "arm64",
|
|
75
80
|
}
|
|
76
81
|
HEALTH_TIMEOUT_S = 2.0
|
|
82
|
+
_PATH: Any = os.path
|
|
83
|
+
_SIDECAR_SUFFIXES = (".sha256", ".part", ".part.ranges", ".tmp")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _native_path(raw: str) -> str:
|
|
87
|
+
"""Native OS absolute path with clean separators, preserving symlinks."""
|
|
88
|
+
return str(_PATH.normpath(_PATH.abspath(_PATH.expanduser(raw))))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _models_dir(base_dir: str) -> str:
|
|
92
|
+
return _native_path(_PATH.join(_PATH.expanduser(base_dir), "models"))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _models_dir_state(base_dir: str) -> tuple[str, bool]:
|
|
96
|
+
path = _models_dir(base_dir)
|
|
97
|
+
try:
|
|
98
|
+
exists = bool(_PATH.isdir(path))
|
|
99
|
+
except OSError:
|
|
100
|
+
exists = False
|
|
101
|
+
return path, exists
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _canon_key(path: str) -> str:
|
|
105
|
+
expanded = _PATH.expanduser(path)
|
|
106
|
+
try:
|
|
107
|
+
resolved = _PATH.realpath(expanded)
|
|
108
|
+
except OSError:
|
|
109
|
+
resolved = _native_path(expanded)
|
|
110
|
+
return str(_PATH.normcase(resolved))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _is_sidecar(path: str) -> bool:
|
|
114
|
+
return path.lower().endswith(_SIDECAR_SUFFIXES)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _is_proper_subdir(child_key: str, root_key: str) -> bool:
|
|
118
|
+
if not child_key or not root_key or child_key == root_key:
|
|
119
|
+
return False
|
|
120
|
+
sep = str(_PATH.sep)
|
|
121
|
+
prefix = root_key if root_key.endswith(sep) else root_key + sep
|
|
122
|
+
return child_key.startswith(prefix)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _extract_dests(raw_paths: Iterable[str]) -> list[str]:
|
|
126
|
+
found: list[str] = []
|
|
127
|
+
seen: set[str] = set()
|
|
128
|
+
for raw in raw_paths:
|
|
129
|
+
if not raw or not raw.strip():
|
|
130
|
+
continue
|
|
131
|
+
norm = _native_path(raw)
|
|
132
|
+
if _is_sidecar(norm):
|
|
133
|
+
continue
|
|
134
|
+
key = str(_PATH.normcase(norm))
|
|
135
|
+
if key not in seen:
|
|
136
|
+
seen.add(key)
|
|
137
|
+
found.append(norm)
|
|
138
|
+
return found
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _index_owned_deployments(
|
|
142
|
+
records: Mapping[str, Record], file_owners: dict[str, set[str]]
|
|
143
|
+
) -> None:
|
|
144
|
+
library_names = {r["plan"]["name"] for r in records.values()}
|
|
145
|
+
try:
|
|
146
|
+
owned_deployments = hosts.load_owned()["deployments"]
|
|
147
|
+
except (OSError, ValueError):
|
|
148
|
+
return
|
|
149
|
+
for name, owned in owned_deployments.items():
|
|
150
|
+
if name in library_names or owned.get("removed"):
|
|
151
|
+
continue
|
|
152
|
+
owner = f"deployment:{name}"
|
|
153
|
+
for dest in _extract_dests(owned.get("files") or ()):
|
|
154
|
+
file_owners.setdefault(_canon_key(dest), set()).add(owner)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@dataclass
|
|
158
|
+
class _StorageIndex:
|
|
159
|
+
file_owners: dict[str, set[str]]
|
|
160
|
+
dir_owners: dict[str, set[str]]
|
|
77
161
|
|
|
78
162
|
|
|
79
163
|
def platform_name(facts: HostFacts) -> str:
|
|
@@ -103,6 +187,7 @@ class Library:
|
|
|
103
187
|
catalog: tuple[cat.CatalogEntry, ...]
|
|
104
188
|
priced: dict[str, Priced] = field(default_factory=dict)
|
|
105
189
|
_health: dict[str, bool] = field(default_factory=dict, repr=False)
|
|
190
|
+
_storage_idx: _StorageIndex | None = field(default=None, repr=False)
|
|
106
191
|
|
|
107
192
|
@classmethod
|
|
108
193
|
def read(cls, facts: HostFacts, base_dir: str) -> Library:
|
|
@@ -114,6 +199,34 @@ class Library:
|
|
|
114
199
|
library_pricing.entries(),
|
|
115
200
|
)
|
|
116
201
|
|
|
202
|
+
def storage_index(self) -> _StorageIndex:
|
|
203
|
+
if self._storage_idx is None:
|
|
204
|
+
file_owners: dict[str, set[str]] = {}
|
|
205
|
+
dir_owners: dict[str, set[str]] = {}
|
|
206
|
+
for model_id, record in self.records.items():
|
|
207
|
+
owner = f"library:{model_id}"
|
|
208
|
+
dests = _extract_dests(f["dest"] for f in record["plan"].get("files") or ())
|
|
209
|
+
if dests:
|
|
210
|
+
dir_owners.setdefault(_canon_key(str(_PATH.dirname(dests[0]))), set()).add(
|
|
211
|
+
owner
|
|
212
|
+
)
|
|
213
|
+
for dest in dests:
|
|
214
|
+
file_owners.setdefault(_canon_key(dest), set()).add(owner)
|
|
215
|
+
for model_id, (job, _alive) in self.jobs.items():
|
|
216
|
+
if model_id in self.records or job["kind"] == "smoke_test":
|
|
217
|
+
continue
|
|
218
|
+
owner = f"library:{model_id}"
|
|
219
|
+
dests = _extract_dests([*job.get("needs", ()), *job.get("files", ())])
|
|
220
|
+
if dests:
|
|
221
|
+
dir_owners.setdefault(_canon_key(str(_PATH.dirname(dests[0]))), set()).add(
|
|
222
|
+
owner
|
|
223
|
+
)
|
|
224
|
+
for dest in dests:
|
|
225
|
+
file_owners.setdefault(_canon_key(dest), set()).add(owner)
|
|
226
|
+
_index_owned_deployments(self.records, file_owners)
|
|
227
|
+
self._storage_idx = _StorageIndex(file_owners=file_owners, dir_owners=dir_owners)
|
|
228
|
+
return self._storage_idx
|
|
229
|
+
|
|
117
230
|
def healthy(self, base_url: str) -> bool:
|
|
118
231
|
if base_url not in self._health:
|
|
119
232
|
self._health[base_url] = answering(base_url)
|
|
@@ -557,6 +670,217 @@ def _apply_custom_meta(
|
|
|
557
670
|
found["verification"] = _verification_meta(raw_ver, smoke_running=smoke_running)
|
|
558
671
|
|
|
559
672
|
|
|
673
|
+
def _partial_size(path: str, expected_size: int | None) -> int:
|
|
674
|
+
part = path + ".part"
|
|
675
|
+
try:
|
|
676
|
+
if not _PATH.isfile(part):
|
|
677
|
+
return 0
|
|
678
|
+
if expected_size is not None and expected_size > 0:
|
|
679
|
+
return max(0, remote_ops_common.kept_bytes(part, expected_size))
|
|
680
|
+
return max(0, int(_PATH.getsize(part)))
|
|
681
|
+
except OSError:
|
|
682
|
+
return 0
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
def _file_disk_state(path: str, expected_size: int | None) -> tuple[bool, int]:
|
|
686
|
+
try:
|
|
687
|
+
if _PATH.isfile(path):
|
|
688
|
+
return True, max(0, int(_PATH.getsize(path)))
|
|
689
|
+
except OSError:
|
|
690
|
+
return False, 0
|
|
691
|
+
return False, _partial_size(path, expected_size)
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def _matches_asset(
|
|
695
|
+
norm_path: str,
|
|
696
|
+
plan_file: Mapping[str, object] | None,
|
|
697
|
+
asset_path: str,
|
|
698
|
+
asset_local: str,
|
|
699
|
+
) -> bool:
|
|
700
|
+
ap = asset_path.replace("\\", "/").lstrip("/")
|
|
701
|
+
al = asset_local.replace("\\", "/").lstrip("/")
|
|
702
|
+
if plan_file is not None:
|
|
703
|
+
pf_path = str(plan_file.get("path") or "").replace("\\", "/").lstrip("/")
|
|
704
|
+
pf_local = str(plan_file.get("local_name") or "").replace("\\", "/").lstrip("/")
|
|
705
|
+
if (ap and pf_path == ap) or (al and pf_local == al):
|
|
706
|
+
return True
|
|
707
|
+
target = al or ap
|
|
708
|
+
if not target:
|
|
709
|
+
return False
|
|
710
|
+
if "/" in target:
|
|
711
|
+
return norm_path.replace("\\", "/").endswith("/" + target)
|
|
712
|
+
return str(_PATH.basename(norm_path)) == target
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
def _classify_role(
|
|
716
|
+
idx: int,
|
|
717
|
+
norm_path: str,
|
|
718
|
+
plan_file: Mapping[str, object] | None,
|
|
719
|
+
model: Model,
|
|
720
|
+
custom_mmproj: str | None,
|
|
721
|
+
) -> StorageFileRole:
|
|
722
|
+
lower_name = str(_PATH.basename(norm_path)).lower()
|
|
723
|
+
norm_posix = norm_path.replace("\\", "/").lower()
|
|
724
|
+
if lower_name.startswith("mmproj"):
|
|
725
|
+
return "mmproj"
|
|
726
|
+
if model.entry.mmproj is not None and _matches_asset(
|
|
727
|
+
norm_path, plan_file, model.entry.mmproj.path, model.entry.mmproj.local_name
|
|
728
|
+
):
|
|
729
|
+
return "mmproj"
|
|
730
|
+
if custom_mmproj and _matches_asset(norm_path, plan_file, custom_mmproj, custom_mmproj):
|
|
731
|
+
return "mmproj"
|
|
732
|
+
if plan_file is not None and plan_file.get("generated"):
|
|
733
|
+
return "other"
|
|
734
|
+
if model.entry.mtp_head is not None and _matches_asset(
|
|
735
|
+
norm_path, plan_file, model.entry.mtp_head.path, model.entry.mtp_head.local_name
|
|
736
|
+
):
|
|
737
|
+
return "other"
|
|
738
|
+
if idx > 0 and (
|
|
739
|
+
lower_name.startswith(("mtp-", "mtp_")) or "/mtp/" in norm_posix or "/packs/" in norm_posix
|
|
740
|
+
):
|
|
741
|
+
return "other"
|
|
742
|
+
if idx == 0 or lower_name.endswith(".gguf"):
|
|
743
|
+
return "weights"
|
|
744
|
+
return "other"
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _storage_file_entries(
|
|
748
|
+
record: Record | None,
|
|
749
|
+
job: Job | None,
|
|
750
|
+
plan: Plan | None,
|
|
751
|
+
) -> list[tuple[str, Mapping[str, object] | None]]:
|
|
752
|
+
found: list[tuple[str, Mapping[str, object] | None]] = []
|
|
753
|
+
seen: set[str] = set()
|
|
754
|
+
if record is not None:
|
|
755
|
+
for pf in record["plan"].get("files") or ():
|
|
756
|
+
raw = pf.get("dest", "")
|
|
757
|
+
if not raw or not raw.strip():
|
|
758
|
+
continue
|
|
759
|
+
norm = _native_path(raw)
|
|
760
|
+
if _is_sidecar(norm):
|
|
761
|
+
continue
|
|
762
|
+
key = str(_PATH.normcase(norm))
|
|
763
|
+
if key not in seen:
|
|
764
|
+
seen.add(key)
|
|
765
|
+
found.append((norm, pf))
|
|
766
|
+
return found
|
|
767
|
+
if job is None:
|
|
768
|
+
return found
|
|
769
|
+
by_dest: dict[str, Mapping[str, object]] = {}
|
|
770
|
+
if plan is not None:
|
|
771
|
+
for pf in plan.get("files") or ():
|
|
772
|
+
raw_dest = pf.get("dest", "")
|
|
773
|
+
if raw_dest and raw_dest.strip():
|
|
774
|
+
by_dest[str(_PATH.normcase(_native_path(raw_dest)))] = pf
|
|
775
|
+
for norm in _extract_dests([*job.get("needs", ()), *job.get("files", ())]):
|
|
776
|
+
found.append((norm, by_dest.get(str(_PATH.normcase(norm)))))
|
|
777
|
+
return found
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def _record_base_dir(record: Record | None, job: Job | None) -> str | None:
|
|
781
|
+
if record is not None:
|
|
782
|
+
if isinstance(rec_base := record.get("base_dir"), str) and rec_base:
|
|
783
|
+
return rec_base
|
|
784
|
+
deploy_doc = record["plan"].get("deployment")
|
|
785
|
+
if isinstance(deploy_doc, Mapping) and isinstance(d := deploy_doc.get("dir"), str) and d:
|
|
786
|
+
return str(_PATH.dirname(_PATH.dirname(_native_path(d))))
|
|
787
|
+
if job is not None and isinstance(job_base := job.get("base_dir"), str) and job_base:
|
|
788
|
+
return job_base
|
|
789
|
+
return None
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
def _is_dedicated_dir(
|
|
793
|
+
dir_path: str,
|
|
794
|
+
owner: str,
|
|
795
|
+
lib: Library,
|
|
796
|
+
record: Record | None,
|
|
797
|
+
job: Job | None,
|
|
798
|
+
idx: _StorageIndex,
|
|
799
|
+
) -> bool:
|
|
800
|
+
dir_key = _canon_key(dir_path)
|
|
801
|
+
if any(o != owner for o in idx.dir_owners.get(dir_key, ())):
|
|
802
|
+
return False
|
|
803
|
+
base_dirs = [lib.base_dir]
|
|
804
|
+
if (extra_base := _record_base_dir(record, job)) is not None:
|
|
805
|
+
base_dirs.append(extra_base)
|
|
806
|
+
model_roots = [_models_dir(b) for b in dict.fromkeys(base_dirs)]
|
|
807
|
+
root_keys = [_canon_key(r) for r in model_roots]
|
|
808
|
+
asset_keys = [_canon_key(_PATH.join(r, "assets")) for r in model_roots]
|
|
809
|
+
if dir_key in root_keys or any(
|
|
810
|
+
dir_key == ak or _is_proper_subdir(dir_key, ak) for ak in asset_keys
|
|
811
|
+
):
|
|
812
|
+
return False
|
|
813
|
+
return any(_is_proper_subdir(dir_key, rk) for rk in root_keys)
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def _storage_info(
|
|
817
|
+
lib: Library,
|
|
818
|
+
model: Model,
|
|
819
|
+
record: Record | None,
|
|
820
|
+
job: Job | None,
|
|
821
|
+
plan: Plan | None,
|
|
822
|
+
state: str,
|
|
823
|
+
) -> Storage | None:
|
|
824
|
+
if state == "absent":
|
|
825
|
+
return None
|
|
826
|
+
if record is None and (job is None or job["kind"] == "smoke_test"):
|
|
827
|
+
return None
|
|
828
|
+
entries = _storage_file_entries(record, job, plan)
|
|
829
|
+
if not entries:
|
|
830
|
+
return None
|
|
831
|
+
idx = lib.storage_index()
|
|
832
|
+
owner = f"library:{model.id}"
|
|
833
|
+
custom_raw = (record.get("custom") if record is not None else None) or (
|
|
834
|
+
job.get("custom") if job is not None else None
|
|
835
|
+
)
|
|
836
|
+
custom_mmproj = (
|
|
837
|
+
str(custom_raw["mmproj_file"])
|
|
838
|
+
if isinstance(custom_raw, Mapping) and isinstance(custom_raw.get("mmproj_file"), str)
|
|
839
|
+
else None
|
|
840
|
+
)
|
|
841
|
+
files: list[StorageFile] = []
|
|
842
|
+
for i, (norm_path, plan_file) in enumerate(entries):
|
|
843
|
+
raw_size = plan_file.get("size_bytes") if plan_file is not None else None
|
|
844
|
+
expected = (
|
|
845
|
+
raw_size if isinstance(raw_size, int) and not isinstance(raw_size, bool) else None
|
|
846
|
+
)
|
|
847
|
+
present, size_bytes = _file_disk_state(norm_path, expected)
|
|
848
|
+
owners = idx.file_owners.get(_canon_key(norm_path), set())
|
|
849
|
+
files.append(
|
|
850
|
+
{
|
|
851
|
+
"path": norm_path,
|
|
852
|
+
"role": _classify_role(i, norm_path, plan_file, model, custom_mmproj),
|
|
853
|
+
"size_bytes": size_bytes,
|
|
854
|
+
"present": present,
|
|
855
|
+
"shared": any(o != owner for o in owners),
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
primary_path = files[0]["path"]
|
|
859
|
+
dir_path = str(_PATH.dirname(primary_path))
|
|
860
|
+
dedicated = _is_dedicated_dir(dir_path, owner, lib, record, job, idx)
|
|
861
|
+
return {
|
|
862
|
+
"dir": dir_path,
|
|
863
|
+
"primary_path": primary_path,
|
|
864
|
+
"dedicated_dir": dedicated,
|
|
865
|
+
"disk_bytes": sum(f["size_bytes"] for f in files),
|
|
866
|
+
"files_present": all(f["present"] for f in files),
|
|
867
|
+
"files": files,
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
def _apply_storage(
|
|
872
|
+
lib: Library,
|
|
873
|
+
found: Row,
|
|
874
|
+
model: Model,
|
|
875
|
+
record: Record | None,
|
|
876
|
+
job: Job | None,
|
|
877
|
+
plan: Plan | None,
|
|
878
|
+
state: str,
|
|
879
|
+
) -> None:
|
|
880
|
+
if (storage := _storage_info(lib, model, record, job, plan, state)) is not None:
|
|
881
|
+
found["storage"] = storage
|
|
882
|
+
|
|
883
|
+
|
|
560
884
|
def row(lib: Library, model: Model) -> Row:
|
|
561
885
|
record = lib.records.get(model.id)
|
|
562
886
|
priced = lib.judge(model)
|
|
@@ -620,6 +944,7 @@ def row(lib: Library, model: Model) -> Row:
|
|
|
620
944
|
_apply_engine_meta(lib, found, model, plan)
|
|
621
945
|
_apply_record_meta(found, model, record, state, problem)
|
|
622
946
|
_apply_custom_meta(found, record, job, alive)
|
|
947
|
+
_apply_storage(lib, found, model, record, job, plan, state)
|
|
623
948
|
return found
|
|
624
949
|
|
|
625
950
|
|
|
@@ -753,6 +1078,7 @@ def host(lib: Library) -> Host:
|
|
|
753
1078
|
engine_order: tuple[Engine, ...] = ("llama.cpp", "polystrata", "strata")
|
|
754
1079
|
ordered = [by_family[f] for f in engine_order if f in by_family]
|
|
755
1080
|
engine_label = " + ".join(ordered) if ordered else "llama.cpp"
|
|
1081
|
+
models_dir, models_dir_exists = _models_dir_state(lib.base_dir)
|
|
756
1082
|
found: Host = {
|
|
757
1083
|
"platform": platform_name(facts),
|
|
758
1084
|
"arch": ARCH.get(str(facts.get("arch")), str(facts.get("arch"))),
|
|
@@ -761,6 +1087,8 @@ def host(lib: Library) -> Host:
|
|
|
761
1087
|
"ram_total_bytes": facts["ram"]["total_bytes"],
|
|
762
1088
|
"ram_available_bytes": facts["ram"]["available_bytes"],
|
|
763
1089
|
"disk_free_bytes": library_pricing.base_free(lib.base_dir),
|
|
1090
|
+
"models_dir": models_dir,
|
|
1091
|
+
"models_dir_exists": models_dir_exists,
|
|
764
1092
|
"supported_formats": ["gguf"],
|
|
765
1093
|
"gpus": [
|
|
766
1094
|
{
|
|
@@ -34,6 +34,9 @@ from localmodels.probe import HostFacts
|
|
|
34
34
|
# Installed SimplexAI scores closer than this are a tie (model-scoring.md; AIHOT: 3 points or more
|
|
35
35
|
# rarely swap): a challenger with another engine must beat the llama.cpp pick by at least this.
|
|
36
36
|
TIE_BAND = 3
|
|
37
|
+
# Scores within this band are statistically indistinguishable (AIHOT: under 1 point is a coin
|
|
38
|
+
# flip; roadmap decision 71): break ties by decode speed, and let prefer_over_llama recipes win.
|
|
39
|
+
COIN_FLIP = 1
|
|
37
40
|
# --prefer fast: the fastest fitting model whose score is within this many points of the best.
|
|
38
41
|
FAST_QUALITY_BAND = 5
|
|
39
42
|
WINDOWS_FALLBACK_ID = "spark-x2.6-4b"
|
|
@@ -71,12 +74,13 @@ def strata_recipe_bar(
|
|
|
71
74
|
) -> int:
|
|
72
75
|
"""The installed score one Strata/PolyStrata recipe must reach to replace the llama.cpp pick:
|
|
73
76
|
a recipe marked ``prefer_over_llama`` (such as PolyStrata Inkling 2 Mini on CUDA 13+, which
|
|
74
|
-
offers higher-precision quants and faster decode/prefill on NVIDIA cards) wins
|
|
75
|
-
llama.cpp under ``smartest``, while keeping ``--prefer fastest`` on
|
|
77
|
+
offers higher-precision quants and faster decode/prefill on NVIDIA cards) wins within
|
|
78
|
+
``COIN_FLIP`` against llama.cpp under ``smartest``, while keeping ``--prefer fastest`` on
|
|
79
|
+
llama.cpp when one fits."""
|
|
76
80
|
if options.get("prefer") == "fastest" and llama_score >= 0:
|
|
77
81
|
return 1 << 30
|
|
78
82
|
if prefer_over_llama:
|
|
79
|
-
return max(0, llama_score)
|
|
83
|
+
return max(0, llama_score - COIN_FLIP)
|
|
80
84
|
return llama_score + TIE_BAND
|
|
81
85
|
|
|
82
86
|
|
|
@@ -381,7 +385,9 @@ def choose(
|
|
|
381
385
|
near = [t for t in ranked if t[0][0] >= best - FAST_QUALITY_BAND]
|
|
382
386
|
_, entry_id, index = max(near, key=lambda t: (t[0][1], t[0][0]))
|
|
383
387
|
return entry_id, index
|
|
384
|
-
|
|
388
|
+
best = max(key[0] for key, _, _ in ranked)
|
|
389
|
+
near = [t for t in ranked if t[0][0] >= best - COIN_FLIP]
|
|
390
|
+
_, entry_id, index = max(near, key=lambda t: (t[0][1], t[0][0]))
|
|
385
391
|
return entry_id, index
|
|
386
392
|
|
|
387
393
|
|
|
@@ -420,6 +426,9 @@ def recommended_entry(
|
|
|
420
426
|
if entry.id == product_default:
|
|
421
427
|
return (entry, "product-default")
|
|
422
428
|
if resident:
|
|
423
|
-
|
|
429
|
+
scored = [(rank_key(e, c.variant, budget, backend=backend), e) for e, c in resident]
|
|
430
|
+
best = max(k[0] for k, _ in scored)
|
|
431
|
+
near = [(k, e) for k, e in scored if k[0] >= best - COIN_FLIP]
|
|
432
|
+
pick = max(near, key=lambda t: (t[0][1], t[0][0]))[1]
|
|
424
433
|
return pick, "best-quality-resident"
|
|
425
434
|
return None
|
|
@@ -30,6 +30,7 @@ from localmodels import (
|
|
|
30
30
|
gateway,
|
|
31
31
|
gateway_clients,
|
|
32
32
|
harness,
|
|
33
|
+
harness_core,
|
|
33
34
|
hosts,
|
|
34
35
|
probe,
|
|
35
36
|
stack_clients,
|
|
@@ -119,7 +120,7 @@ def discovery_on(
|
|
|
119
120
|
return True
|
|
120
121
|
if plan is None:
|
|
121
122
|
raise SetupError("没有可证明的网关目标,未读取账号发现设置")
|
|
122
|
-
out =
|
|
123
|
+
out = harness_core.run_tool(
|
|
123
124
|
[magpie, "accounts", "discovery"], timeout=20, env=harness.checked_gateway_environment(plan)
|
|
124
125
|
)
|
|
125
126
|
if out.returncode:
|
|
@@ -303,7 +304,7 @@ def changes(saved: MagpieSetupPlan, fresh: MagpieSetupPlan) -> list[str]:
|
|
|
303
304
|
|
|
304
305
|
def _models(tools: harness.ToolPlan, client: str, provider: str) -> list[str]:
|
|
305
306
|
"""``provider``'s models that ``magpie models <client>`` offers the client, in its order."""
|
|
306
|
-
out =
|
|
307
|
+
out = harness_core.run_tool(
|
|
307
308
|
[harness.tool_path(tools, "magpie"), "models", client],
|
|
308
309
|
timeout=60,
|
|
309
310
|
env=harness.checked_gateway_environment(tools),
|
|
@@ -364,7 +365,7 @@ def _run(plan: MagpieSetupPlan, log: Log, timeout: float) -> list[Check]:
|
|
|
364
365
|
wired = {n: w for n, w in plan["clients"].items() if w["action"] == "wire"}
|
|
365
366
|
targets: dict[str, str] = {}
|
|
366
367
|
for provider in sorted({str(w["subscription"]) for w in wired.values()}):
|
|
367
|
-
out =
|
|
368
|
+
out = harness_core.run_tool(
|
|
368
369
|
[magpie, "provider", "models", provider],
|
|
369
370
|
timeout=120,
|
|
370
371
|
env=harness.checked_gateway_environment(tools),
|
|
@@ -429,7 +430,7 @@ def _accept(
|
|
|
429
430
|
)
|
|
430
431
|
before = calls()
|
|
431
432
|
with tempfile.TemporaryDirectory(prefix="localmodels-pi-") as cwd:
|
|
432
|
-
out =
|
|
433
|
+
out = harness_core.run_tool(
|
|
433
434
|
[harness.tool_path(tools, "pi"), *gateway.PI_ACCEPT_FLAGS, TOUCH_PROMPT],
|
|
434
435
|
timeout=timeout,
|
|
435
436
|
cwd=cwd,
|
|
@@ -300,7 +300,7 @@ def adopt_magpie_successor(
|
|
|
300
300
|
return False
|
|
301
301
|
path = Path(pid_file)
|
|
302
302
|
try:
|
|
303
|
-
saved = process_identity.
|
|
303
|
+
saved = process_identity.recorded(path)
|
|
304
304
|
if saved is None or process_identity._windows_inspect(saved["pid"]) is not None:
|
|
305
305
|
return False
|
|
306
306
|
cand = magpie_successor_pid(saved, program, port, gateway_home)
|
|
@@ -14,7 +14,7 @@ from dataclasses import dataclass, replace
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from typing import Any
|
|
16
16
|
|
|
17
|
-
from localmodels import estimator
|
|
17
|
+
from localmodels import estimator, remote_ops_redirect
|
|
18
18
|
from localmodels.gguf import read_gguf_header, split_parts
|
|
19
19
|
from localmodels.memcalc import (
|
|
20
20
|
MIB,
|
|
@@ -73,12 +73,17 @@ def safetensors_size(directory: Path) -> tuple[int, int]:
|
|
|
73
73
|
|
|
74
74
|
def _http_json(url: str, timeout: float) -> dict[str, Any]:
|
|
75
75
|
headers = {"User-Agent": "localmodels-memcalc"}
|
|
76
|
-
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
|
77
|
-
|
|
76
|
+
token = (os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or "").strip()
|
|
77
|
+
try:
|
|
78
|
+
scheme, host, _ = remote_ops_redirect.url_origin(url)
|
|
79
|
+
except remote_ops_redirect.UnsafeRedirectError as exc:
|
|
80
|
+
raise MemcalcError(f"could not fetch {url.split('?')[0]}: {exc}") from exc
|
|
81
|
+
if token and scheme == "https" and host and not remote_ops_redirect.is_hf_mirror_host(host):
|
|
78
82
|
headers["Authorization"] = f"Bearer {token}"
|
|
79
83
|
request = urllib.request.Request(url, headers=headers)
|
|
84
|
+
opener = urllib.request.build_opener(remote_ops_redirect.SafeRedirectHandler())
|
|
80
85
|
try:
|
|
81
|
-
with
|
|
86
|
+
with opener.open(request, timeout=timeout) as response:
|
|
82
87
|
data = json.loads(response.read(16 * MIB))
|
|
83
88
|
except OSError as exc:
|
|
84
89
|
raise MemcalcError(f"could not fetch {url.split('?')[0]}: {exc}") from exc
|