@simplexai/localmodels-linux-x64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.35
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 +138 -97
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +4 -0
- package/modules/localmodels/app.py +7 -2
- package/modules/localmodels/approval.py +4 -4
- package/modules/localmodels/bifrost_checks.py +121 -3
- package/modules/localmodels/bifrost_provider.py +53 -0
- package/modules/localmodels/bifrost_unit.py +32 -1
- package/modules/localmodels/budget.py +5 -1
- package/modules/localmodels/catalog.json +51 -10
- package/modules/localmodels/catalog.py +30 -29
- package/modules/localmodels/catalog_add.py +1 -0
- package/modules/localmodels/cli_parser.py +10 -2
- package/modules/localmodels/component.py +7 -1
- package/modules/localmodels/decode_calibration.json +6 -0
- package/modules/localmodels/decode_calibration.py +104 -0
- package/modules/localmodels/deploy.py +44 -7
- package/modules/localmodels/deploy_steps.py +10 -1
- package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
- package/modules/localmodels/engines.json +57 -1
- package/modules/localmodels/engines.py +6 -2
- package/modules/localmodels/estimator.py +21 -7
- package/modules/localmodels/frontend.py +4 -4
- package/modules/localmodels/gateway.py +14 -4
- package/modules/localmodels/gateway_app_bifrost.py +4 -3
- package/modules/localmodels/gateway_bifrost.py +70 -57
- package/modules/localmodels/gateway_probe.py +3 -4
- package/modules/localmodels/gguf.py +7 -0
- package/modules/localmodels/harness.py +24 -25
- package/modules/localmodels/harness_gateway.py +19 -10
- package/modules/localmodels/harness_probe.py +33 -6
- package/modules/localmodels/hosts.py +73 -9
- package/modules/localmodels/install.py +36 -6
- package/modules/localmodels/library_cli.py +179 -0
- package/modules/localmodels/library_convert.py +132 -0
- package/modules/localmodels/library_gateway.py +471 -0
- package/modules/localmodels/library_jobs.py +314 -0
- package/modules/localmodels/library_model.py +246 -0
- package/modules/localmodels/library_pricing.py +347 -0
- package/modules/localmodels/library_serve.py +348 -0
- package/modules/localmodels/library_state.py +373 -0
- package/modules/localmodels/library_status.py +349 -0
- package/modules/localmodels/llm_rank.py +16 -2
- package/modules/localmodels/memcalc.py +7 -30
- package/modules/localmodels/metal.py +26 -0
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/preparation.py +49 -0
- package/modules/localmodels/probe.py +8 -8
- package/modules/localmodels/process_identity.py +536 -9
- package/modules/localmodels/quant_formats.py +123 -0
- package/modules/localmodels/recommend_cli.py +8 -4
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +104 -6
- package/modules/localmodels/remote_ops_download.py +17 -2
- package/modules/localmodels/remote_ops_prepare.py +406 -0
- package/modules/localmodels/remote_ops_remove.py +40 -7
- package/modules/localmodels/remote_ops_service.py +110 -8
- package/modules/localmodels/remote_ops_verify.py +15 -2
- package/modules/localmodels/runtime_auth.py +31 -1
- package/modules/localmodels/runtime_cli.py +3 -4
- package/modules/localmodels/runtime_io.py +50 -6
- package/modules/localmodels/service_autostart.py +45 -1
- package/modules/localmodels/service_control.py +13 -0
- package/modules/localmodels/service_deployment.py +12 -3
- package/modules/localmodels/service_jobs.py +33 -4
- package/modules/localmodels/service_probe.py +67 -13
- package/modules/localmodels/service_stop.py +152 -0
- package/modules/localmodels/service_worker.py +9 -1
- package/modules/localmodels/services_cli.py +50 -6
- package/modules/localmodels/setup_inspection.py +34 -25
- package/modules/localmodels/setup_text.py +118 -0
- package/modules/localmodels/sizecalc.py +625 -0
- package/modules/localmodels/sizecalc_cli.py +249 -0
- package/modules/localmodels/stack.py +69 -17
- package/modules/localmodels/stack_args.py +91 -19
- package/modules/localmodels/stack_auto.py +78 -0
- package/modules/localmodels/stack_binding.py +23 -35
- package/modules/localmodels/stack_card.py +195 -0
- package/modules/localmodels/stack_cleanup.py +379 -0
- package/modules/localmodels/stack_clients.py +4 -1
- package/modules/localmodels/stack_compose.py +150 -194
- package/modules/localmodels/stack_console.py +2 -0
- package/modules/localmodels/stack_decision.py +3 -2
- package/modules/localmodels/stack_down.py +189 -0
- package/modules/localmodels/stack_events.py +54 -0
- package/modules/localmodels/stack_hardware.py +22 -23
- package/modules/localmodels/stack_journal.py +29 -8
- package/modules/localmodels/stack_ledger.py +411 -0
- package/modules/localmodels/stack_lifecycle.py +162 -167
- package/modules/localmodels/stack_llm_ram.py +57 -5
- package/modules/localmodels/stack_memory.py +721 -0
- package/modules/localmodels/stack_picks.py +139 -0
- package/modules/localmodels/stack_plan.py +140 -22
- package/modules/localmodels/stack_ports.py +22 -0
- package/modules/localmodels/stack_preflight.py +699 -0
- package/modules/localmodels/stack_review.py +123 -5
- package/modules/localmodels/stack_rollback.py +2 -0
- package/modules/localmodels/stack_route.py +256 -0
- package/modules/localmodels/stack_run.py +11 -0
- package/modules/localmodels/stack_suite.py +102 -17
- package/modules/localmodels/stack_summary.py +65 -4
- package/modules/localmodels/stack_try.py +354 -0
- package/modules/localmodels/stack_try_client.py +194 -0
- package/modules/localmodels/stack_try_docs.py +139 -0
- package/modules/localmodels/stack_up.py +8 -1
- package/modules/localmodels/stack_update.py +29 -4
- package/modules/localmodels/stack_verify.py +3 -1
- package/modules/localmodels/stack_view.py +10 -11
- package/modules/localmodels/stack_view_apply.py +4 -2
- package/modules/localmodels/stack_view_events.py +2 -1
- package/modules/localmodels/stack_view_serve.py +3 -0
- package/modules/localmodels/stack_view_text.py +1 -1
- package/modules/localmodels/stack_view_words.py +4 -1
- package/modules/localmodels/stack_warm.py +574 -0
- package/modules/localmodels/stack_whatif.py +558 -0
- package/modules/localmodels/suite.py +48 -39
- package/modules/localmodels/tool_archive.py +40 -0
- package/modules/localmodels/tools.json +8 -0
- package/modules/localmodels/transport.py +1 -0
- package/modules/localmodels/vision.py +8 -1
- package/modules/localmodels/web/sizecalc/app.js +431 -0
- package/modules/localmodels/web/sizecalc/calc.js +269 -0
- package/modules/localmodels/web/sizecalc/page.html +362 -0
- package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/logo-claude.svg +3 -0
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/localmodels/web/view/logo-pi.svg +6 -0
- package/modules/localmodels/web/view/view.css +4 -0
- package/modules/localmodels/web/view/view.js +15 -6
- package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/METADATA +1 -1
- package/modules/simplex_localmodels-0.1.0.dev35.dist-info/RECORD +241 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Materialize pinned Strata outputs inside the download action (stdlib, Python 3.8+).
|
|
3
|
+
|
|
4
|
+
Only the bundled conversion tools run here. They write to a private workspace; exact output
|
|
5
|
+
pins are checked before a group is published, so a reused hardlink is never modified in place.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import shutil
|
|
16
|
+
import stat
|
|
17
|
+
import subprocess
|
|
18
|
+
import tempfile
|
|
19
|
+
from collections.abc import Iterator
|
|
20
|
+
from typing import List, Tuple
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from localmodels import remote_ops
|
|
24
|
+
except ImportError: # run as a bare file from this directory
|
|
25
|
+
import remote_ops # type: ignore[import-not-found,no-redef]
|
|
26
|
+
|
|
27
|
+
KIND = "strata-qwen4exp-v1"
|
|
28
|
+
MTP_REVISION = "de4b8e4d43b917e7706784d8bb445c9af86a3540"
|
|
29
|
+
TOOL_TIMEOUT_S = 7200
|
|
30
|
+
_Group = List[Tuple[str, "remote_ops.Reusable"]]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _private_dir(path: str) -> None:
|
|
34
|
+
try:
|
|
35
|
+
os.mkdir(path, 0o700)
|
|
36
|
+
except FileExistsError:
|
|
37
|
+
pass
|
|
38
|
+
info = os.lstat(path)
|
|
39
|
+
if not stat.S_ISDIR(info.st_mode) or info.st_uid != os.getuid() or info.st_mode & 0o077:
|
|
40
|
+
raise RuntimeError("Strata preparation workspace must be a private owned directory")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@contextlib.contextmanager
|
|
44
|
+
def _locked(directory: str) -> Iterator[int]:
|
|
45
|
+
import fcntl
|
|
46
|
+
|
|
47
|
+
_private_dir(directory)
|
|
48
|
+
fd = os.open(
|
|
49
|
+
os.path.join(directory, "lock"),
|
|
50
|
+
os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0),
|
|
51
|
+
0o600,
|
|
52
|
+
)
|
|
53
|
+
try:
|
|
54
|
+
info = os.fstat(fd)
|
|
55
|
+
if (
|
|
56
|
+
not stat.S_ISREG(info.st_mode)
|
|
57
|
+
or info.st_uid != os.getuid()
|
|
58
|
+
or info.st_mode & 0o077
|
|
59
|
+
or info.st_nlink != 1
|
|
60
|
+
):
|
|
61
|
+
raise RuntimeError("Strata preparation lock must be a private owned file")
|
|
62
|
+
try:
|
|
63
|
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
64
|
+
except BlockingIOError as exc:
|
|
65
|
+
raise RuntimeError("another Strata preparation is using this model directory") from exc
|
|
66
|
+
yield fd
|
|
67
|
+
finally:
|
|
68
|
+
os.close(fd)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@contextlib.contextmanager
|
|
72
|
+
def purge_workspace(model_dir: str | None, *, remove_empty: bool = False) -> Iterator[list[str]]:
|
|
73
|
+
"""List owned preparation files and hold their writer lock through approved removal."""
|
|
74
|
+
private = (
|
|
75
|
+
os.path.join(os.path.realpath(remote_ops._expand(model_dir)), ".prepare")
|
|
76
|
+
if model_dir
|
|
77
|
+
else ""
|
|
78
|
+
)
|
|
79
|
+
if not private or not os.path.lexists(private):
|
|
80
|
+
yield []
|
|
81
|
+
return
|
|
82
|
+
with _locked(private):
|
|
83
|
+
roots = [
|
|
84
|
+
os.path.join(private, name)
|
|
85
|
+
for name in os.listdir(private)
|
|
86
|
+
if re.fullmatch(r"work-[0-9a-f]{20}", name)
|
|
87
|
+
]
|
|
88
|
+
files = []
|
|
89
|
+
directories = []
|
|
90
|
+
for work in roots:
|
|
91
|
+
_private_dir(work)
|
|
92
|
+
for root, dirs, names in os.walk(work):
|
|
93
|
+
directories.append(root)
|
|
94
|
+
files += [os.path.join(root, name) for name in names]
|
|
95
|
+
files += [
|
|
96
|
+
os.path.join(root, name)
|
|
97
|
+
for name in dirs
|
|
98
|
+
if os.path.islink(os.path.join(root, name))
|
|
99
|
+
]
|
|
100
|
+
yield files
|
|
101
|
+
if not remove_empty:
|
|
102
|
+
return
|
|
103
|
+
for directory in sorted(directories, reverse=True):
|
|
104
|
+
if not os.listdir(directory):
|
|
105
|
+
os.rmdir(directory)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _relative(root: str, path: str) -> str:
|
|
109
|
+
expanded = remote_ops._expand(path)
|
|
110
|
+
canonical = os.path.join(
|
|
111
|
+
os.path.realpath(os.path.dirname(expanded)), os.path.basename(expanded)
|
|
112
|
+
)
|
|
113
|
+
if os.path.commonpath((root, canonical)) != root or canonical == root:
|
|
114
|
+
raise RuntimeError("Strata preparation files must stay inside its model directory")
|
|
115
|
+
return os.path.relpath(canonical, root)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _groups(
|
|
119
|
+
spec: remote_ops.StrataPreparation, files: list[remote_ops.Reusable], root: str
|
|
120
|
+
) -> dict[str, _Group]:
|
|
121
|
+
pack = spec["pack"]
|
|
122
|
+
if not pack.startswith("packs/") or any(p in ("", ".", "..") for p in pack.split("/")):
|
|
123
|
+
raise RuntimeError("Strata preparation pack must be a relative packs directory")
|
|
124
|
+
groups: dict[str, _Group] = {pack: [], "mtp/rt": []}
|
|
125
|
+
seen = set()
|
|
126
|
+
for file in files:
|
|
127
|
+
if not file.get("generated"):
|
|
128
|
+
continue
|
|
129
|
+
if file["url"] or file.get("mirrors"):
|
|
130
|
+
raise RuntimeError("generated Strata outputs cannot have download URLs")
|
|
131
|
+
relative = _relative(root, file["dest"])
|
|
132
|
+
group = next((g for g in groups if relative.startswith(g + "/")), "")
|
|
133
|
+
if not group or relative in seen:
|
|
134
|
+
raise RuntimeError("Strata preparation has an undeclared or duplicate output path")
|
|
135
|
+
seen.add(relative)
|
|
136
|
+
groups[group].append((relative, file))
|
|
137
|
+
if not seen:
|
|
138
|
+
raise RuntimeError("Strata preparation has no declared generated outputs")
|
|
139
|
+
return groups
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _valid(path: str, file: remote_ops.Download) -> bool:
|
|
143
|
+
return (
|
|
144
|
+
os.path.isfile(path)
|
|
145
|
+
and not os.path.islink(path)
|
|
146
|
+
and os.path.getsize(path) == file["size_bytes"]
|
|
147
|
+
and remote_ops._sha256(path, os.path.basename(path)) == file["sha256"]
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _discard_receipt(path: str) -> None:
|
|
152
|
+
try:
|
|
153
|
+
os.unlink(path + ".sha256")
|
|
154
|
+
except FileNotFoundError:
|
|
155
|
+
pass
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _receipt(path: str, digest: str) -> None:
|
|
159
|
+
marker = path + ".sha256"
|
|
160
|
+
try:
|
|
161
|
+
if remote_ops._read(marker).strip() == digest:
|
|
162
|
+
return
|
|
163
|
+
except (OSError, UnicodeError):
|
|
164
|
+
pass
|
|
165
|
+
fd, temporary = tempfile.mkstemp(prefix=".strata-receipt-", dir=os.path.dirname(path))
|
|
166
|
+
try:
|
|
167
|
+
with os.fdopen(fd, "w", encoding="utf-8") as stream:
|
|
168
|
+
stream.write(digest)
|
|
169
|
+
os.replace(temporary, marker)
|
|
170
|
+
finally:
|
|
171
|
+
if os.path.exists(temporary):
|
|
172
|
+
os.unlink(temporary)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _require_file(path: str, file: remote_ops.Download) -> None:
|
|
176
|
+
label = os.path.basename(path)
|
|
177
|
+
if not os.path.isfile(path) or os.path.getsize(path) != file["size_bytes"]:
|
|
178
|
+
raise RuntimeError(f"Strata preparation {label} size mismatch")
|
|
179
|
+
if os.path.islink(path) or remote_ops._sha256(path, label) != file["sha256"]:
|
|
180
|
+
raise RuntimeError(f"Strata preparation {label} SHA256 mismatch")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _inputs(
|
|
184
|
+
spec: remote_ops.StrataPreparation, files: list[remote_ops.Reusable], root: str
|
|
185
|
+
) -> None:
|
|
186
|
+
sources = {remote_ops._expand(f["dest"]): f for f in files if not f.get("generated")}
|
|
187
|
+
first = remote_ops._expand(spec["gguf"])
|
|
188
|
+
if first not in sources:
|
|
189
|
+
raise RuntimeError("Strata preparation GGUF must be a declared input")
|
|
190
|
+
_relative(root, first)
|
|
191
|
+
split = re.fullmatch(r"(.+)-00001-of-(\d{5})\.gguf", os.path.basename(first))
|
|
192
|
+
if split:
|
|
193
|
+
stem, count = split[1], split[2]
|
|
194
|
+
for number in range(1, int(split[2]) + 1):
|
|
195
|
+
name = f"{stem}-{number:05d}-of-{count}.gguf"
|
|
196
|
+
if os.path.join(os.path.dirname(first), name) not in sources:
|
|
197
|
+
raise RuntimeError("Strata preparation needs every pinned GGUF shard")
|
|
198
|
+
for path, file in sources.items():
|
|
199
|
+
_relative(root, path)
|
|
200
|
+
try:
|
|
201
|
+
_require_file(path, file)
|
|
202
|
+
except RuntimeError:
|
|
203
|
+
_discard_receipt(path)
|
|
204
|
+
raise
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _gguf_source(spec: remote_ops.StrataPreparation, work: str) -> str:
|
|
208
|
+
asset = spec["gguf_py"]
|
|
209
|
+
if (
|
|
210
|
+
not asset["name"]
|
|
211
|
+
or asset["name"] in (".", "..")
|
|
212
|
+
or os.path.basename(asset["name"]) != asset["name"]
|
|
213
|
+
):
|
|
214
|
+
raise RuntimeError("Strata preparation source archive needs a file name")
|
|
215
|
+
archive = os.path.join(work, asset["name"])
|
|
216
|
+
remote_ops.fetch(asset["url"], archive, asset["sha256"], asset["size_bytes"], asset["name"])
|
|
217
|
+
source_file: remote_ops.Download = {
|
|
218
|
+
"dest": archive,
|
|
219
|
+
"url": asset["url"],
|
|
220
|
+
"size_bytes": asset["size_bytes"],
|
|
221
|
+
"sha256": asset["sha256"],
|
|
222
|
+
}
|
|
223
|
+
_require_file(archive, source_file)
|
|
224
|
+
source = os.path.join(work, "llama.cpp")
|
|
225
|
+
if os.path.exists(source):
|
|
226
|
+
shutil.rmtree(source)
|
|
227
|
+
os.mkdir(source, 0o700)
|
|
228
|
+
remote_ops.unpack(archive, source)
|
|
229
|
+
gguf_py = os.path.join(source, "gguf-py")
|
|
230
|
+
if not os.path.isdir(os.path.join(gguf_py, "gguf")):
|
|
231
|
+
raise RuntimeError("the pinned Strata preparation source has no gguf-py")
|
|
232
|
+
return gguf_py
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _environment(spec: remote_ops.StrataPreparation, gguf_py: str) -> dict[str, str]:
|
|
236
|
+
env = {
|
|
237
|
+
key: value for key, value in os.environ.items() if not key.startswith(("PYTHON", "STRATA_"))
|
|
238
|
+
}
|
|
239
|
+
env.update(
|
|
240
|
+
STRATA_GGUF_PY=gguf_py,
|
|
241
|
+
STRATA_SOURCE="huggingface",
|
|
242
|
+
STRATA_MTP_REVISION=spec["mtp_revision"],
|
|
243
|
+
STRATA_ALLOW_UNPINNED="0",
|
|
244
|
+
STRATA_EXIT_WITH_PARENT="1",
|
|
245
|
+
HF_ENDPOINT=spec["hf_endpoint"],
|
|
246
|
+
)
|
|
247
|
+
return env
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _run(
|
|
251
|
+
spec: remote_ops.StrataPreparation,
|
|
252
|
+
tool: str,
|
|
253
|
+
args: list[str],
|
|
254
|
+
work: str,
|
|
255
|
+
env: dict[str, str],
|
|
256
|
+
lock_fd: int,
|
|
257
|
+
) -> None:
|
|
258
|
+
engine = remote_ops._expand(spec["engine_dir"])
|
|
259
|
+
python = os.path.join(engine, "python", "bin", "python3")
|
|
260
|
+
script = os.path.join(engine, "tools", tool)
|
|
261
|
+
if not os.access(python, os.X_OK) or not os.path.isfile(script):
|
|
262
|
+
raise RuntimeError(f"the pinned Strata control package has no preparation tool {tool}")
|
|
263
|
+
remote_ops.emit("log", phase="prepare", message="preparing Strata artifacts: " + tool)
|
|
264
|
+
with open(os.path.join(work, tool + ".log"), "w", encoding="utf-8") as log:
|
|
265
|
+
try:
|
|
266
|
+
result = subprocess.run(
|
|
267
|
+
[python, "-I", script, *args],
|
|
268
|
+
cwd=work,
|
|
269
|
+
env=env,
|
|
270
|
+
stdout=log,
|
|
271
|
+
stderr=subprocess.STDOUT,
|
|
272
|
+
pass_fds=(lock_fd,),
|
|
273
|
+
timeout=TOOL_TIMEOUT_S,
|
|
274
|
+
check=False,
|
|
275
|
+
)
|
|
276
|
+
except subprocess.TimeoutExpired as exc:
|
|
277
|
+
raise RuntimeError(
|
|
278
|
+
f"Strata preparation {tool} timed out; retry the approved plan"
|
|
279
|
+
) from exc
|
|
280
|
+
if result.returncode:
|
|
281
|
+
raise RuntimeError(
|
|
282
|
+
f"Strata preparation {tool} failed (exit {result.returncode}); retry the approved plan"
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _generate(
|
|
287
|
+
spec: remote_ops.StrataPreparation,
|
|
288
|
+
group: str,
|
|
289
|
+
outputs: _Group,
|
|
290
|
+
stage: str,
|
|
291
|
+
work: str,
|
|
292
|
+
env: dict[str, str],
|
|
293
|
+
lock_fd: int,
|
|
294
|
+
) -> None:
|
|
295
|
+
output = os.path.join(stage, group)
|
|
296
|
+
if group == spec["pack"]:
|
|
297
|
+
args = ["--gguf", remote_ops._expand(spec["gguf"]), "--out", output]
|
|
298
|
+
_run(spec, "strata_tokenizer.py", args, work, env, lock_fd)
|
|
299
|
+
# iq_pack otherwise starts a child without passing our lock. Extract first so every
|
|
300
|
+
# writer is a directly supervised tool that retains the lock if this action is killed.
|
|
301
|
+
tokenizers = [(relative, file) for relative, file in outputs if "/tokenizer/" in relative]
|
|
302
|
+
for relative, file in tokenizers:
|
|
303
|
+
_require_file(os.path.join(stage, relative), file)
|
|
304
|
+
if not all(
|
|
305
|
+
os.path.isfile(os.path.join(output, "tokenizer", name))
|
|
306
|
+
for name in ("vocab.json", "chat_template.jinja")
|
|
307
|
+
):
|
|
308
|
+
raise RuntimeError("Strata preparation needs the pinned vocabulary and chat template")
|
|
309
|
+
if spec["experts_bin"]:
|
|
310
|
+
args.append("--experts-bin")
|
|
311
|
+
_run(spec, "iq_pack.py", args, work, env, lock_fd)
|
|
312
|
+
return
|
|
313
|
+
mtp = os.path.join(work, "mtp")
|
|
314
|
+
intermediate = os.path.join(mtp, "mtp-q2_0.gguf")
|
|
315
|
+
_run(spec, "mtp_fetch.py", ["fetch", "--out", mtp], work, env, lock_fd)
|
|
316
|
+
_run(spec, "mtp_fetch.py", ["verify", "--out", mtp], work, env, lock_fd)
|
|
317
|
+
_run(
|
|
318
|
+
spec,
|
|
319
|
+
"mtp_pack.py",
|
|
320
|
+
["--src", mtp, "--experts", "q2_0", "--out", intermediate],
|
|
321
|
+
work,
|
|
322
|
+
env,
|
|
323
|
+
lock_fd,
|
|
324
|
+
)
|
|
325
|
+
_run(
|
|
326
|
+
spec,
|
|
327
|
+
"mtp_rt.py",
|
|
328
|
+
["--gguf", intermediate, "--out", output],
|
|
329
|
+
work,
|
|
330
|
+
env,
|
|
331
|
+
lock_fd,
|
|
332
|
+
)
|
|
333
|
+
shutil.copyfile(
|
|
334
|
+
os.path.join(remote_ops._expand(spec["engine_dir"]), "data", "draft_vocab.bin"),
|
|
335
|
+
os.path.join(output, "draft_vocab.bin"),
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def prepare(spec: remote_ops.StrataPreparation, files: list[remote_ops.Reusable]) -> None:
|
|
340
|
+
"""Generate missing groups, check their exact pins, and atomically publish their files."""
|
|
341
|
+
if spec["kind"] != KIND or spec["mtp_revision"] != MTP_REVISION:
|
|
342
|
+
raise RuntimeError("unsupported Strata preparation kind or MTP revision")
|
|
343
|
+
if os.name != "posix" or spec["scratch_bytes"] < 0:
|
|
344
|
+
raise RuntimeError("Strata preparation requires POSIX and a bounded workspace")
|
|
345
|
+
root = os.path.realpath(remote_ops._expand(spec["model_dir"]))
|
|
346
|
+
groups = _groups(spec, files, root)
|
|
347
|
+
os.makedirs(root, exist_ok=True)
|
|
348
|
+
private = os.path.join(root, ".prepare")
|
|
349
|
+
with _locked(private) as lock_fd:
|
|
350
|
+
_inputs(spec, files, root)
|
|
351
|
+
needed: dict[str, _Group] = {}
|
|
352
|
+
valid = set()
|
|
353
|
+
for group, outputs in groups.items():
|
|
354
|
+
for relative, file in outputs:
|
|
355
|
+
path = os.path.join(root, relative)
|
|
356
|
+
if _valid(path, file):
|
|
357
|
+
valid.add(relative)
|
|
358
|
+
_receipt(path, file["sha256"])
|
|
359
|
+
else:
|
|
360
|
+
_discard_receipt(path)
|
|
361
|
+
if any(relative not in valid for relative, _ in outputs):
|
|
362
|
+
needed[group] = outputs
|
|
363
|
+
if not needed:
|
|
364
|
+
return
|
|
365
|
+
required = spec["scratch_bytes"] + sum(
|
|
366
|
+
file["size_bytes"] for outputs in needed.values() for _, file in outputs
|
|
367
|
+
)
|
|
368
|
+
key = hashlib.sha256(
|
|
369
|
+
json.dumps(
|
|
370
|
+
{
|
|
371
|
+
"spec": spec,
|
|
372
|
+
"pins": [(f["dest"], f["size_bytes"], f["sha256"]) for f in files],
|
|
373
|
+
},
|
|
374
|
+
sort_keys=True,
|
|
375
|
+
).encode()
|
|
376
|
+
).hexdigest()[:20]
|
|
377
|
+
work = os.path.join(private, "work-" + key)
|
|
378
|
+
_private_dir(work)
|
|
379
|
+
# The writer lock excludes surviving conversion children. This workspace contains
|
|
380
|
+
# only replaceable scratch for this exact recipe, not published model files.
|
|
381
|
+
shutil.rmtree(work)
|
|
382
|
+
_private_dir(work)
|
|
383
|
+
free = shutil.disk_usage(root).free
|
|
384
|
+
if required > free:
|
|
385
|
+
raise RuntimeError(
|
|
386
|
+
f"low disk space: Strata preparation needs {required} bytes, {free} free"
|
|
387
|
+
)
|
|
388
|
+
stage = os.path.join(work, "model")
|
|
389
|
+
os.makedirs(stage, mode=0o700, exist_ok=True)
|
|
390
|
+
env = _environment(spec, _gguf_source(spec, work))
|
|
391
|
+
for group, outputs in needed.items():
|
|
392
|
+
_generate(spec, group, outputs, stage, work, env, lock_fd)
|
|
393
|
+
try:
|
|
394
|
+
for relative, file in outputs:
|
|
395
|
+
_require_file(os.path.join(stage, relative), file)
|
|
396
|
+
except RuntimeError:
|
|
397
|
+
shutil.rmtree(os.path.join(stage, group), ignore_errors=True)
|
|
398
|
+
raise
|
|
399
|
+
for relative, file in outputs:
|
|
400
|
+
if relative in valid:
|
|
401
|
+
continue
|
|
402
|
+
destination = os.path.join(root, relative)
|
|
403
|
+
os.makedirs(os.path.dirname(destination), mode=0o700, exist_ok=True)
|
|
404
|
+
os.replace(os.path.join(stage, relative), destination)
|
|
405
|
+
_receipt(destination, file["sha256"])
|
|
406
|
+
shutil.rmtree(work)
|
|
@@ -10,28 +10,61 @@ private-name imports.
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
12
|
import os
|
|
13
|
+
import sys
|
|
14
|
+
import time
|
|
15
|
+
from typing import Callable
|
|
13
16
|
|
|
14
17
|
try:
|
|
15
|
-
from localmodels import remote_ops, remote_ops_launchd, remote_ops_service
|
|
18
|
+
from localmodels import remote_ops, remote_ops_launchd, remote_ops_prepare, remote_ops_service
|
|
16
19
|
except ImportError: # run as a bare file from this directory
|
|
17
20
|
import remote_ops # type: ignore[import-not-found,no-redef]
|
|
18
21
|
import remote_ops_launchd # type: ignore[import-not-found,no-redef]
|
|
22
|
+
import remote_ops_prepare # type: ignore[import-not-found,no-redef]
|
|
19
23
|
import remote_ops_service # type: ignore[import-not-found,no-redef]
|
|
20
24
|
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
RELEASE_WAIT_S = 30.0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _purgeable(p: remote_ops.RemoveParams, preparation: list[str]) -> list[list[object]]:
|
|
23
30
|
"""[path, bytes, links] for every file in the deployment directory and the model files named."""
|
|
24
|
-
found = [remote_ops._expand(f) for f in p.get("purge_files") or []]
|
|
31
|
+
found = [remote_ops._expand(f) for f in p.get("purge_files") or []] + preparation
|
|
25
32
|
for root, _, names in os.walk(remote_ops._expand(p["deploy_dir"])):
|
|
26
33
|
found += [os.path.join(root, n) for n in names]
|
|
27
34
|
stats = [(f, os.lstat(f)) for f in sorted(set(found)) if os.path.lexists(f)]
|
|
28
35
|
return [[f, st.st_size, st.st_nlink] for f, st in stats if not os.path.isdir(f)]
|
|
29
36
|
|
|
30
37
|
|
|
38
|
+
def _delete(path: str, remove: Callable[[str], None] = os.remove) -> None:
|
|
39
|
+
"""Delete one of a stopped service's files or emptied directories. Windows refuses while
|
|
40
|
+
another process still has it open, and a server that was just ended keeps its log and its
|
|
41
|
+
working directory open until its memory is torn down: seconds for a 10 GB llama-server
|
|
42
|
+
(home-win, 2026-11-12: WinError 32 on server.log right after the stop). So a refusal is
|
|
43
|
+
retried there for RELEASE_WAIT_S; elsewhere, and after that, it is raised."""
|
|
44
|
+
deadline = time.monotonic() + RELEASE_WAIT_S
|
|
45
|
+
while True:
|
|
46
|
+
try:
|
|
47
|
+
remove(path)
|
|
48
|
+
return
|
|
49
|
+
except PermissionError:
|
|
50
|
+
if sys.platform != "win32" or time.monotonic() >= deadline:
|
|
51
|
+
raise
|
|
52
|
+
time.sleep(0.25)
|
|
53
|
+
|
|
54
|
+
|
|
31
55
|
def act_remove(p: remote_ops.RemoveParams) -> None:
|
|
32
56
|
"""Stop and delete the service and config files, and the slice once no unit uses it; logs,
|
|
33
57
|
weights and engines stay. ``dry_run`` lists a purge; ``purge`` deletes approved files."""
|
|
34
|
-
|
|
58
|
+
purging = p.get("dry_run") or p.get("purge")
|
|
59
|
+
model_dir = p.get("preparation_dir") if purging and p.get("purge_files") else None
|
|
60
|
+
with remote_ops_prepare.purge_workspace(
|
|
61
|
+
model_dir, remove_empty=bool(p.get("purge"))
|
|
62
|
+
) as preparation:
|
|
63
|
+
_remove(p, preparation)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _remove(p: remote_ops.RemoveParams, preparation: list[str]) -> None:
|
|
67
|
+
listed = _purgeable(p, preparation) if p.get("dry_run") or p.get("purge") else []
|
|
35
68
|
if p.get("dry_run"):
|
|
36
69
|
remote_ops.emit("result", files=listed, bytes=sum(int(str(f[1])) for f in listed))
|
|
37
70
|
return
|
|
@@ -71,13 +104,13 @@ def act_remove(p: remote_ops.RemoveParams) -> None:
|
|
|
71
104
|
*p.get("config_files", []),
|
|
72
105
|
]:
|
|
73
106
|
if os.path.exists(remote_ops._expand(path)):
|
|
74
|
-
|
|
107
|
+
_delete(remote_ops._expand(path))
|
|
75
108
|
approved = set(p.get("purge") or []) & {str(f[0]) for f in listed}
|
|
76
109
|
for path in approved:
|
|
77
110
|
if os.path.lexists(path): # the service files above may be listed too
|
|
78
|
-
|
|
111
|
+
_delete(path)
|
|
79
112
|
for root, _, _ in sorted(os.walk(paths["root"]), reverse=True) if approved else []:
|
|
80
113
|
if not os.listdir(root):
|
|
81
|
-
os.rmdir
|
|
114
|
+
_delete(root, os.rmdir)
|
|
82
115
|
kept = [paths["log"]] if os.path.exists(paths["log"]) else []
|
|
83
116
|
remote_ops.emit("result", removed=True, purged=len(approved), kept=kept)
|