@simplexai/localmodels-linux-arm64 0.1.0-dev.110 → 0.1.0-dev.112

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