@simplexai/localmodels-linux-x64 0.1.0-dev.38 → 0.1.0-dev.40
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 +81 -73
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +4 -0
- package/modules/localmodels/auth_proxy.py +74 -16
- package/modules/localmodels/bifrost_config.py +19 -0
- package/modules/localmodels/budget.py +27 -18
- package/modules/localmodels/catalog.json +18 -6
- package/modules/localmodels/chat_template.py +35 -0
- package/modules/localmodels/cli_parser.py +26 -3
- package/modules/localmodels/deploy.py +44 -10
- package/modules/localmodels/deploy_steps.py +6 -3
- package/modules/localmodels/download-mirrors.json +52 -4
- package/modules/localmodels/engines-b11583.json +20 -4
- package/modules/localmodels/engines-b12167.json +5 -1
- package/modules/localmodels/engines-strata-0.1.47.json +5 -1
- package/modules/localmodels/engines-strata-0.1.49.2.json +5 -1
- package/modules/localmodels/engines-strata-0.1.59.1.json +5 -1
- package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +5 -1
- package/modules/localmodels/engines-whisper-b5454.json +5 -1
- package/modules/localmodels/engines.json +55 -11
- package/modules/localmodels/frontend.py +5 -2
- package/modules/localmodels/gateway.py +2 -0
- package/modules/localmodels/gateway_bifrost.py +3 -0
- package/modules/localmodels/gateway_home.py +132 -0
- package/modules/localmodels/guard.py +15 -6
- package/modules/localmodels/harness.py +104 -37
- package/modules/localmodels/harness_gateway.py +9 -3
- package/modules/localmodels/harness_probe.py +5 -1
- package/modules/localmodels/hf_repo.py +15 -8
- package/modules/localmodels/library_gateway.py +28 -15
- package/modules/localmodels/library_jobs.py +7 -1
- package/modules/localmodels/library_serve.py +5 -0
- package/modules/localmodels/metal.py +29 -12
- package/modules/localmodels/metal_probe.py +16 -6
- package/modules/localmodels/npm_signatures.py +131 -0
- package/modules/localmodels/npm_transport.py +26 -10
- package/modules/localmodels/probe.py +4 -0
- package/modules/localmodels/process_identity.py +21 -5
- package/modules/localmodels/region.py +244 -0
- package/modules/localmodels/remote_ops.py +69 -13
- package/modules/localmodels/remote_ops_download.py +217 -10
- package/modules/localmodels/remote_ops_prepare.py +61 -8
- package/modules/localmodels/remote_ops_remove.py +15 -0
- package/modules/localmodels/remote_ops_service.py +10 -0
- package/modules/localmodels/runtime-lock.json +13 -13
- package/modules/localmodels/runtime_args.py +4 -2
- package/modules/localmodels/runtime_cli.py +76 -74
- package/modules/localmodels/runtime_discovery.py +58 -0
- package/modules/localmodels/runtime_install.py +103 -7
- package/modules/localmodels/runtime_io.py +64 -7
- package/modules/localmodels/runtime_pi.py +122 -0
- package/modules/localmodels/runtime_process.py +101 -15
- package/modules/localmodels/runtime_releases.py +51 -71
- package/modules/localmodels/service_deployment.py +5 -3
- package/modules/localmodels/service_probe.py +146 -31
- package/modules/localmodels/setup_inspection.py +110 -14
- package/modules/localmodels/setup_text.py +13 -0
- package/modules/localmodels/slot_cache.py +467 -0
- package/modules/localmodels/source_byok.py +484 -0
- package/modules/localmodels/source_byok_probe.py +275 -0
- package/modules/localmodels/source_cli.py +426 -0
- package/modules/localmodels/stack_args.py +2 -1
- package/modules/localmodels/stack_binding.py +125 -5
- package/modules/localmodels/stack_capacity.py +3 -3
- package/modules/localmodels/stack_down.py +22 -7
- package/modules/localmodels/stack_events.py +62 -0
- package/modules/localmodels/stack_hardware.py +20 -17
- package/modules/localmodels/stack_lifecycle.py +12 -3
- package/modules/localmodels/stack_rollback.py +9 -4
- package/modules/localmodels/stack_up.py +27 -20
- package/modules/localmodels/stack_update.py +3 -1
- package/modules/localmodels/tools.json +1365 -14
- package/modules/localmodels/transport.py +2 -0
- package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/RECORD +78 -70
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev38.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -12,12 +12,14 @@ from __future__ import annotations
|
|
|
12
12
|
import http.client
|
|
13
13
|
import json
|
|
14
14
|
import os
|
|
15
|
+
import shutil
|
|
16
|
+
import tarfile
|
|
15
17
|
import threading
|
|
16
18
|
import time
|
|
17
19
|
import urllib.error
|
|
18
20
|
import urllib.parse
|
|
19
21
|
import urllib.request
|
|
20
|
-
from typing import Tuple
|
|
22
|
+
from typing import Iterator, Tuple
|
|
21
23
|
|
|
22
24
|
try:
|
|
23
25
|
from localmodels import remote_ops, remote_ops_prepare
|
|
@@ -44,7 +46,15 @@ def act_engine(p: remote_ops.EngineParams) -> None:
|
|
|
44
46
|
):
|
|
45
47
|
a = p["assets"][i]
|
|
46
48
|
archive = os.path.join(cache, a["name"])
|
|
47
|
-
remote_ops.fetch(
|
|
49
|
+
remote_ops.fetch(
|
|
50
|
+
a["url"],
|
|
51
|
+
archive,
|
|
52
|
+
a["sha256"],
|
|
53
|
+
a["size_bytes"],
|
|
54
|
+
a["name"],
|
|
55
|
+
npm_copies(a),
|
|
56
|
+
p.get("region"),
|
|
57
|
+
)
|
|
48
58
|
remote_ops.unpack(archive, directory)
|
|
49
59
|
if not os.access(binary, os.X_OK):
|
|
50
60
|
raise RuntimeError(f"the engine has no executable {os.path.relpath(binary, directory)}")
|
|
@@ -93,9 +103,11 @@ def act_download(p: remote_ops.DownloadParams) -> None:
|
|
|
93
103
|
raise RuntimeError(
|
|
94
104
|
f"{f['dest']} has no download URL, and the reusable copy failed the SHA256 check"
|
|
95
105
|
)
|
|
96
|
-
remote_ops.fetch(
|
|
106
|
+
remote_ops.fetch(
|
|
107
|
+
f["url"], dest, f["sha256"], f["size_bytes"], label, f.get("mirrors"), p.get("region")
|
|
108
|
+
)
|
|
97
109
|
if p.get("preparation"):
|
|
98
|
-
remote_ops_prepare.prepare(p["preparation"], p["files"])
|
|
110
|
+
remote_ops_prepare.prepare(p["preparation"], p["files"], p.get("region"))
|
|
99
111
|
remote_ops.emit("result", files=len(p["files"]))
|
|
100
112
|
|
|
101
113
|
|
|
@@ -108,18 +120,107 @@ SEGMENTS = 4
|
|
|
108
120
|
MIN_SEGMENT_BYTES = 64 << 20
|
|
109
121
|
ATTEMPTS = 5
|
|
110
122
|
WEB = ("http", "https")
|
|
111
|
-
SOURCE_HOSTS = (
|
|
123
|
+
SOURCE_HOSTS = (
|
|
124
|
+
("hf-mirror.com", "hf-mirror"),
|
|
125
|
+
("huggingface.co", "huggingface"),
|
|
126
|
+
("modelscope.cn", "modelscope"),
|
|
127
|
+
("npmmirror.com", "npmmirror"),
|
|
128
|
+
)
|
|
129
|
+
# Which side of the network each host serves best. A host on neither (GitHub, a LAN registry,
|
|
130
|
+
# a user's own mirror) is neutral: it is never a reason to switch the region.
|
|
131
|
+
GLOBAL_HOSTS = ("huggingface.co", "registry.npmjs.org", "nodejs.org")
|
|
132
|
+
CN_HOSTS = ("hf-mirror.com", "modelscope.cn", "npmmirror.com")
|
|
133
|
+
# The same bytes under another host: (global prefix, cn prefix). Region "cn" tries the cn copy
|
|
134
|
+
# first; "global" keeps today's sources first and tries the cn copy only after them.
|
|
135
|
+
ALTERNATES = (
|
|
136
|
+
("https://huggingface.co/", "https://hf-mirror.com/"),
|
|
137
|
+
("https://registry.npmjs.org/", "https://registry.npmmirror.com/"),
|
|
138
|
+
("https://nodejs.org/dist/", "https://cdn.npmmirror.com/binaries/node/"),
|
|
139
|
+
)
|
|
140
|
+
NPM_REGISTRIES = (
|
|
141
|
+
("npm", "https://registry.npmjs.org"),
|
|
142
|
+
("npmmirror", "https://registry.npmmirror.com"),
|
|
143
|
+
)
|
|
144
|
+
# Region cn's order by label; within one rank the plan's order holds. A non-public source (a
|
|
145
|
+
# LAN registry or mirror, remote_ops.non_public) comes first, then ModelScope and the npm
|
|
146
|
+
# mirror, then another neutral source (a user's public mirror, the original GitHub asset), then
|
|
147
|
+
# hf-mirror.com, then the global hosts.
|
|
148
|
+
CN_RANK = {"modelscope": 1, "npmmirror": 1, "custom": 2, "hf-mirror": 3}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def cn_rank(source: remote_ops.Source) -> int:
|
|
152
|
+
return 0 if remote_ops.non_public(source["url"]) else CN_RANK.get(source["source"], 4)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
NPM_OVERHEAD_BYTES = 4 << 20
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _host_in(url: str, domains: tuple[str, ...]) -> bool:
|
|
159
|
+
host = (urllib.parse.urlsplit(url).hostname or "").lower()
|
|
160
|
+
return any(host == d or host.endswith("." + d) for d in domains)
|
|
112
161
|
|
|
113
162
|
|
|
114
163
|
def source_name(url: str) -> str:
|
|
115
|
-
"""The public label of a download URL: huggingface, modelscope or
|
|
116
|
-
|
|
164
|
+
"""The public label of a download URL: huggingface, hf-mirror, modelscope, npmmirror or
|
|
165
|
+
custom (never the URL)."""
|
|
117
166
|
for domain, name in SOURCE_HOSTS:
|
|
118
|
-
if
|
|
167
|
+
if _host_in(url, (domain,)):
|
|
119
168
|
return name
|
|
120
169
|
return "custom"
|
|
121
170
|
|
|
122
171
|
|
|
172
|
+
def side(url: str) -> str:
|
|
173
|
+
"""``cn``, ``global`` or "" (neutral) for a download URL."""
|
|
174
|
+
return "cn" if _host_in(url, CN_HOSTS) else "global" if _host_in(url, GLOBAL_HOSTS) else ""
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def alternates(source: remote_ops.Source) -> list[remote_ops.Source]:
|
|
178
|
+
"""Other hosts that serve the same path: hf-mirror.com for huggingface.co, the npm mirror for
|
|
179
|
+
the npm registry and nodejs.org's releases, and the other way round."""
|
|
180
|
+
found: list[remote_ops.Source] = []
|
|
181
|
+
for pair in ALTERNATES:
|
|
182
|
+
for here, there in (pair, pair[::-1]):
|
|
183
|
+
if source["url"].startswith(here):
|
|
184
|
+
url = there + source["url"][len(here) :]
|
|
185
|
+
other: remote_ops.Source = {"source": source_name(url), "url": url}
|
|
186
|
+
if source.get("member"):
|
|
187
|
+
other["member"] = source["member"]
|
|
188
|
+
found.append(other)
|
|
189
|
+
return found
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def npm_copies(asset: remote_ops.Archive) -> list[remote_ops.Source]:
|
|
193
|
+
"""The npm packages holding a byte-identical copy of ``asset`` (``npm_copy`` in the engine
|
|
194
|
+
and tool locks), on the npm registry and its China mirror; the copy is the package's file of
|
|
195
|
+
the asset's name, and its SHA256 pin is the asset's."""
|
|
196
|
+
copy = asset.get("npm_copy")
|
|
197
|
+
if not copy:
|
|
198
|
+
return []
|
|
199
|
+
name, version = copy["package"], copy["version"]
|
|
200
|
+
tail = f"{name}/-/{name.split('/')[-1]}-{version}.tgz"
|
|
201
|
+
return [
|
|
202
|
+
{"source": label, "url": f"{base}/{tail}", "member": "package/" + asset["name"]}
|
|
203
|
+
for label, base in NPM_REGISTRIES
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def candidates(
|
|
208
|
+
sources: list[remote_ops.Source], region: str | None
|
|
209
|
+
) -> tuple[list[remote_ops.Source], list[remote_ops.Source]]:
|
|
210
|
+
"""(the plan's own sources, the alternates added for the region), without duplicates."""
|
|
211
|
+
own: list[remote_ops.Source] = []
|
|
212
|
+
for s in sources:
|
|
213
|
+
if s.get("url") and all(s["url"] != o["url"] for o in own):
|
|
214
|
+
own.append(s)
|
|
215
|
+
extra: list[remote_ops.Source] = []
|
|
216
|
+
if region in ("cn", "global"):
|
|
217
|
+
for s in own:
|
|
218
|
+
for alt in alternates(s):
|
|
219
|
+
if all(alt["url"] != o["url"] for o in own + extra):
|
|
220
|
+
extra.append(alt)
|
|
221
|
+
return own, extra
|
|
222
|
+
|
|
223
|
+
|
|
123
224
|
def _ranged_request(url: str, start: int, end: int) -> urllib.request.Request:
|
|
124
225
|
request = urllib.request.Request(url, headers={"User-Agent": "localmodels-deploy"})
|
|
125
226
|
request.add_header("Range", f"bytes={start}-{end - 1}")
|
|
@@ -157,9 +258,22 @@ def probe(url: str, size: int) -> tuple[float, bool] | None:
|
|
|
157
258
|
return got / max(1e-3, time.monotonic() - start), ranged
|
|
158
259
|
|
|
159
260
|
|
|
160
|
-
|
|
261
|
+
LONE_SMALL_BYTES = 1 << 20
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def rank(
|
|
265
|
+
sources: list[remote_ops.Source],
|
|
266
|
+
size: int,
|
|
267
|
+
label: str,
|
|
268
|
+
unreachable: list[remote_ops.Source] | None = None,
|
|
269
|
+
) -> list[_Ranked]:
|
|
161
270
|
"""The sources fastest first, each with whether it serves ranges; ones that failed the probe
|
|
162
|
-
go last in plan order, so a passing hiccup still leaves them as
|
|
271
|
+
go last in plan order (and into ``unreachable``), so a passing hiccup still leaves them as
|
|
272
|
+
a fallback. A lone source of a small file is not probed: there is nothing to rank, the
|
|
273
|
+
probe would download the whole file a second time (most of pi's ~120 module tarballs),
|
|
274
|
+
and one plain stream reads it in about the time a resume would save."""
|
|
275
|
+
if len(sources) == 1 and size <= min(PROBE_BYTES, LONE_SMALL_BYTES):
|
|
276
|
+
return [(sources[0], False)]
|
|
163
277
|
measured: list[tuple[float, int, _Ranked]] = []
|
|
164
278
|
failed: list[_Ranked] = []
|
|
165
279
|
notes = []
|
|
@@ -168,6 +282,8 @@ def rank(sources: list[remote_ops.Source], size: int, label: str) -> list[_Ranke
|
|
|
168
282
|
if result is None: # try ranges anyway: a resumed .part must not restart on a hiccup
|
|
169
283
|
failed.append((source, urllib.parse.urlsplit(source["url"]).scheme in WEB))
|
|
170
284
|
notes.append(source["source"] + " unreachable")
|
|
285
|
+
if unreachable is not None:
|
|
286
|
+
unreachable.append(source)
|
|
171
287
|
else:
|
|
172
288
|
measured.append((-result[0], i, (source, result[1])))
|
|
173
289
|
notes.append("{} {:.1f} MB/s".format(source["source"], result[0] / 1e6))
|
|
@@ -178,6 +294,50 @@ def rank(sources: list[remote_ops.Source], size: int, label: str) -> list[_Ranke
|
|
|
178
294
|
return [r for _, _, r in sorted(measured)] + failed
|
|
179
295
|
|
|
180
296
|
|
|
297
|
+
def _web(source: remote_ops.Source) -> bool:
|
|
298
|
+
return urllib.parse.urlsplit(source["url"]).scheme in WEB
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def ordered(
|
|
302
|
+
sources: list[remote_ops.Source],
|
|
303
|
+
size: int,
|
|
304
|
+
label: str,
|
|
305
|
+
region: str | None,
|
|
306
|
+
failed: list[remote_ops.Source],
|
|
307
|
+
) -> Iterator[_Ranked]:
|
|
308
|
+
"""The sources to try in turn. Without a region, ``rank``'s speed order as before. In
|
|
309
|
+
global, the plan's own sources keep that order and the cn alternates follow. In cn, the
|
|
310
|
+
CN_RANK order: each source is probed only when its turn comes, one that fails the probe is
|
|
311
|
+
added to ``failed`` and moved last, and the first that passes is used. npm packages (a
|
|
312
|
+
``member``) cannot be probed for the pinned size; they are tried as they come."""
|
|
313
|
+
own, extra = candidates(sources, region)
|
|
314
|
+
if region != "cn":
|
|
315
|
+
yield from rank([s for s in own if not s.get("member")], size, label, failed)
|
|
316
|
+
rest = [s for s in own if s.get("member")] + extra
|
|
317
|
+
rest.sort(key=lambda s: side(s["url"]) == "cn")
|
|
318
|
+
yield from ((s, _web(s) and not s.get("member")) for s in rest)
|
|
319
|
+
return
|
|
320
|
+
queue = sorted(own + extra, key=cn_rank)
|
|
321
|
+
demoted: list[remote_ops.Source] = []
|
|
322
|
+
notes = []
|
|
323
|
+
for source in queue:
|
|
324
|
+
if source.get("member"):
|
|
325
|
+
yield source, False
|
|
326
|
+
continue
|
|
327
|
+
result = probe(source["url"], size)
|
|
328
|
+
if result is None:
|
|
329
|
+
notes.append(source["source"] + " unreachable")
|
|
330
|
+
failed.append(source)
|
|
331
|
+
demoted.append(source)
|
|
332
|
+
continue
|
|
333
|
+
notes.append("{} {:.1f} MB/s".format(source["source"], result[0] / 1e6))
|
|
334
|
+
remote_ops.emit(
|
|
335
|
+
"log", message="download source for {} (region cn): {}".format(label, ", ".join(notes))
|
|
336
|
+
)
|
|
337
|
+
yield source, result[1]
|
|
338
|
+
yield from ((s, _web(s)) for s in demoted)
|
|
339
|
+
|
|
340
|
+
|
|
181
341
|
class _NoRangeError(Exception):
|
|
182
342
|
"""The source stopped honouring byte ranges; the next source is tried."""
|
|
183
343
|
|
|
@@ -319,6 +479,53 @@ def transfer(source: remote_ops.Source, part: str, size: int, label: str, ranged
|
|
|
319
479
|
_finish(job, label)
|
|
320
480
|
|
|
321
481
|
|
|
482
|
+
def npm_transfer(source: remote_ops.Source, part: str, size: int, label: str) -> None:
|
|
483
|
+
"""Fill ``part`` with the ``member`` file of the npm package at ``source``: the package is
|
|
484
|
+
read in one bounded stream (an npm tarball is a gzip of the file, so a little larger than
|
|
485
|
+
it), then only that regular file of exactly ``size`` bytes is taken. The caller checks its
|
|
486
|
+
SHA256 against the asset's pin as for any other source."""
|
|
487
|
+
archive = part + ".npm"
|
|
488
|
+
cap = size + size // 64 + NPM_OVERHEAD_BYTES
|
|
489
|
+
request = urllib.request.Request(source["url"], headers={"User-Agent": "localmodels-deploy"})
|
|
490
|
+
got, start, mark = 0, time.monotonic(), time.monotonic()
|
|
491
|
+
try:
|
|
492
|
+
with urllib.request.urlopen(request, timeout=60) as r, open(archive, "wb") as out:
|
|
493
|
+
while True:
|
|
494
|
+
chunk = r.read(remote_ops._CHUNK)
|
|
495
|
+
if not chunk:
|
|
496
|
+
break
|
|
497
|
+
got += len(chunk)
|
|
498
|
+
if got > cap:
|
|
499
|
+
raise RuntimeError(f"the npm copy of {label} exceeds its size limit")
|
|
500
|
+
out.write(chunk)
|
|
501
|
+
if time.monotonic() - mark >= remote_ops._PROGRESS_EVERY_S:
|
|
502
|
+
mark = time.monotonic()
|
|
503
|
+
remote_ops.emit(
|
|
504
|
+
"progress",
|
|
505
|
+
phase="download",
|
|
506
|
+
file=label,
|
|
507
|
+
done=min(got, size),
|
|
508
|
+
total=size,
|
|
509
|
+
bytes_per_s=int(got / max(1e-3, mark - start)),
|
|
510
|
+
source=source["source"],
|
|
511
|
+
connections=1,
|
|
512
|
+
**remote_ops.step_fields(min(got, size)),
|
|
513
|
+
)
|
|
514
|
+
with tarfile.open(archive) as tar:
|
|
515
|
+
member = tar.getmember(source["member"])
|
|
516
|
+
stream = tar.extractfile(member) if member.isfile() and member.size == size else None
|
|
517
|
+
if stream is None:
|
|
518
|
+
raise RuntimeError(f"the npm copy of {label} does not hold a {size}-byte file")
|
|
519
|
+
discard(_state_path(part)) # part is rewritten whole, not resumed
|
|
520
|
+
with stream, open(part, "wb") as out:
|
|
521
|
+
shutil.copyfileobj(stream, out, remote_ops._CHUNK)
|
|
522
|
+
except KeyError:
|
|
523
|
+
raise RuntimeError(f"the npm copy of {label} does not hold {source['member']}") from None
|
|
524
|
+
finally:
|
|
525
|
+
if os.path.exists(archive):
|
|
526
|
+
os.remove(archive)
|
|
527
|
+
|
|
528
|
+
|
|
322
529
|
def _finish(job: _Transfer, label: str) -> None:
|
|
323
530
|
if job.errors:
|
|
324
531
|
raise job.errors[0]
|
|
@@ -204,7 +204,7 @@ def _inputs(
|
|
|
204
204
|
raise
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
def _gguf_source(spec: remote_ops.StrataPreparation, work: str) -> str:
|
|
207
|
+
def _gguf_source(spec: remote_ops.StrataPreparation, work: str, region: str | None) -> str:
|
|
208
208
|
asset = spec["gguf_py"]
|
|
209
209
|
if (
|
|
210
210
|
not asset["name"]
|
|
@@ -213,7 +213,9 @@ def _gguf_source(spec: remote_ops.StrataPreparation, work: str) -> str:
|
|
|
213
213
|
):
|
|
214
214
|
raise RuntimeError("Strata preparation source archive needs a file name")
|
|
215
215
|
archive = os.path.join(work, asset["name"])
|
|
216
|
-
remote_ops.fetch(
|
|
216
|
+
remote_ops.fetch(
|
|
217
|
+
asset["url"], archive, asset["sha256"], asset["size_bytes"], asset["name"], None, region
|
|
218
|
+
)
|
|
217
219
|
source_file: remote_ops.Download = {
|
|
218
220
|
"dest": archive,
|
|
219
221
|
"url": asset["url"],
|
|
@@ -232,7 +234,53 @@ def _gguf_source(spec: remote_ops.StrataPreparation, work: str) -> str:
|
|
|
232
234
|
return gguf_py
|
|
233
235
|
|
|
234
236
|
|
|
235
|
-
|
|
237
|
+
HF_API = "https://huggingface.co"
|
|
238
|
+
HF_MIRROR = "https://hf-mirror.com" # region.HF_MIRROR; this bundle imports no controller module
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def hub_endpoints(endpoint: str, region: str | None) -> list[str]:
|
|
242
|
+
"""The Hubs the preparation tools may read, in order: for the plan's default Hugging Face,
|
|
243
|
+
hf-mirror.com beside it (first in cn); a Hub the plan names is the only one. Every output
|
|
244
|
+
is checked against its pin, so the order only decides speed."""
|
|
245
|
+
if endpoint.rstrip("/") != HF_API or region not in ("cn", "global"):
|
|
246
|
+
return [endpoint]
|
|
247
|
+
return [HF_MIRROR, HF_API] if region == "cn" else [HF_API, HF_MIRROR]
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _generate_from_hubs(
|
|
251
|
+
spec: remote_ops.StrataPreparation,
|
|
252
|
+
group: str,
|
|
253
|
+
outputs: _Group,
|
|
254
|
+
stage: str,
|
|
255
|
+
work: str,
|
|
256
|
+
env: dict[str, str],
|
|
257
|
+
lock_fd: int,
|
|
258
|
+
region: str | None,
|
|
259
|
+
) -> None:
|
|
260
|
+
"""Generate one group; a group that reads the Hub (the MTP head) is retried from the other
|
|
261
|
+
Hub when the first fails, and a success there switches the region (``region_fallback``)."""
|
|
262
|
+
hubs = hub_endpoints(spec["hf_endpoint"], region) if group != spec["pack"] else [""]
|
|
263
|
+
for index, hub in enumerate(hubs):
|
|
264
|
+
if hub:
|
|
265
|
+
env["HF_ENDPOINT"] = hub
|
|
266
|
+
try:
|
|
267
|
+
_generate(spec, group, outputs, stage, work, env, lock_fd)
|
|
268
|
+
except RuntimeError as exc:
|
|
269
|
+
if index + 1 == len(hubs):
|
|
270
|
+
raise
|
|
271
|
+
remote_ops.emit("log", phase="prepare", message=f"{exc}; trying the other Hub")
|
|
272
|
+
shutil.rmtree(os.path.join(stage, group), ignore_errors=True)
|
|
273
|
+
continue
|
|
274
|
+
if index:
|
|
275
|
+
side = "cn" if hub == HF_MIRROR else "global"
|
|
276
|
+
switch = {"region_fallback": side} if side != region else {}
|
|
277
|
+
remote_ops.emit("log", phase="prepare", message="read the other Hub", **switch)
|
|
278
|
+
return
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _environment(
|
|
282
|
+
spec: remote_ops.StrataPreparation, gguf_py: str, region: str | None
|
|
283
|
+
) -> dict[str, str]:
|
|
236
284
|
env = {
|
|
237
285
|
key: value for key, value in os.environ.items() if not key.startswith(("PYTHON", "STRATA_"))
|
|
238
286
|
}
|
|
@@ -242,7 +290,7 @@ def _environment(spec: remote_ops.StrataPreparation, gguf_py: str) -> dict[str,
|
|
|
242
290
|
STRATA_MTP_REVISION=spec["mtp_revision"],
|
|
243
291
|
STRATA_ALLOW_UNPINNED="0",
|
|
244
292
|
STRATA_EXIT_WITH_PARENT="1",
|
|
245
|
-
HF_ENDPOINT=spec["hf_endpoint"],
|
|
293
|
+
HF_ENDPOINT=hub_endpoints(spec["hf_endpoint"], region)[0],
|
|
246
294
|
)
|
|
247
295
|
return env
|
|
248
296
|
|
|
@@ -355,8 +403,13 @@ def verify_reused_outputs(files: list[remote_ops.Reusable]) -> None:
|
|
|
355
403
|
_receipt(path, file["sha256"])
|
|
356
404
|
|
|
357
405
|
|
|
358
|
-
def prepare(
|
|
359
|
-
|
|
406
|
+
def prepare(
|
|
407
|
+
spec: remote_ops.StrataPreparation,
|
|
408
|
+
files: list[remote_ops.Reusable],
|
|
409
|
+
region: str | None = None,
|
|
410
|
+
) -> None:
|
|
411
|
+
"""Generate missing groups, check their exact pins, and atomically publish their files.
|
|
412
|
+
In region cn the tools read the Hub through hf-mirror.com unless the plan names its own."""
|
|
360
413
|
if spec["kind"] != KIND or spec["mtp_revision"] != MTP_REVISION:
|
|
361
414
|
raise RuntimeError("unsupported Strata preparation kind or MTP revision")
|
|
362
415
|
if os.name != "posix" or spec["scratch_bytes"] < 0:
|
|
@@ -406,9 +459,9 @@ def prepare(spec: remote_ops.StrataPreparation, files: list[remote_ops.Reusable]
|
|
|
406
459
|
)
|
|
407
460
|
stage = os.path.join(work, "model")
|
|
408
461
|
os.makedirs(stage, mode=0o700, exist_ok=True)
|
|
409
|
-
env = _environment(spec, _gguf_source(spec, work))
|
|
462
|
+
env = _environment(spec, _gguf_source(spec, work, region), region)
|
|
410
463
|
for group, outputs in needed.items():
|
|
411
|
-
|
|
464
|
+
_generate_from_hubs(spec, group, outputs, stage, work, env, lock_fd, region)
|
|
412
465
|
try:
|
|
413
466
|
for relative, file in outputs:
|
|
414
467
|
_require_file(os.path.join(stage, relative), file)
|
|
@@ -35,6 +35,20 @@ def _purgeable(p: remote_ops.RemoveParams, preparation: list[str]) -> list[list[
|
|
|
35
35
|
return [[f, st.st_size, st.st_nlink] for f, st in stats if not os.path.isdir(f)]
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
def _delete_prompt_caches(root: str) -> None:
|
|
39
|
+
"""The kept prompt starts, which hold prompt text: slot_cache.py's prefix.json,
|
|
40
|
+
prefix-tally.json and saved slots (prefix-<hash>.bin) under ``slots``, and a temporary
|
|
41
|
+
file a stop may have left of them."""
|
|
42
|
+
slots = os.path.join(root, "slots")
|
|
43
|
+
if not os.path.isdir(slots):
|
|
44
|
+
return
|
|
45
|
+
for name in os.listdir(slots):
|
|
46
|
+
if name.startswith("prefix") and name.endswith((".json", ".bin", ".tmp")):
|
|
47
|
+
_delete(os.path.join(slots, name))
|
|
48
|
+
if not os.listdir(slots):
|
|
49
|
+
_delete(slots, os.rmdir)
|
|
50
|
+
|
|
51
|
+
|
|
38
52
|
def _delete(path: str, remove: Callable[[str], None] = os.remove) -> None:
|
|
39
53
|
"""Delete one of a stopped service's files or emptied directories. Windows refuses while
|
|
40
54
|
another process still has it open, and a server that was just ended keeps its log and its
|
|
@@ -105,6 +119,7 @@ def _remove(p: remote_ops.RemoveParams, preparation: list[str]) -> None:
|
|
|
105
119
|
]:
|
|
106
120
|
if os.path.exists(remote_ops._expand(path)):
|
|
107
121
|
_delete(remote_ops._expand(path))
|
|
122
|
+
_delete_prompt_caches(paths["root"])
|
|
108
123
|
approved = set(p.get("purge") or []) & {str(f[0]) for f in listed}
|
|
109
124
|
for path in approved:
|
|
110
125
|
if os.path.lexists(path): # the service files above may be listed too
|
|
@@ -652,6 +652,16 @@ def listener_problem(port: int, pids: list[int]) -> str | None:
|
|
|
652
652
|
return None
|
|
653
653
|
|
|
654
654
|
|
|
655
|
+
def group_pids(pid: int) -> list[int]:
|
|
656
|
+
"""A service's recorded process and the live members of the process group it leads. A
|
|
657
|
+
launcher in front of the server (slot_cache.py, auth_proxy.py) is the recorded process; the
|
|
658
|
+
server is its child in that group, and on a card it is the child that holds the memory."""
|
|
659
|
+
try:
|
|
660
|
+
return sorted({pid, *_group_members(pid)})
|
|
661
|
+
except (RuntimeError, OSError): # another owner, or no process list: the recorded process
|
|
662
|
+
return [pid]
|
|
663
|
+
|
|
664
|
+
|
|
655
665
|
def _status_pids(p: remote_ops.ServiceParams, pid: int) -> list[int]:
|
|
656
666
|
if p["service_kind"] != "systemd-user":
|
|
657
667
|
return [pid]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema": "localmodels.runtime-lock/v1",
|
|
3
3
|
"versions": {
|
|
4
4
|
"codex": "0.150.1",
|
|
5
|
-
"claude": "2.1.
|
|
5
|
+
"claude": "2.1.311"
|
|
6
6
|
},
|
|
7
7
|
"artifacts": {
|
|
8
8
|
"codex/win32-x64": [
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
],
|
|
58
58
|
"claude/win32-arm64": [
|
|
59
59
|
{
|
|
60
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
60
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/win32-arm64/claude.exe",
|
|
61
61
|
"algorithm": "sha256",
|
|
62
|
-
"digest": "
|
|
62
|
+
"digest": "951b5d94bf2a5296db2c442784e68d18fa04dec2d7d2e805aa50e75d618aad5e",
|
|
63
63
|
"maxBytes": 419430400,
|
|
64
64
|
"format": "binary",
|
|
65
65
|
"executable": "claude.exe"
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
],
|
|
68
68
|
"claude/win32-x64": [
|
|
69
69
|
{
|
|
70
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
70
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/win32-x64/claude.exe",
|
|
71
71
|
"algorithm": "sha256",
|
|
72
|
-
"digest": "
|
|
72
|
+
"digest": "966f4b2ce962298f5dee6a942e8c47c8f97392e69e728e622319a98b259c0680",
|
|
73
73
|
"maxBytes": 419430400,
|
|
74
74
|
"format": "binary",
|
|
75
75
|
"executable": "claude.exe"
|
|
@@ -77,9 +77,9 @@
|
|
|
77
77
|
],
|
|
78
78
|
"claude/darwin-arm64": [
|
|
79
79
|
{
|
|
80
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
80
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/darwin-arm64/claude",
|
|
81
81
|
"algorithm": "sha256",
|
|
82
|
-
"digest": "
|
|
82
|
+
"digest": "85d8c08707fcfd1e78ffa0204eefbc6ec9e4fe22f375fb2767ef85d957ed3161",
|
|
83
83
|
"maxBytes": 419430400,
|
|
84
84
|
"format": "binary",
|
|
85
85
|
"executable": "claude"
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
],
|
|
88
88
|
"claude/darwin-x64": [
|
|
89
89
|
{
|
|
90
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
90
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/darwin-x64/claude",
|
|
91
91
|
"algorithm": "sha256",
|
|
92
|
-
"digest": "
|
|
92
|
+
"digest": "d34e1cb82015b050471a97574aa6ea6f698ecf3a97a61c980961f43ad9f838f5",
|
|
93
93
|
"maxBytes": 419430400,
|
|
94
94
|
"format": "binary",
|
|
95
95
|
"executable": "claude"
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
],
|
|
98
98
|
"claude/linux-arm64": [
|
|
99
99
|
{
|
|
100
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
100
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/linux-arm64/claude",
|
|
101
101
|
"algorithm": "sha256",
|
|
102
|
-
"digest": "
|
|
102
|
+
"digest": "2e2496c9a8065df93acb0fca2d341f59a6b8777649b2e025ab8c9bcd5eef61f3",
|
|
103
103
|
"maxBytes": 419430400,
|
|
104
104
|
"format": "binary",
|
|
105
105
|
"executable": "claude"
|
|
@@ -107,9 +107,9 @@
|
|
|
107
107
|
],
|
|
108
108
|
"claude/linux-x64": [
|
|
109
109
|
{
|
|
110
|
-
"url": "https://downloads.claude.ai/claude-code-releases/2.1.
|
|
110
|
+
"url": "https://downloads.claude.ai/claude-code-releases/2.1.311/linux-x64/claude",
|
|
111
111
|
"algorithm": "sha256",
|
|
112
|
-
"digest": "
|
|
112
|
+
"digest": "86dc1fcc69498159eaf15f446613e847010f9036bfbbdffd4c49350be8489ada",
|
|
113
113
|
"maxBytes": 419430400,
|
|
114
114
|
"format": "binary",
|
|
115
115
|
"executable": "claude"
|
|
@@ -53,8 +53,10 @@ DOCS: dict[str, tuple[str, str, list[tuple[str, str]]]] = {
|
|
|
53
53
|
"Look the runtime up as status does, then write localmodels.harness-plan/v1 to --out and "
|
|
54
54
|
"print it. A runtime that already answers --version is reused; otherwise the plan pins "
|
|
55
55
|
"the artifacts for this OS and CPU (URL, digest, size limit) for DIR/tools/<runtime>/<version>. "
|
|
56
|
-
"
|
|
57
|
-
"version
|
|
56
|
+
"A fresh install uses the bundled lock; Pi comes with its whole dependency tree. "
|
|
57
|
+
"--before-version selects an earlier stable Codex or Claude release after a failed "
|
|
58
|
+
"launch; Pi has only its pinned release. "
|
|
59
|
+
"No archive is downloaded. The plan's id "
|
|
58
60
|
"(a SHA256 of the plan) is the --approve value.",
|
|
59
61
|
[("%(prog)s --root ~/harness --runtime codex --out plan.json", "")],
|
|
60
62
|
),
|