@simplexai/localmodels-win32-x64 0.1.0-dev.109 → 0.1.0-dev.111
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/README.md +1 -1
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +47 -47
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +433 -75
- package/modules/localmodels/catalog_recipes.py +1 -0
- package/modules/localmodels/chat_template.py +4 -0
- package/modules/localmodels/custom_hub.py +66 -2
- package/modules/localmodels/custom_hub_http.py +18 -0
- package/modules/localmodels/deploy.py +65 -5
- package/modules/localmodels/download-mirrors.json +70 -0
- package/modules/localmodels/engine_adapters/strata_poly.py +20 -4
- package/modules/localmodels/engine_adapters/suite_plan.py +3 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.10.json +132 -0
- package/modules/localmodels/http_local.py +46 -0
- package/modules/localmodels/library_custom.py +73 -0
- package/modules/localmodels/library_direct.py +4 -1
- package/modules/localmodels/library_jobs.py +0 -12
- package/modules/localmodels/library_poly.py +11 -5
- package/modules/localmodels/library_presentation.py +28 -0
- package/modules/localmodels/library_serve.py +30 -21
- package/modules/localmodels/library_smoke.py +1 -1
- package/modules/localmodels/library_state.py +20 -1
- package/modules/localmodels/library_status.py +46 -55
- package/modules/localmodels/mirrors.py +217 -21
- package/modules/localmodels/npm_transport.py +46 -35
- package/modules/localmodels/plan_envelope.py +8 -1
- package/modules/localmodels/region.py +91 -20
- package/modules/localmodels/remote_ops_common.py +1 -0
- package/modules/localmodels/remote_ops_download.py +574 -126
- package/modules/localmodels/remote_ops_prepare.py +8 -2
- package/modules/localmodels/remote_ops_ranges.py +80 -44
- package/modules/localmodels/remote_ops_redirect.py +3 -1
- package/modules/localmodels/remote_ops_remove.py +4 -2
- package/modules/localmodels/runtime_index.py +3 -1
- package/modules/localmodels/stack.py +1 -6
- package/modules/localmodels/stack_suite.py +1 -1
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.9.txt → strata-poly-serve-0.2.20-poly.10.txt} +1 -1
- package/modules/localmodels/suite.py +80 -3
- package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/RECORD +43 -43
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +0 -132
- /package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/licenses/LICENSE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev109.dist-info → simplex_localmodels-0.1.0.dev111.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -5,8 +5,11 @@ One process resolves the region once, lazily, the first time something is about
|
|
|
5
5
|
1. ``SIMPLEX_REGION`` (or the CLI's ``--region``, which sets it) when it is ``cn`` or ``global``;
|
|
6
6
|
``auto`` or unset means not forced. Linger passes the region it resolved this way.
|
|
7
7
|
2. ``SIMPLEX_REGION_FILE`` (when set by Linger to share ``<home>/runtime/region.json``) or
|
|
8
|
-
``$LOCALMODELS_STATE/region.json`` when it is younger than ``STALE_AFTER`` (6 hours
|
|
9
|
-
``network_fingerprint`` matches the current proxy
|
|
8
|
+
``$LOCALMODELS_STATE/region.json`` when it is younger than ``STALE_AFTER`` (6 hours; 1 hour
|
|
9
|
+
when ``method`` is ``fallback``) and its ``network_fingerprint`` matches the current proxy
|
|
10
|
+
environment. ``method: user`` is an explicit preference: it does not expire and is not
|
|
11
|
+
rewritten by ``fallback_to``. A non-empty ``host_net_fp`` that differs from this host
|
|
12
|
+
expires ``probe`` and ``fallback`` records only; a file without that field still hits.
|
|
10
13
|
3. A multi-signal concurrent speed probe covering npm (pinned pi tarball race), PyPI (official
|
|
11
14
|
vs Tsinghua / Aliyun / USTC / Tencent), and Model Hub (Hugging Face vs hf-mirror / ModelScope).
|
|
12
15
|
Recording per-ecosystem winners in ``region.json["ecosystems"]`` prevents a Cloudflare Anycast
|
|
@@ -21,12 +24,14 @@ was decisively outperformed by the other side switches the region (``fallback_to
|
|
|
21
24
|
from __future__ import annotations
|
|
22
25
|
|
|
23
26
|
import configparser
|
|
27
|
+
import contextlib
|
|
24
28
|
import datetime as dt
|
|
25
29
|
import json
|
|
26
30
|
import os
|
|
27
31
|
import re
|
|
28
32
|
import stat
|
|
29
33
|
import sys
|
|
34
|
+
import tempfile
|
|
30
35
|
import threading
|
|
31
36
|
from collections.abc import Mapping, MutableMapping, Sequence
|
|
32
37
|
from pathlib import Path
|
|
@@ -40,6 +45,7 @@ REGIONS = ("global", "cn")
|
|
|
40
45
|
ENV = "SIMPLEX_REGION"
|
|
41
46
|
FILE_ENV = "SIMPLEX_REGION_FILE"
|
|
42
47
|
STALE_AFTER = dt.timedelta(hours=6)
|
|
48
|
+
FALLBACK_STALE_AFTER = dt.timedelta(hours=1)
|
|
43
49
|
HF_API = "https://huggingface.co"
|
|
44
50
|
HF_MIRROR = "https://hf-mirror.com"
|
|
45
51
|
PYPI_MIRROR = "https://pypi.tuna.tsinghua.edu.cn/simple/"
|
|
@@ -123,11 +129,9 @@ def _read_regular_text(path: Path, *, max_bytes: int = 64 << 10) -> str | None:
|
|
|
123
129
|
return None
|
|
124
130
|
|
|
125
131
|
|
|
126
|
-
def
|
|
127
|
-
now: dt.datetime | None = None,
|
|
132
|
+
def _read_doc(
|
|
128
133
|
env: Mapping[str, str] | None = None,
|
|
129
|
-
) -> dict[str, Any] | None:
|
|
130
|
-
"""The saved region document when valid, younger than STALE_AFTER, and matching proxy state."""
|
|
134
|
+
) -> tuple[dict[str, Any], dt.datetime] | None:
|
|
131
135
|
text = _read_regular_text(_resolve_region_path(env))
|
|
132
136
|
if text is None or len(text.encode("utf-8")) > (64 << 10):
|
|
133
137
|
return None
|
|
@@ -144,13 +148,39 @@ def saved(
|
|
|
144
148
|
or when.tzinfo is None
|
|
145
149
|
):
|
|
146
150
|
return None
|
|
151
|
+
return doc, when
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def saved(
|
|
155
|
+
now: dt.datetime | None = None,
|
|
156
|
+
env: Mapping[str, str] | None = None,
|
|
157
|
+
) -> dict[str, Any] | None:
|
|
158
|
+
"""The saved region document when valid, younger than STALE_AFTER, and matching proxy state."""
|
|
159
|
+
pair = _read_doc(env)
|
|
160
|
+
if pair is None:
|
|
161
|
+
return None
|
|
162
|
+
doc, when = pair
|
|
163
|
+
method = doc.get("method")
|
|
164
|
+
active_env = os.environ if env is None else env
|
|
165
|
+
fp_ok = True
|
|
147
166
|
stored_fp = doc.get("network_fingerprint")
|
|
148
167
|
if isinstance(stored_fp, str) and stored_fp:
|
|
149
|
-
active_env = os.environ if env is None else env
|
|
150
168
|
if stored_fp != mirrors.network_fingerprint(active_env):
|
|
151
|
-
|
|
169
|
+
fp_ok = False
|
|
170
|
+
host_ok = True
|
|
171
|
+
stored_host = doc.get("host_net_fp")
|
|
172
|
+
if isinstance(stored_host, str) and stored_host:
|
|
173
|
+
current_host = mirrors.host_network_fingerprint()
|
|
174
|
+
if current_host and current_host != stored_host:
|
|
175
|
+
host_ok = False
|
|
152
176
|
age = (now or dt.datetime.now(dt.timezone.utc)) - when
|
|
153
|
-
|
|
177
|
+
limit = FALLBACK_STALE_AFTER if method == "fallback" else STALE_AFTER
|
|
178
|
+
fresh = dt.timedelta(0) <= age <= limit
|
|
179
|
+
if method == "user":
|
|
180
|
+
if not (fp_ok and host_ok and fresh) and "ecosystems" in doc:
|
|
181
|
+
doc = {k: v for k, v in doc.items() if k != "ecosystems"}
|
|
182
|
+
return doc
|
|
183
|
+
return doc if (fp_ok and host_ok and fresh) else None
|
|
154
184
|
|
|
155
185
|
|
|
156
186
|
def save(
|
|
@@ -161,14 +191,17 @@ def save(
|
|
|
161
191
|
env: Mapping[str, str] | None = None,
|
|
162
192
|
) -> None:
|
|
163
193
|
"""Write region.json owner-only and atomically; a state directory that cannot be written
|
|
164
|
-
costs only the next run a probe.
|
|
194
|
+
costs only the next run a probe. An existing ``method: user`` preference is protected from
|
|
195
|
+
every non-user writer (``probe``, ``fallback``, ``env``) while ``save(..., "user")`` updates it."""
|
|
165
196
|
active_env = os.environ if env is None else env
|
|
197
|
+
existing = saved(env=active_env)
|
|
198
|
+
if method != "user" and existing is not None and existing.get("method") == "user":
|
|
199
|
+
return
|
|
166
200
|
fp = mirrors.network_fingerprint(active_env)
|
|
167
201
|
merged: dict[EcosystemName, EcosystemRecord] = {}
|
|
168
202
|
if ecosystems is not None:
|
|
169
203
|
merged.update(ecosystems)
|
|
170
204
|
else:
|
|
171
|
-
existing = saved(env=active_env)
|
|
172
205
|
if existing is not None:
|
|
173
206
|
for name, rec in _parse_ecosystems(existing.get("ecosystems")).items():
|
|
174
207
|
if rec["region"] == region:
|
|
@@ -183,17 +216,34 @@ def save(
|
|
|
183
216
|
"method": method,
|
|
184
217
|
"network_fingerprint": fp,
|
|
185
218
|
}
|
|
219
|
+
host_fp = mirrors.host_network_fingerprint()
|
|
220
|
+
if host_fp:
|
|
221
|
+
doc["host_net_fp"] = host_fp
|
|
186
222
|
if merged:
|
|
187
223
|
doc["ecosystems"] = dict(merged)
|
|
188
224
|
path = _resolve_region_path(active_env)
|
|
189
|
-
|
|
225
|
+
tmp_path: str | None = None
|
|
190
226
|
try:
|
|
191
227
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
228
|
+
fd, tmp_path = tempfile.mkstemp(
|
|
229
|
+
prefix=f".{path.name}.",
|
|
230
|
+
suffix=".tmp",
|
|
231
|
+
dir=str(path.parent),
|
|
232
|
+
)
|
|
233
|
+
try:
|
|
234
|
+
fh = os.fdopen(fd, "w", encoding="utf-8")
|
|
235
|
+
except BaseException:
|
|
236
|
+
with contextlib.suppress(OSError):
|
|
237
|
+
os.close(fd)
|
|
238
|
+
raise
|
|
239
|
+
with fh:
|
|
240
|
+
fh.write(json.dumps(doc) + "\n")
|
|
241
|
+
os.replace(tmp_path, path)
|
|
242
|
+
tmp_path = None
|
|
195
243
|
except OSError:
|
|
196
|
-
|
|
244
|
+
if tmp_path is not None:
|
|
245
|
+
with contextlib.suppress(OSError):
|
|
246
|
+
os.unlink(tmp_path)
|
|
197
247
|
|
|
198
248
|
|
|
199
249
|
def _combine_signals(
|
|
@@ -293,9 +343,13 @@ def current_region(env: Mapping[str, str] | None = None) -> str:
|
|
|
293
343
|
for name in [k for k, rec in _ecosystems.items() if rec["region"] != explicit]:
|
|
294
344
|
_ecosystems.pop(name, None)
|
|
295
345
|
found = saved(env=active_env)
|
|
296
|
-
|
|
346
|
+
raw_pair = _read_doc(active_env)
|
|
347
|
+
raw_doc = raw_pair[0] if raw_pair is not None else None
|
|
348
|
+
is_user_pref = raw_doc is not None and raw_doc.get("method") == "user"
|
|
349
|
+
same_region_on_disk = raw_doc is not None and raw_doc.get("region") == explicit
|
|
350
|
+
if not is_user_pref and not same_region_on_disk:
|
|
297
351
|
save(explicit, "env", env=active_env)
|
|
298
|
-
elif found is not None:
|
|
352
|
+
elif found is not None and found["region"] == explicit:
|
|
299
353
|
_ecosystems.update(_parse_ecosystems(found.get("ecosystems")))
|
|
300
354
|
_resolved = explicit
|
|
301
355
|
return explicit
|
|
@@ -316,13 +370,22 @@ def current_region(env: Mapping[str, str] | None = None) -> str:
|
|
|
316
370
|
return _resolved
|
|
317
371
|
|
|
318
372
|
|
|
373
|
+
def _user_preference(env: Mapping[str, str] | None = None) -> bool:
|
|
374
|
+
"""True when region.json is an explicit user choice that fallback must not rewrite."""
|
|
375
|
+
found = saved(env=os.environ if env is None else env)
|
|
376
|
+
return found is not None and found.get("method") == "user"
|
|
377
|
+
|
|
378
|
+
|
|
319
379
|
def fallback_to(region: str, env: MutableMapping[str, str] | None = None) -> None:
|
|
320
380
|
"""The other side served what the preferred side could not: use it from now on, here, in
|
|
321
|
-
child processes (``SIMPLEX_REGION``) and in later runs (region.json).
|
|
381
|
+
child processes (``SIMPLEX_REGION``) and in later runs (region.json). A ``method: user``
|
|
382
|
+
preference is left as the user set it."""
|
|
322
383
|
global _resolved
|
|
323
384
|
if region not in REGIONS:
|
|
324
385
|
return
|
|
325
386
|
env = os.environ if env is None else env
|
|
387
|
+
if _user_preference(env):
|
|
388
|
+
return
|
|
326
389
|
with _LOCK:
|
|
327
390
|
changed = _resolved != region or env.get(ENV) not in (None, "", "auto", region)
|
|
328
391
|
_resolved = region
|
|
@@ -653,7 +716,15 @@ def language_environment(
|
|
|
653
716
|
result["RUSTUP_DIST_SERVER"] = rust_url
|
|
654
717
|
result["RUSTUP_UPDATE_ROOT"] = rust_url.rstrip("/") + "/rustup"
|
|
655
718
|
if not _env_get_fold(result, "HF_ENDPOINT"):
|
|
656
|
-
|
|
719
|
+
hub = ecosystem_record("model_hub", env=result, allow_probe=allow_probe)
|
|
720
|
+
# Inject hf-mirror when the model_hub probe verified it as a working CN candidate.
|
|
721
|
+
# A 308 back to huggingface.co is discarded by mirrors.probe_url and absent from
|
|
722
|
+
# candidates, while a working pure-CN hf-mirror stays eligible even when ModelScope won.
|
|
723
|
+
if (
|
|
724
|
+
hub is not None
|
|
725
|
+
and hub.get("region") == "cn"
|
|
726
|
+
and any(c.rstrip("/") == HF_MIRROR for c in (hub.get("candidates") or ()))
|
|
727
|
+
):
|
|
657
728
|
result["HF_ENDPOINT"] = HF_MIRROR
|
|
658
729
|
_apply_homebrew_env(result, reg, allow_probe=allow_probe)
|
|
659
730
|
return result
|
|
@@ -153,6 +153,7 @@ class RemoveParams(ServiceParams, total=False):
|
|
|
153
153
|
purge: list[str] # the listed files the operator approved deleting
|
|
154
154
|
config_files: list[str] # files install wrote from the plan's config_files
|
|
155
155
|
preparation_dir: str # the recorded model root whose failed preparation a purge may list
|
|
156
|
+
keep_key: bool # keep <deploy_dir>/api-key across non-purge unload/reload
|
|
156
157
|
|
|
157
158
|
|
|
158
159
|
CHUNK = 8 << 20
|