@simplexai/localmodels-linux-arm64 0.1.0-dev.60 → 0.1.0-dev.61
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 +73 -60
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +5 -3
- package/modules/localmodels/auth_proxy.py +185 -19
- package/modules/localmodels/catalog.json +363 -0
- package/modules/localmodels/catalog.py +1 -1
- package/modules/localmodels/catalog_add.py +5 -5
- package/modules/localmodels/catalog_license.py +2 -0
- package/modules/localmodels/catalog_recipes.py +2 -0
- package/modules/localmodels/cli_parser.py +6 -2
- package/modules/localmodels/context_policy.py +40 -4
- package/modules/localmodels/debug_mode.py +13 -0
- package/modules/localmodels/debug_stub_server.py +156 -1
- package/modules/localmodels/deploy.py +11 -2
- package/modules/localmodels/download-mirrors.json +12 -0
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +26 -0
- package/modules/localmodels/engines-whisper-b5454.json +120 -1
- package/modules/localmodels/gateway_app_bifrost.py +14 -14
- package/modules/localmodels/gateway_bifrost.py +4 -1
- package/modules/localmodels/gateway_cli.py +14 -80
- package/modules/localmodels/gateway_server.py +88 -16
- package/modules/localmodels/gpu_specs.py +35 -1
- package/modules/localmodels/harness.py +1 -2
- package/modules/localmodels/hf_repo.py +12 -4
- package/modules/localmodels/install.py +4 -4
- package/modules/localmodels/library_serve.py +69 -13
- package/modules/localmodels/npm_transport.py +4 -58
- package/modules/localmodels/recommend_cli.py +2 -1
- package/modules/localmodels/remote_ops.py +120 -713
- package/modules/localmodels/remote_ops_common.py +729 -0
- package/modules/localmodels/remote_ops_download.py +397 -381
- package/modules/localmodels/remote_ops_mirrors.py +26 -65
- package/modules/localmodels/remote_ops_prepare.py +43 -35
- package/modules/localmodels/remote_ops_ranges.py +98 -62
- package/modules/localmodels/remote_ops_remove.py +30 -22
- package/modules/localmodels/remote_ops_service.py +102 -95
- package/modules/localmodels/remote_ops_verify.py +94 -63
- package/modules/localmodels/runtime_cli.py +15 -5
- package/modules/localmodels/runtime_io.py +54 -1
- package/modules/localmodels/speech-sv.txt +93 -0
- package/modules/localmodels/speech_admission.py +437 -0
- package/modules/localmodels/speech_catalog.py +170 -0
- package/modules/localmodels/speech_cli.py +273 -0
- package/modules/localmodels/speech_jobs.py +772 -0
- package/modules/localmodels/speech_model.py +404 -0
- package/modules/localmodels/speech_serve.py +287 -0
- package/modules/localmodels/speech_server.py +837 -0
- package/modules/localmodels/speech_state.py +697 -0
- package/modules/localmodels/speech_worker_sensevoice.py +255 -0
- package/modules/localmodels/speech_workers.py +783 -0
- package/modules/localmodels/stack.py +0 -33
- package/modules/localmodels/stack_auto.py +5 -3
- package/modules/localmodels/stack_aux_gpu.py +45 -4
- package/modules/localmodels/stack_capacity.py +77 -8
- package/modules/localmodels/stack_cli.py +16 -1
- package/modules/localmodels/stack_compose.py +1 -1
- package/modules/localmodels/stack_down.py +24 -1
- package/modules/localmodels/stack_hardware.py +57 -88
- package/modules/localmodels/stack_hardware_text.py +4 -59
- package/modules/localmodels/stack_memory.py +13 -3
- package/modules/localmodels/stack_suite.py +9 -10
- package/modules/localmodels/stack_summary.py +4 -4
- package/modules/localmodels/stack_view_llm.py +1 -1
- package/modules/localmodels/transport.py +3 -2
- package/modules/localmodels/tui_views.py +2 -2
- package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/RECORD +70 -57
- package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/NOTICE +9 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -8,7 +8,6 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
import collections
|
|
10
10
|
import contextlib
|
|
11
|
-
import json
|
|
12
11
|
import os
|
|
13
12
|
import shutil
|
|
14
13
|
import tarfile
|
|
@@ -18,9 +17,9 @@ import urllib.request
|
|
|
18
17
|
from typing import Iterator
|
|
19
18
|
|
|
20
19
|
try:
|
|
21
|
-
from localmodels import
|
|
20
|
+
from localmodels import remote_ops_common
|
|
22
21
|
except ImportError: # run as a bare file from this directory
|
|
23
|
-
import
|
|
22
|
+
import remote_ops_common # type: ignore[import-not-found,no-redef]
|
|
24
23
|
|
|
25
24
|
RATE_WINDOW_S = 10.0
|
|
26
25
|
|
|
@@ -119,8 +118,8 @@ CN_RANK: dict[str, int] = {
|
|
|
119
118
|
}
|
|
120
119
|
|
|
121
120
|
|
|
122
|
-
def cn_rank(source:
|
|
123
|
-
return 0 if
|
|
121
|
+
def cn_rank(source: remote_ops_common.Source) -> int:
|
|
122
|
+
return 0 if remote_ops_common.non_public(source["url"]) else CN_RANK.get(source["source"], 4)
|
|
124
123
|
|
|
125
124
|
|
|
126
125
|
def _host_in(url: str, domains: tuple[str, ...]) -> bool:
|
|
@@ -141,13 +140,13 @@ def side(url: str) -> str:
|
|
|
141
140
|
return "cn" if _host_in(url, CN_HOSTS) else "global" if _host_in(url, GLOBAL_HOSTS) else ""
|
|
142
141
|
|
|
143
142
|
|
|
144
|
-
def is_web(source:
|
|
143
|
+
def is_web(source: remote_ops_common.Source) -> bool:
|
|
145
144
|
return urllib.parse.urlsplit(source["url"]).scheme in WEB
|
|
146
145
|
|
|
147
146
|
|
|
148
|
-
def alternates(source:
|
|
147
|
+
def alternates(source: remote_ops_common.Source) -> list[remote_ops_common.Source]:
|
|
149
148
|
"""Other hosts that serve byte-identical files at the same path."""
|
|
150
|
-
found: list[
|
|
149
|
+
found: list[remote_ops_common.Source] = []
|
|
151
150
|
seen = {source["url"]}
|
|
152
151
|
for group in MIRROR_GROUPS:
|
|
153
152
|
for here in group:
|
|
@@ -160,14 +159,14 @@ def alternates(source: remote_ops.Source) -> list[remote_ops.Source]:
|
|
|
160
159
|
if url in seen:
|
|
161
160
|
continue
|
|
162
161
|
seen.add(url)
|
|
163
|
-
other:
|
|
162
|
+
other: remote_ops_common.Source = {"source": source_name(url), "url": url}
|
|
164
163
|
if source.get("member"):
|
|
165
164
|
other["member"] = source["member"]
|
|
166
165
|
found.append(other)
|
|
167
166
|
return found
|
|
168
167
|
|
|
169
168
|
|
|
170
|
-
def npm_copies(asset:
|
|
169
|
+
def npm_copies(asset: remote_ops_common.Archive) -> list[remote_ops_common.Source]:
|
|
171
170
|
"""The npm packages holding a byte-identical copy of ``asset`` (``npm_copy`` in the engine
|
|
172
171
|
and tool locks), on the npm registry and its China mirror; the copy is the package's file of
|
|
173
172
|
the asset's name, and its SHA256 pin is the asset's."""
|
|
@@ -183,14 +182,14 @@ def npm_copies(asset: remote_ops.Archive) -> list[remote_ops.Source]:
|
|
|
183
182
|
|
|
184
183
|
|
|
185
184
|
def candidates(
|
|
186
|
-
sources: list[
|
|
187
|
-
) -> tuple[list[
|
|
185
|
+
sources: list[remote_ops_common.Source], region: str | None
|
|
186
|
+
) -> tuple[list[remote_ops_common.Source], list[remote_ops_common.Source]]:
|
|
188
187
|
"""(the plan's own sources, the alternates added for the region), without duplicates."""
|
|
189
|
-
own: list[
|
|
188
|
+
own: list[remote_ops_common.Source] = []
|
|
190
189
|
for s in sources:
|
|
191
190
|
if s.get("url") and all(s["url"] != o["url"] for o in own):
|
|
192
191
|
own.append(s)
|
|
193
|
-
extra: list[
|
|
192
|
+
extra: list[remote_ops_common.Source] = []
|
|
194
193
|
if region in ("cn", "global"):
|
|
195
194
|
for s in own:
|
|
196
195
|
for alt in alternates(s):
|
|
@@ -201,50 +200,12 @@ def candidates(
|
|
|
201
200
|
|
|
202
201
|
NPM_OVERHEAD_BYTES = 4 << 20
|
|
203
202
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
try:
|
|
211
|
-
state = json.loads(remote_ops._read(state_path(part)))
|
|
212
|
-
segments = [[int(a), int(b), int(c)] for a, b, c in state["segments"]]
|
|
213
|
-
except (OSError, ValueError, KeyError, TypeError):
|
|
214
|
-
return None
|
|
215
|
-
if state.get("size") != size or not os.path.exists(part) or os.path.getsize(part) != size:
|
|
216
|
-
return None
|
|
217
|
-
if any(not 0 <= start <= done <= end <= size for start, end, done in segments):
|
|
218
|
-
return None
|
|
219
|
-
return segments
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def save_ranges(part: str, size: int, segments: list[list[int]]) -> None:
|
|
223
|
-
path = state_path(part)
|
|
224
|
-
remote_ops._write(path + ".tmp", json.dumps({"size": size, "segments": segments}))
|
|
225
|
-
os.replace(path + ".tmp", path)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
def kept_bytes(part: str, size: int) -> int:
|
|
229
|
-
"""Bytes of ``part`` already downloaded: its ranges record when it has one, else its size."""
|
|
230
|
-
segments = load_ranges(part, size)
|
|
231
|
-
if segments is not None:
|
|
232
|
-
return size - sum(end - done for _, end, done in segments)
|
|
233
|
-
return os.path.getsize(part) if os.path.exists(part) else 0
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def discard(part: str) -> None:
|
|
237
|
-
for path in (part, state_path(part), state_path(part) + ".tmp", part + ".tmp", part + ".npm"):
|
|
238
|
-
try:
|
|
239
|
-
os.remove(path)
|
|
240
|
-
except FileNotFoundError:
|
|
241
|
-
pass
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
def clear_link(target: str) -> None:
|
|
245
|
-
"""Remove an existing file or symlink before tar.extract recreates a link member."""
|
|
246
|
-
if os.path.islink(target) or os.path.isfile(target):
|
|
247
|
-
os.unlink(target)
|
|
203
|
+
state_path = remote_ops_common.state_path
|
|
204
|
+
load_ranges = remote_ops_common.load_ranges
|
|
205
|
+
save_ranges = remote_ops_common.save_ranges
|
|
206
|
+
kept_bytes = remote_ops_common.kept_bytes
|
|
207
|
+
discard = remote_ops_common.discard
|
|
208
|
+
clear_link = remote_ops_common.clear_link
|
|
248
209
|
|
|
249
210
|
|
|
250
211
|
@contextlib.contextmanager
|
|
@@ -279,7 +240,7 @@ def engine_lock(directory: str) -> Iterator[None]:
|
|
|
279
240
|
|
|
280
241
|
|
|
281
242
|
def npm_transfer(
|
|
282
|
-
source:
|
|
243
|
+
source: remote_ops_common.Source,
|
|
283
244
|
part: str,
|
|
284
245
|
size: int,
|
|
285
246
|
label: str,
|
|
@@ -296,16 +257,16 @@ def npm_transfer(
|
|
|
296
257
|
try:
|
|
297
258
|
with urllib.request.urlopen(request, timeout=60) as r, open(archive, "wb") as out:
|
|
298
259
|
while True:
|
|
299
|
-
chunk = r.read(
|
|
260
|
+
chunk = r.read(remote_ops_common.CHUNK)
|
|
300
261
|
if not chunk:
|
|
301
262
|
break
|
|
302
263
|
got += len(chunk)
|
|
303
264
|
if got > cap:
|
|
304
265
|
raise RuntimeError(f"the npm copy of {label} exceeds its size limit")
|
|
305
266
|
out.write(chunk)
|
|
306
|
-
if time.monotonic() - mark >=
|
|
267
|
+
if time.monotonic() - mark >= remote_ops_common.PROGRESS_EVERY_S:
|
|
307
268
|
mark = time.monotonic()
|
|
308
|
-
|
|
269
|
+
remote_ops_common.emit(
|
|
309
270
|
"progress",
|
|
310
271
|
phase="download",
|
|
311
272
|
file=label,
|
|
@@ -314,16 +275,16 @@ def npm_transfer(
|
|
|
314
275
|
bytes_per_s=int(got / max(1e-3, mark - start)),
|
|
315
276
|
source=source["source"],
|
|
316
277
|
connections=1,
|
|
317
|
-
**
|
|
278
|
+
**remote_ops_common.step_fields(min(got, size)),
|
|
318
279
|
)
|
|
319
280
|
with tarfile.open(archive) as tar:
|
|
320
281
|
member = tar.getmember(source["member"])
|
|
321
282
|
stream = tar.extractfile(member) if member.isfile() and member.size == size else None
|
|
322
283
|
if stream is None:
|
|
323
284
|
raise RuntimeError(f"the npm copy of {label} does not hold a {size}-byte file")
|
|
324
|
-
discard(state_path(part)) #
|
|
285
|
+
remote_ops_common.discard(remote_ops_common.state_path(part)) # rewritten whole
|
|
325
286
|
with stream, open(part, "wb") as out:
|
|
326
|
-
shutil.copyfileobj(stream, out,
|
|
287
|
+
shutil.copyfileobj(stream, out, remote_ops_common.CHUNK)
|
|
327
288
|
except KeyError:
|
|
328
289
|
raise RuntimeError(f"the npm copy of {label} does not hold {source['member']}") from None
|
|
329
290
|
finally:
|
|
@@ -17,17 +17,18 @@ import stat
|
|
|
17
17
|
import subprocess
|
|
18
18
|
import tempfile
|
|
19
19
|
from collections.abc import Iterator
|
|
20
|
-
from typing import List, Tuple
|
|
20
|
+
from typing import Callable, List, Optional, Tuple
|
|
21
21
|
|
|
22
22
|
try:
|
|
23
|
-
from localmodels import
|
|
23
|
+
from localmodels import remote_ops_common
|
|
24
24
|
except ImportError: # run as a bare file from this directory
|
|
25
|
-
import
|
|
25
|
+
import remote_ops_common # type: ignore[import-not-found,no-redef]
|
|
26
26
|
|
|
27
27
|
KIND = "strata-qwen4exp-v1"
|
|
28
28
|
MTP_REVISION = "de4b8e4d43b917e7706784d8bb445c9af86a3540"
|
|
29
29
|
TOOL_TIMEOUT_S = 7200
|
|
30
|
-
_Group = List[Tuple[str, "
|
|
30
|
+
_Group = List[Tuple[str, "remote_ops_common.Reusable"]]
|
|
31
|
+
_FetchFn = Callable[..., Optional[str]]
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def _private_dir(path: str) -> None:
|
|
@@ -72,7 +73,7 @@ def _locked(directory: str) -> Iterator[int]:
|
|
|
72
73
|
def purge_workspace(model_dir: str | None, *, remove_empty: bool = False) -> Iterator[list[str]]:
|
|
73
74
|
"""List owned preparation files and hold their writer lock through approved removal."""
|
|
74
75
|
private = (
|
|
75
|
-
os.path.join(os.path.realpath(
|
|
76
|
+
os.path.join(os.path.realpath(remote_ops_common.expand(model_dir)), ".prepare")
|
|
76
77
|
if model_dir
|
|
77
78
|
else ""
|
|
78
79
|
)
|
|
@@ -106,7 +107,7 @@ def purge_workspace(model_dir: str | None, *, remove_empty: bool = False) -> Ite
|
|
|
106
107
|
|
|
107
108
|
|
|
108
109
|
def _relative(root: str, path: str) -> str:
|
|
109
|
-
expanded =
|
|
110
|
+
expanded = remote_ops_common.expand(path)
|
|
110
111
|
canonical = os.path.join(
|
|
111
112
|
os.path.realpath(os.path.dirname(expanded)), os.path.basename(expanded)
|
|
112
113
|
)
|
|
@@ -116,7 +117,7 @@ def _relative(root: str, path: str) -> str:
|
|
|
116
117
|
|
|
117
118
|
|
|
118
119
|
def _groups(
|
|
119
|
-
spec:
|
|
120
|
+
spec: remote_ops_common.StrataPreparation, files: list[remote_ops_common.Reusable], root: str
|
|
120
121
|
) -> dict[str, _Group]:
|
|
121
122
|
pack = spec["pack"]
|
|
122
123
|
if not pack.startswith("packs/") or any(p in ("", ".", "..") for p in pack.split("/")):
|
|
@@ -139,12 +140,12 @@ def _groups(
|
|
|
139
140
|
return groups
|
|
140
141
|
|
|
141
142
|
|
|
142
|
-
def _valid(path: str, file:
|
|
143
|
+
def _valid(path: str, file: remote_ops_common.Download) -> bool:
|
|
143
144
|
return (
|
|
144
145
|
os.path.isfile(path)
|
|
145
146
|
and not os.path.islink(path)
|
|
146
147
|
and os.path.getsize(path) == file["size_bytes"]
|
|
147
|
-
and
|
|
148
|
+
and remote_ops_common.sha256_file(path, os.path.basename(path)) == file["sha256"]
|
|
148
149
|
)
|
|
149
150
|
|
|
150
151
|
|
|
@@ -158,7 +159,7 @@ def _discard_receipt(path: str) -> None:
|
|
|
158
159
|
def _receipt(path: str, digest: str) -> None:
|
|
159
160
|
marker = path + ".sha256"
|
|
160
161
|
try:
|
|
161
|
-
if
|
|
162
|
+
if remote_ops_common.read_text(marker).strip() == digest:
|
|
162
163
|
return
|
|
163
164
|
except (OSError, UnicodeError):
|
|
164
165
|
pass
|
|
@@ -172,19 +173,19 @@ def _receipt(path: str, digest: str) -> None:
|
|
|
172
173
|
os.unlink(temporary)
|
|
173
174
|
|
|
174
175
|
|
|
175
|
-
def _require_file(path: str, file:
|
|
176
|
+
def _require_file(path: str, file: remote_ops_common.Download) -> None:
|
|
176
177
|
label = os.path.basename(path)
|
|
177
178
|
if not os.path.isfile(path) or os.path.getsize(path) != file["size_bytes"]:
|
|
178
179
|
raise RuntimeError(f"Strata preparation {label} size mismatch")
|
|
179
|
-
if os.path.islink(path) or
|
|
180
|
+
if os.path.islink(path) or remote_ops_common.sha256_file(path, label) != file["sha256"]:
|
|
180
181
|
raise RuntimeError(f"Strata preparation {label} SHA256 mismatch")
|
|
181
182
|
|
|
182
183
|
|
|
183
184
|
def _inputs(
|
|
184
|
-
spec:
|
|
185
|
+
spec: remote_ops_common.StrataPreparation, files: list[remote_ops_common.Reusable], root: str
|
|
185
186
|
) -> None:
|
|
186
|
-
sources = {
|
|
187
|
-
first =
|
|
187
|
+
sources = {remote_ops_common.expand(f["dest"]): f for f in files if not f.get("generated")}
|
|
188
|
+
first = remote_ops_common.expand(spec["gguf"])
|
|
188
189
|
if first not in sources:
|
|
189
190
|
raise RuntimeError("Strata preparation GGUF must be a declared input")
|
|
190
191
|
_relative(root, first)
|
|
@@ -204,7 +205,12 @@ def _inputs(
|
|
|
204
205
|
raise
|
|
205
206
|
|
|
206
207
|
|
|
207
|
-
def _gguf_source(
|
|
208
|
+
def _gguf_source(
|
|
209
|
+
spec: remote_ops_common.StrataPreparation,
|
|
210
|
+
work: str,
|
|
211
|
+
region: str | None,
|
|
212
|
+
fetch_fn: _FetchFn,
|
|
213
|
+
) -> str:
|
|
208
214
|
asset = spec["gguf_py"]
|
|
209
215
|
if (
|
|
210
216
|
not asset["name"]
|
|
@@ -213,10 +219,10 @@ def _gguf_source(spec: remote_ops.StrataPreparation, work: str, region: str | No
|
|
|
213
219
|
):
|
|
214
220
|
raise RuntimeError("Strata preparation source archive needs a file name")
|
|
215
221
|
archive = os.path.join(work, asset["name"])
|
|
216
|
-
|
|
222
|
+
fetch_fn(
|
|
217
223
|
asset["url"], archive, asset["sha256"], asset["size_bytes"], asset["name"], None, region
|
|
218
224
|
)
|
|
219
|
-
source_file:
|
|
225
|
+
source_file: remote_ops_common.Download = {
|
|
220
226
|
"dest": archive,
|
|
221
227
|
"url": asset["url"],
|
|
222
228
|
"size_bytes": asset["size_bytes"],
|
|
@@ -227,7 +233,7 @@ def _gguf_source(spec: remote_ops.StrataPreparation, work: str, region: str | No
|
|
|
227
233
|
if os.path.exists(source):
|
|
228
234
|
shutil.rmtree(source)
|
|
229
235
|
os.mkdir(source, 0o700)
|
|
230
|
-
|
|
236
|
+
remote_ops_common.unpack(archive, source)
|
|
231
237
|
gguf_py = os.path.join(source, "gguf-py")
|
|
232
238
|
if not os.path.isdir(os.path.join(gguf_py, "gguf")):
|
|
233
239
|
raise RuntimeError("the pinned Strata preparation source has no gguf-py")
|
|
@@ -248,7 +254,7 @@ def hub_endpoints(endpoint: str, region: str | None) -> list[str]:
|
|
|
248
254
|
|
|
249
255
|
|
|
250
256
|
def _generate_from_hubs(
|
|
251
|
-
spec:
|
|
257
|
+
spec: remote_ops_common.StrataPreparation,
|
|
252
258
|
group: str,
|
|
253
259
|
outputs: _Group,
|
|
254
260
|
stage: str,
|
|
@@ -268,18 +274,18 @@ def _generate_from_hubs(
|
|
|
268
274
|
except RuntimeError as exc:
|
|
269
275
|
if index + 1 == len(hubs):
|
|
270
276
|
raise
|
|
271
|
-
|
|
277
|
+
remote_ops_common.emit("log", phase="prepare", message=f"{exc}; trying the other Hub")
|
|
272
278
|
shutil.rmtree(os.path.join(stage, group), ignore_errors=True)
|
|
273
279
|
continue
|
|
274
280
|
if index:
|
|
275
281
|
side = "cn" if hub == HF_MIRROR else "global"
|
|
276
282
|
switch = {"region_fallback": side} if side != region else {}
|
|
277
|
-
|
|
283
|
+
remote_ops_common.emit("log", phase="prepare", message="read the other Hub", **switch)
|
|
278
284
|
return
|
|
279
285
|
|
|
280
286
|
|
|
281
287
|
def _environment(
|
|
282
|
-
spec:
|
|
288
|
+
spec: remote_ops_common.StrataPreparation, gguf_py: str, region: str | None
|
|
283
289
|
) -> dict[str, str]:
|
|
284
290
|
env = {
|
|
285
291
|
key: value for key, value in os.environ.items() if not key.startswith(("PYTHON", "STRATA_"))
|
|
@@ -296,19 +302,19 @@ def _environment(
|
|
|
296
302
|
|
|
297
303
|
|
|
298
304
|
def _run(
|
|
299
|
-
spec:
|
|
305
|
+
spec: remote_ops_common.StrataPreparation,
|
|
300
306
|
tool: str,
|
|
301
307
|
args: list[str],
|
|
302
308
|
work: str,
|
|
303
309
|
env: dict[str, str],
|
|
304
310
|
lock_fd: int,
|
|
305
311
|
) -> None:
|
|
306
|
-
engine =
|
|
312
|
+
engine = remote_ops_common.expand(spec["engine_dir"])
|
|
307
313
|
python = os.path.join(engine, "python", "bin", "python3")
|
|
308
314
|
script = os.path.join(engine, "tools", tool)
|
|
309
315
|
if not os.access(python, os.X_OK) or not os.path.isfile(script):
|
|
310
316
|
raise RuntimeError(f"the pinned Strata control package has no preparation tool {tool}")
|
|
311
|
-
|
|
317
|
+
remote_ops_common.emit("log", phase="prepare", message="preparing Strata artifacts: " + tool)
|
|
312
318
|
with open(os.path.join(work, tool + ".log"), "w", encoding="utf-8") as log:
|
|
313
319
|
try:
|
|
314
320
|
result = subprocess.run(
|
|
@@ -332,7 +338,7 @@ def _run(
|
|
|
332
338
|
|
|
333
339
|
|
|
334
340
|
def _generate(
|
|
335
|
-
spec:
|
|
341
|
+
spec: remote_ops_common.StrataPreparation,
|
|
336
342
|
group: str,
|
|
337
343
|
outputs: _Group,
|
|
338
344
|
stage: str,
|
|
@@ -342,7 +348,7 @@ def _generate(
|
|
|
342
348
|
) -> None:
|
|
343
349
|
output = os.path.join(stage, group)
|
|
344
350
|
if group == spec["pack"]:
|
|
345
|
-
args = ["--gguf",
|
|
351
|
+
args = ["--gguf", remote_ops_common.expand(spec["gguf"]), "--out", output]
|
|
346
352
|
_run(spec, "strata_tokenizer.py", args, work, env, lock_fd)
|
|
347
353
|
# iq_pack otherwise starts a child without passing our lock. Extract first so every
|
|
348
354
|
# writer is a directly supervised tool that retains the lock if this action is killed.
|
|
@@ -379,17 +385,17 @@ def _generate(
|
|
|
379
385
|
lock_fd,
|
|
380
386
|
)
|
|
381
387
|
shutil.copyfile(
|
|
382
|
-
os.path.join(
|
|
388
|
+
os.path.join(remote_ops_common.expand(spec["engine_dir"]), "data", "draft_vocab.bin"),
|
|
383
389
|
os.path.join(output, "draft_vocab.bin"),
|
|
384
390
|
)
|
|
385
391
|
|
|
386
392
|
|
|
387
|
-
def verify_reused_outputs(files: list[
|
|
393
|
+
def verify_reused_outputs(files: list[remote_ops_common.Reusable]) -> None:
|
|
388
394
|
"""Without a conversion recipe, every generated destination must already match its pin."""
|
|
389
395
|
for file in files:
|
|
390
396
|
if not file.get("generated"):
|
|
391
397
|
continue
|
|
392
|
-
path =
|
|
398
|
+
path = remote_ops_common.expand(file["dest"])
|
|
393
399
|
try:
|
|
394
400
|
if file["url"] or file.get("mirrors"):
|
|
395
401
|
raise RuntimeError("generated outputs cannot have download URLs")
|
|
@@ -404,9 +410,11 @@ def verify_reused_outputs(files: list[remote_ops.Reusable]) -> None:
|
|
|
404
410
|
|
|
405
411
|
|
|
406
412
|
def prepare(
|
|
407
|
-
spec:
|
|
408
|
-
files: list[
|
|
413
|
+
spec: remote_ops_common.StrataPreparation,
|
|
414
|
+
files: list[remote_ops_common.Reusable],
|
|
409
415
|
region: str | None = None,
|
|
416
|
+
*,
|
|
417
|
+
fetch_fn: _FetchFn,
|
|
410
418
|
) -> None:
|
|
411
419
|
"""Generate missing groups, check their exact pins, and atomically publish their files.
|
|
412
420
|
In region cn the tools read the Hub through hf-mirror.com unless the plan names its own."""
|
|
@@ -414,7 +422,7 @@ def prepare(
|
|
|
414
422
|
raise RuntimeError("unsupported Strata preparation kind or MTP revision")
|
|
415
423
|
if os.name != "posix" or spec["scratch_bytes"] < 0:
|
|
416
424
|
raise RuntimeError("Strata preparation requires POSIX and a bounded workspace")
|
|
417
|
-
root = os.path.realpath(
|
|
425
|
+
root = os.path.realpath(remote_ops_common.expand(spec["model_dir"]))
|
|
418
426
|
groups = _groups(spec, files, root)
|
|
419
427
|
os.makedirs(root, exist_ok=True)
|
|
420
428
|
private = os.path.join(root, ".prepare")
|
|
@@ -459,7 +467,7 @@ def prepare(
|
|
|
459
467
|
)
|
|
460
468
|
stage = os.path.join(work, "model")
|
|
461
469
|
os.makedirs(stage, mode=0o700, exist_ok=True)
|
|
462
|
-
env = _environment(spec, _gguf_source(spec, work, region), region)
|
|
470
|
+
env = _environment(spec, _gguf_source(spec, work, region, fetch_fn), region)
|
|
463
471
|
for group, outputs in needed.items():
|
|
464
472
|
_generate_from_hubs(spec, group, outputs, stage, work, env, lock_fd, region)
|
|
465
473
|
try:
|