@simplexai/localmodels-linux-arm64 0.1.0-dev.58 → 0.1.0-dev.60
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 +105 -98
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +104 -43
- package/modules/localmodels/app.py +1 -1
- package/modules/localmodels/apple_sensors.py +431 -0
- package/modules/localmodels/bifrost_admin.py +83 -8
- package/modules/localmodels/bifrost_checks.py +2 -2
- package/modules/localmodels/bifrost_config.py +235 -13
- package/modules/localmodels/bifrost_log.py +166 -0
- package/modules/localmodels/bifrost_models.py +1 -1
- package/modules/localmodels/budget.py +1 -1
- package/modules/localmodels/catalog.json +192 -77
- package/modules/localmodels/catalog.py +20 -3
- package/modules/localmodels/catalog_add.py +42 -11
- package/modules/localmodels/custom_hub.py +983 -0
- package/modules/localmodels/custom_hub_http.py +579 -0
- package/modules/localmodels/custom_probe.py +451 -0
- package/modules/localmodels/deploy.py +27 -5
- package/modules/localmodels/deploy_steps.py +5 -0
- package/modules/localmodels/download-mirrors.json +8 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
- package/modules/localmodels/engines.py +38 -8
- package/modules/localmodels/estimator.py +60 -7
- package/modules/localmodels/frontend.py +26 -21
- package/modules/localmodels/gateway.py +48 -3
- package/modules/localmodels/gateway_app_bifrost.py +4 -4
- package/modules/localmodels/gateway_bifrost.py +128 -21
- package/modules/localmodels/gguf.py +6 -0
- package/modules/localmodels/host_sensors.py +704 -0
- package/modules/localmodels/hosts.py +99 -12
- package/modules/localmodels/library_cli.py +181 -3
- package/modules/localmodels/library_convert.py +34 -0
- package/modules/localmodels/library_custom.py +831 -0
- package/modules/localmodels/library_elastic.py +182 -127
- package/modules/localmodels/library_gateway.py +193 -40
- package/modules/localmodels/library_jobs.py +92 -18
- package/modules/localmodels/library_kept.py +50 -6
- package/modules/localmodels/library_model.py +254 -2
- package/modules/localmodels/library_pricing.py +97 -8
- package/modules/localmodels/library_serve.py +196 -66
- package/modules/localmodels/library_smoke.py +315 -0
- package/modules/localmodels/library_state.py +81 -2
- package/modules/localmodels/library_status.py +144 -8
- package/modules/localmodels/metal.py +1 -1
- package/modules/localmodels/metal_probe.py +4 -4
- package/modules/localmodels/nvml_ctypes.py +431 -0
- package/modules/localmodels/plan_envelope.py +18 -7
- package/modules/localmodels/process_identity_linux.py +39 -0
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +57 -8
- package/modules/localmodels/remote_ops_download.py +205 -53
- package/modules/localmodels/remote_ops_mirrors.py +43 -2
- package/modules/localmodels/remote_ops_ranges.py +2 -5
- package/modules/localmodels/remote_ops_service.py +95 -37
- package/modules/localmodels/remote_ops_verify.py +22 -5
- package/modules/localmodels/runtime-lock.json +19 -19
- package/modules/localmodels/runtime_auth.py +4 -1
- package/modules/localmodels/service_control.py +32 -1
- package/modules/localmodels/service_wiring.py +237 -12
- package/modules/localmodels/service_worker.py +6 -2
- package/modules/localmodels/services_cli.py +35 -27
- package/modules/localmodels/setup_inspection.py +47 -70
- package/modules/localmodels/setup_inspection_harness.py +159 -15
- package/modules/localmodels/setup_text.py +14 -0
- package/modules/localmodels/setup_upgrade.py +1 -1
- package/modules/localmodels/source_byok.py +9 -7
- package/modules/localmodels/source_byok_probe.py +6 -1
- package/modules/localmodels/stack.py +9 -1
- package/modules/localmodels/stack_binding.py +3 -35
- package/modules/localmodels/stack_cleanup.py +4 -0
- package/modules/localmodels/stack_compose.py +18 -2
- package/modules/localmodels/stack_lifecycle.py +26 -3
- package/modules/localmodels/stack_memory.py +1 -0
- package/modules/localmodels/stack_plan.py +6 -2
- package/modules/localmodels/stack_ports.py +2 -0
- package/modules/localmodels/stack_remove.py +10 -1
- package/modules/localmodels/stack_up.py +33 -7
- package/modules/localmodels/stack_update.py +3 -1
- package/modules/localmodels/stack_view.py +77 -53
- package/modules/localmodels/stack_view_demo.py +36 -5
- package/modules/localmodels/stack_view_events.py +147 -12
- package/modules/localmodels/stack_view_gpu.py +97 -17
- package/modules/localmodels/stack_view_llm.py +15 -0
- package/modules/localmodels/stack_view_measure.py +4 -1
- package/modules/localmodels/stack_view_schema.py +54 -8
- package/modules/localmodels/stack_view_serve.py +40 -3
- package/modules/localmodels/stack_view_slots.py +89 -10
- package/modules/localmodels/stack_view_telemetry.py +163 -0
- package/modules/localmodels/stack_view_text.py +5 -2
- package/modules/localmodels/stack_view_tick.py +658 -0
- package/modules/localmodels/stack_view_words.py +4 -0
- package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
- package/modules/localmodels/suite.py +45 -27
- package/modules/localmodels/telemetry_math.py +538 -0
- package/modules/localmodels/transport.py +13 -2
- package/modules/localmodels/web/view/view.js +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +102 -95
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/bifrost_datasheet.py +0 -53
- package/modules/localmodels/bifrost_provider.py +0 -88
- package/modules/localmodels/bifrost_unit.py +0 -99
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
- package/modules/localmodels/gateway_switch.py +0 -51
- package/modules/localmodels/library_floor.py +0 -78
- package/modules/localmodels/service_stop.py +0 -52
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"""Isolated conservative smoke-test for custom (or downloaded) library models.
|
|
2
|
+
|
|
3
|
+
Runs an ephemeral loopback ``llama-server`` at ``--ctx <4096|2048>`` and ``slots=1``, verifies a
|
|
4
|
+
minimal completion (``"Reply with OK."``, ``max_tokens: 16``), auto-retries once without
|
|
5
|
+
``--jinja`` on chat-template errors, and ALWAYS shuts down and deletes the ephemeral deployment
|
|
6
|
+
before returning. Never touches active curated models, Bifrost, Pi ``models.json``, or
|
|
7
|
+
``model-source.json``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import contextlib
|
|
13
|
+
import copy
|
|
14
|
+
import os
|
|
15
|
+
import shutil
|
|
16
|
+
import socket
|
|
17
|
+
import uuid
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from localmodels import (
|
|
21
|
+
app,
|
|
22
|
+
custom_hub,
|
|
23
|
+
hosts,
|
|
24
|
+
library_jobs,
|
|
25
|
+
library_pricing,
|
|
26
|
+
library_serve,
|
|
27
|
+
library_state,
|
|
28
|
+
library_status,
|
|
29
|
+
plan_envelope,
|
|
30
|
+
remote_ops,
|
|
31
|
+
stack_lifecycle,
|
|
32
|
+
)
|
|
33
|
+
from localmodels.library_model import LibraryError, Row, progress
|
|
34
|
+
from localmodels.library_state import Record, VerificationFailureRecord, VerificationRecord
|
|
35
|
+
from localmodels.probe import HostFacts
|
|
36
|
+
from localmodels.records import FinishedRecord, Plan
|
|
37
|
+
|
|
38
|
+
DIAGNOSTIC_LOG_LIMIT = 4000
|
|
39
|
+
_TEMPLATE_ERROR_PATTERNS = (
|
|
40
|
+
"chat template",
|
|
41
|
+
"chat_template",
|
|
42
|
+
"minja",
|
|
43
|
+
"jinja",
|
|
44
|
+
"template error",
|
|
45
|
+
"failed to parse template",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _free_ephemeral_port(taken: set[int]) -> int:
|
|
50
|
+
for _ in range(16):
|
|
51
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
52
|
+
sock.bind(("127.0.0.1", 0))
|
|
53
|
+
port = int(sock.getsockname()[1])
|
|
54
|
+
if port not in taken:
|
|
55
|
+
return port
|
|
56
|
+
raise LibraryError("ENGINE_START_FAILED", "could not allocate an ephemeral loopback port")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _replace_flag(argv: list[str], names: tuple[str, ...], flag: str, value: str) -> list[str]:
|
|
60
|
+
out: list[str] = []
|
|
61
|
+
i = 0
|
|
62
|
+
replaced = False
|
|
63
|
+
while i < len(argv):
|
|
64
|
+
if argv[i] in names:
|
|
65
|
+
if not replaced:
|
|
66
|
+
out.extend([flag, value])
|
|
67
|
+
replaced = True
|
|
68
|
+
i += 2
|
|
69
|
+
continue
|
|
70
|
+
out.append(argv[i])
|
|
71
|
+
i += 1
|
|
72
|
+
if not replaced:
|
|
73
|
+
out.extend([flag, value])
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _strip_flags(argv: list[str], names: set[str], valued: set[str]) -> list[str]:
|
|
78
|
+
out: list[str] = []
|
|
79
|
+
i = 0
|
|
80
|
+
while i < len(argv):
|
|
81
|
+
tok = argv[i]
|
|
82
|
+
if tok in names:
|
|
83
|
+
i += 1
|
|
84
|
+
continue
|
|
85
|
+
if tok in valued:
|
|
86
|
+
i += 2
|
|
87
|
+
continue
|
|
88
|
+
out.append(tok)
|
|
89
|
+
i += 1
|
|
90
|
+
return out
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _build_smoke_plan(
|
|
94
|
+
record: Record,
|
|
95
|
+
facts: HostFacts,
|
|
96
|
+
base_dir: str,
|
|
97
|
+
port: int,
|
|
98
|
+
ctx: int,
|
|
99
|
+
*,
|
|
100
|
+
use_jinja: bool,
|
|
101
|
+
) -> Plan:
|
|
102
|
+
"""Build an ephemeral loopback smoke-test plan derived from ``record['plan']``."""
|
|
103
|
+
plan = copy.deepcopy(record["plan"])
|
|
104
|
+
token_id = uuid.uuid4().hex[:10]
|
|
105
|
+
smoke_name = f"smoke-{token_id}"
|
|
106
|
+
base = base_dir.rstrip("/")
|
|
107
|
+
deploy_dir = f"{base}/deployments/{smoke_name}"
|
|
108
|
+
api_key_file = f"{deploy_dir}/api-key"
|
|
109
|
+
|
|
110
|
+
argv = list(plan["service"]["argv"])
|
|
111
|
+
argv = _strip_flags(
|
|
112
|
+
argv,
|
|
113
|
+
names={"--jinja", "--no-warmup", "--mmproj-offload"},
|
|
114
|
+
valued={"--mmproj", "--chat-template-file", "--reasoning-budget"},
|
|
115
|
+
)
|
|
116
|
+
argv = _replace_flag(argv, ("-c", "--ctx-size"), "-c", str(ctx))
|
|
117
|
+
argv = _replace_flag(argv, ("-np", "--parallel"), "-np", "1")
|
|
118
|
+
argv = _replace_flag(argv, ("--host",), "--host", "127.0.0.1")
|
|
119
|
+
argv = _replace_flag(argv, ("--port",), "--port", str(port))
|
|
120
|
+
argv = _replace_flag(argv, ("--api-key-file",), "--api-key-file", api_key_file)
|
|
121
|
+
argv = _replace_flag(argv, ("--cache-ram",), "--cache-ram", "256")
|
|
122
|
+
if use_jinja:
|
|
123
|
+
argv.append("--jinja")
|
|
124
|
+
for flag in ("--metrics", "--slots", "--no-ui"):
|
|
125
|
+
if flag not in argv:
|
|
126
|
+
argv.append(flag)
|
|
127
|
+
|
|
128
|
+
service_kind = facts["service_manager"]["kind"]
|
|
129
|
+
plan["name"] = smoke_name
|
|
130
|
+
plan["service"] = {
|
|
131
|
+
"name": plan_envelope.service_name(base, smoke_name),
|
|
132
|
+
"kind": service_kind,
|
|
133
|
+
"deploy_dir": deploy_dir,
|
|
134
|
+
"port": port,
|
|
135
|
+
"bind": "127.0.0.1",
|
|
136
|
+
"argv": argv,
|
|
137
|
+
"env": dict(plan["service"].get("env") or {}),
|
|
138
|
+
"autostart": False,
|
|
139
|
+
}
|
|
140
|
+
plan["endpoint"] = {
|
|
141
|
+
**plan["endpoint"],
|
|
142
|
+
"base_url": f"http://127.0.0.1:{port}/v1",
|
|
143
|
+
}
|
|
144
|
+
plan["launch"] = {
|
|
145
|
+
**plan["launch"],
|
|
146
|
+
"window": ctx,
|
|
147
|
+
"slots": 1,
|
|
148
|
+
"smoke": True,
|
|
149
|
+
"vision": False,
|
|
150
|
+
}
|
|
151
|
+
return plan
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _read_server_log(deploy_dir: str) -> str:
|
|
155
|
+
log_path = Path(os.path.expanduser(deploy_dir)) / "server.log"
|
|
156
|
+
try:
|
|
157
|
+
raw = log_path.read_bytes()
|
|
158
|
+
except OSError:
|
|
159
|
+
return ""
|
|
160
|
+
return raw[-16384:].decode("utf-8", errors="replace")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _cleanup_smoke_plan(plan: Plan) -> None:
|
|
164
|
+
run = library_jobs.executor()
|
|
165
|
+
with contextlib.suppress(Exception):
|
|
166
|
+
run.run_action("remove", stack_lifecycle.plan_params(plan), timeout=120)
|
|
167
|
+
with contextlib.suppress(Exception):
|
|
168
|
+
hosts.delete_record(
|
|
169
|
+
hosts.LOCAL_ID, plan["name"], purged=True, deploy_dir=plan["service"]["deploy_dir"]
|
|
170
|
+
)
|
|
171
|
+
deploy_dir = Path(os.path.expanduser(plan["service"]["deploy_dir"]))
|
|
172
|
+
if deploy_dir.parent.name == "deployments" and deploy_dir.is_dir():
|
|
173
|
+
shutil.rmtree(deploy_dir, ignore_errors=True)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _is_template_error(text: str) -> bool:
|
|
177
|
+
lower = text.lower()
|
|
178
|
+
return any(pattern in lower for pattern in _TEMPLATE_ERROR_PATTERNS)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _diagnostic_text(finished: FinishedRecord, server_log: str) -> str:
|
|
182
|
+
failed = next((s for s in finished["steps"] if not s["ok"]), None)
|
|
183
|
+
parts = [
|
|
184
|
+
str(finished.get("error") or ""),
|
|
185
|
+
str(failed.get("stderr") or "") if failed is not None else "",
|
|
186
|
+
server_log,
|
|
187
|
+
]
|
|
188
|
+
combined = "\n".join(part.strip() for part in parts if part and part.strip())
|
|
189
|
+
redacted = custom_hub.redact_secrets(remote_ops.redact_text(combined))
|
|
190
|
+
return redacted[-DIAGNOSTIC_LOG_LIMIT:]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _run_attempt(
|
|
194
|
+
model_id: str,
|
|
195
|
+
smoke_plan: Plan,
|
|
196
|
+
) -> tuple[FinishedRecord, str]:
|
|
197
|
+
def on_event(step: str, _event: object) -> None:
|
|
198
|
+
done = 2 if step == "verify" else 1
|
|
199
|
+
progress(model_id, "smoke_test", done, 3)
|
|
200
|
+
|
|
201
|
+
server_log = ""
|
|
202
|
+
try:
|
|
203
|
+
finished = app.run_deploy(hosts.LOCAL_ID, smoke_plan, on_event=on_event)
|
|
204
|
+
if not finished["ok"]:
|
|
205
|
+
server_log = _read_server_log(smoke_plan["service"]["deploy_dir"])
|
|
206
|
+
return finished, server_log
|
|
207
|
+
finally:
|
|
208
|
+
_cleanup_smoke_plan(smoke_plan)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def smoke_test(model_id: str, base_dir: str, *, ctx: int = 4096) -> Row:
|
|
212
|
+
"""Run an isolated ephemeral smoke-test at ``ctx`` tokens and persist ``verification``."""
|
|
213
|
+
if isinstance(ctx, bool) or ctx <= 0:
|
|
214
|
+
raise LibraryError("INVALID_STATE", "--ctx must be a positive integer")
|
|
215
|
+
model = library_pricing.find(model_id, library_pricing.entries())
|
|
216
|
+
with library_state.locked():
|
|
217
|
+
library_state.refuse_busy(model.id, "smoke_test")
|
|
218
|
+
record = library_state.load(model.id)
|
|
219
|
+
if record is None:
|
|
220
|
+
raise LibraryError("INVALID_STATE", f"{model.id} is not downloaded")
|
|
221
|
+
if missing := library_jobs.files_missing(record["plan"]):
|
|
222
|
+
raise LibraryError("MODEL_FILES_MISSING", "missing: " + ", ".join(missing))
|
|
223
|
+
facts = library_jobs.probe()
|
|
224
|
+
taken = {
|
|
225
|
+
r["plan"]["service"]["port"] for r in library_state.records() if r["state"] != "idle"
|
|
226
|
+
}
|
|
227
|
+
taken.update(
|
|
228
|
+
int(j.get("port", 0))
|
|
229
|
+
for j, alive in library_state.jobs().values()
|
|
230
|
+
if alive and j.get("port")
|
|
231
|
+
)
|
|
232
|
+
port = _free_ephemeral_port(taken)
|
|
233
|
+
prior_verification = record.get("verification")
|
|
234
|
+
record["verification"] = {"status": "running", "context_tokens": ctx}
|
|
235
|
+
library_state.save(record)
|
|
236
|
+
job = library_state.acquire("smoke_test", model.id, record["pool"], 0, [], port=port)
|
|
237
|
+
|
|
238
|
+
record_base = record.get("base_dir") or base_dir
|
|
239
|
+
custom_meta = record.get("custom")
|
|
240
|
+
use_jinja = (
|
|
241
|
+
bool(custom_meta.get("has_chat_template", True)) if custom_meta is not None else True
|
|
242
|
+
)
|
|
243
|
+
progress(model.id, "smoke_test", 0, 3)
|
|
244
|
+
with library_state.held([job]):
|
|
245
|
+
try:
|
|
246
|
+
smoke_plan = _build_smoke_plan(
|
|
247
|
+
record, facts, record_base, port, ctx, use_jinja=use_jinja
|
|
248
|
+
)
|
|
249
|
+
finished, server_log = _run_attempt(model.id, smoke_plan)
|
|
250
|
+
jinja_fallback = False
|
|
251
|
+
if not finished["ok"] and use_jinja:
|
|
252
|
+
diag = _diagnostic_text(finished, server_log)
|
|
253
|
+
if _is_template_error(diag):
|
|
254
|
+
jinja_fallback = True
|
|
255
|
+
retry_plan = _build_smoke_plan(
|
|
256
|
+
record, facts, record_base, port, ctx, use_jinja=False
|
|
257
|
+
)
|
|
258
|
+
finished, server_log = _run_attempt(model.id, retry_plan)
|
|
259
|
+
except BaseException:
|
|
260
|
+
with library_state.locked():
|
|
261
|
+
current = library_state.load(model.id)
|
|
262
|
+
if current is not None:
|
|
263
|
+
if prior_verification is not None:
|
|
264
|
+
current["verification"] = prior_verification
|
|
265
|
+
else:
|
|
266
|
+
current["verification"] = {"status": "untested"}
|
|
267
|
+
library_state.save(current)
|
|
268
|
+
raise
|
|
269
|
+
|
|
270
|
+
now_iso = plan_envelope.utc_now()
|
|
271
|
+
if finished["ok"]:
|
|
272
|
+
progress(model.id, "smoke_test", 3, 3)
|
|
273
|
+
verified: VerificationRecord = {
|
|
274
|
+
"status": "verified",
|
|
275
|
+
"context_tokens": ctx,
|
|
276
|
+
"tested_at": now_iso,
|
|
277
|
+
}
|
|
278
|
+
with library_state.locked():
|
|
279
|
+
current = library_state.load(model.id)
|
|
280
|
+
if current is not None:
|
|
281
|
+
current["verification"] = verified
|
|
282
|
+
if jinja_fallback and isinstance(current.get("custom"), dict):
|
|
283
|
+
current["custom"]["has_chat_template"] = False
|
|
284
|
+
library_state.save(current)
|
|
285
|
+
else:
|
|
286
|
+
diag_log = _diagnostic_text(finished, server_log)
|
|
287
|
+
kind, code = library_serve.classify_failure_text(diag_log)
|
|
288
|
+
failure: VerificationFailureRecord = {
|
|
289
|
+
"kind": kind,
|
|
290
|
+
"code": code,
|
|
291
|
+
"context_tokens": ctx,
|
|
292
|
+
"can_retry_lower_ctx": kind == "oom" and ctx > 2048,
|
|
293
|
+
"can_redownload": kind == "corrupt",
|
|
294
|
+
}
|
|
295
|
+
if diag_log:
|
|
296
|
+
failure["diagnostic_log"] = diag_log
|
|
297
|
+
failed_ver: VerificationRecord = {
|
|
298
|
+
"status": "failed",
|
|
299
|
+
"context_tokens": ctx,
|
|
300
|
+
"tested_at": now_iso,
|
|
301
|
+
"failure": failure,
|
|
302
|
+
}
|
|
303
|
+
with library_state.locked():
|
|
304
|
+
current = library_state.load(model.id)
|
|
305
|
+
if current is not None:
|
|
306
|
+
current["verification"] = failed_ver
|
|
307
|
+
library_state.save(current)
|
|
308
|
+
summary = custom_hub.redact_secrets(
|
|
309
|
+
remote_ops.redact_text(str(finished.get("error") or "smoke test failed"))
|
|
310
|
+
)
|
|
311
|
+
raise LibraryError(code, summary, failed=True)
|
|
312
|
+
|
|
313
|
+
return library_status.model_row(
|
|
314
|
+
library_status.Library.read(library_jobs.probe(), base_dir), model.id
|
|
315
|
+
)
|
|
@@ -86,6 +86,46 @@ class LoadPosture(_LoadPostureRequired, total=False):
|
|
|
86
86
|
forced: bool
|
|
87
87
|
|
|
88
88
|
|
|
89
|
+
class _CustomMetaRequired(TypedDict):
|
|
90
|
+
hub: str # huggingface | modelscope
|
|
91
|
+
repo_id: str
|
|
92
|
+
format: str # gguf | mlx
|
|
93
|
+
variant_id: str
|
|
94
|
+
shard_count: int
|
|
95
|
+
standby_on_restart: bool
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class CustomMeta(_CustomMetaRequired, total=False):
|
|
99
|
+
revision: str
|
|
100
|
+
url: str
|
|
101
|
+
mmproj_file: str
|
|
102
|
+
mmproj_bytes: int
|
|
103
|
+
accepted_risk: bool
|
|
104
|
+
has_chat_template: bool
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class _VerificationFailureRequired(TypedDict):
|
|
108
|
+
kind: str # oom | unsupported_arch | corrupt | unknown
|
|
109
|
+
code: str
|
|
110
|
+
context_tokens: int
|
|
111
|
+
can_retry_lower_ctx: bool
|
|
112
|
+
can_redownload: bool
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class VerificationFailureRecord(_VerificationFailureRequired, total=False):
|
|
116
|
+
diagnostic_log: str
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class _VerificationRequired(TypedDict):
|
|
120
|
+
status: str # untested | running | verified | failed
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class VerificationRecord(_VerificationRequired, total=False):
|
|
124
|
+
context_tokens: int
|
|
125
|
+
tested_at: str
|
|
126
|
+
failure: VerificationFailureRecord
|
|
127
|
+
|
|
128
|
+
|
|
89
129
|
class Record(_RecordRequired, total=False):
|
|
90
130
|
base_dir: str # where it was downloaded: its weights, engine and deployments live there
|
|
91
131
|
memory_bytes: int # the footprint priced at download (on the pool's whole capacity)
|
|
@@ -98,6 +138,10 @@ class Record(_RecordRequired, total=False):
|
|
|
98
138
|
stack_provider: str # converted: its own stack provider, the main or the fastest LLM
|
|
99
139
|
pi_model: str # what pi offers once it is loaded; fixed when the record is made
|
|
100
140
|
load_posture: LoadPosture # elastic posture & warning metadata recorded on load
|
|
141
|
+
baseline_plan: Plan # pristine capacity plan preserved while a degraded/active load runs
|
|
142
|
+
custom: CustomMeta # custom hub model metadata (absent for curated models)
|
|
143
|
+
verification: VerificationRecord # smoke-test verification state (custom models)
|
|
144
|
+
catalog_entry: dict[str, object] # schema-3 entry snapshot for custom models
|
|
101
145
|
|
|
102
146
|
|
|
103
147
|
class _JobSince20261113(TypedDict, total=False):
|
|
@@ -106,8 +150,13 @@ class _JobSince20261113(TypedDict, total=False):
|
|
|
106
150
|
port: int # a load's port, reserved from admission until its record names it
|
|
107
151
|
source: str # download source label: huggingface | modelscope | custom | cache
|
|
108
152
|
connections: int # active parallel download connections
|
|
153
|
+
shard_index: int # 1-based active shard index for multi-shard downloads
|
|
154
|
+
shard_count: int # total shard count for multi-shard downloads
|
|
109
155
|
load_step: str # load sub-step: prepare | start | load | warm
|
|
110
156
|
error: Problem # a download that stopped cleanly: status shows why; cancel discards it
|
|
157
|
+
custom: CustomMeta # custom hub metadata while download is in progress
|
|
158
|
+
catalog_entry: dict[str, object] # provisional catalog entry while custom download runs
|
|
159
|
+
base_dir: str # base directory for an in-progress custom download
|
|
111
160
|
|
|
112
161
|
|
|
113
162
|
class Job(_JobSince20261113):
|
|
@@ -256,8 +305,10 @@ def cancelled(job: Job) -> bool:
|
|
|
256
305
|
|
|
257
306
|
|
|
258
307
|
def clear_job(model: str) -> None:
|
|
308
|
+
job = job_path(model)
|
|
259
309
|
for path in (
|
|
260
|
-
|
|
310
|
+
job,
|
|
311
|
+
job.with_name(job.name + ".tmp"),
|
|
261
312
|
cancel_path(model),
|
|
262
313
|
pid_path(model),
|
|
263
314
|
Path(str(pid_path(model)) + ".identity.json"),
|
|
@@ -297,6 +348,8 @@ class JobHandle:
|
|
|
297
348
|
source: str | None = None,
|
|
298
349
|
connections: int | None = None,
|
|
299
350
|
load_step: str | None = None,
|
|
351
|
+
shard_index: int | None = None,
|
|
352
|
+
shard_count: int | None = None,
|
|
300
353
|
) -> None:
|
|
301
354
|
import time
|
|
302
355
|
|
|
@@ -305,6 +358,8 @@ class JobHandle:
|
|
|
305
358
|
self.job.get("load_step"),
|
|
306
359
|
self.job.get("source"),
|
|
307
360
|
self.job.get("total"),
|
|
361
|
+
self.job.get("shard_index"),
|
|
362
|
+
self.job.get("shard_count"),
|
|
308
363
|
)
|
|
309
364
|
self.job["phase"], self.job["done"], self.job["total"] = phase, done, total
|
|
310
365
|
self.job["bytes_per_second"] = bytes_per_second
|
|
@@ -317,9 +372,19 @@ class JobHandle:
|
|
|
317
372
|
self.job["connections"] = connections
|
|
318
373
|
else:
|
|
319
374
|
self.job.pop("connections", None)
|
|
375
|
+
if shard_index is not None and shard_index >= 1:
|
|
376
|
+
self.job["shard_index"] = shard_index
|
|
377
|
+
else:
|
|
378
|
+
self.job.pop("shard_index", None)
|
|
379
|
+
if shard_count is not None and shard_count >= 1:
|
|
380
|
+
self.job["shard_count"] = shard_count
|
|
381
|
+
else:
|
|
382
|
+
self.job.pop("shard_count", None)
|
|
320
383
|
else:
|
|
321
384
|
self.job.pop("source", None)
|
|
322
385
|
self.job.pop("connections", None)
|
|
386
|
+
self.job.pop("shard_index", None)
|
|
387
|
+
self.job.pop("shard_count", None)
|
|
323
388
|
if phase in ("load", "warm") and load_step is not None:
|
|
324
389
|
self.job["load_step"] = load_step
|
|
325
390
|
else:
|
|
@@ -329,6 +394,8 @@ class JobHandle:
|
|
|
329
394
|
self.job.get("load_step"),
|
|
330
395
|
self.job.get("source"),
|
|
331
396
|
self.job.get("total"),
|
|
397
|
+
self.job.get("shard_index"),
|
|
398
|
+
self.job.get("shard_count"),
|
|
332
399
|
) != prev
|
|
333
400
|
now = time.monotonic()
|
|
334
401
|
if changed or now - self._written >= JOB_WRITE_EVERY_S or done >= total:
|
|
@@ -365,12 +432,18 @@ def acquire(
|
|
|
365
432
|
needs: list[str] | None = None,
|
|
366
433
|
*,
|
|
367
434
|
port: int = 0,
|
|
435
|
+
custom: CustomMeta | None = None,
|
|
436
|
+
catalog_entry: dict[str, object] | None = None,
|
|
437
|
+
base_dir: str | None = None,
|
|
368
438
|
) -> Job:
|
|
369
439
|
"""Under ``locked()``, after the caller validated the model: claim it for this process.
|
|
370
440
|
The claim is the job and its process-identity receipt; every other library command sees it
|
|
371
441
|
(``refuse_busy``) until ``release``. A load's claim reserves its memory in its pool."""
|
|
372
442
|
become_leader()
|
|
373
443
|
now = utc_now()
|
|
444
|
+
initial_phase = (
|
|
445
|
+
"download" if kind == "download" else "smoke_test" if kind == "smoke_test" else "load"
|
|
446
|
+
)
|
|
374
447
|
job: Job = {
|
|
375
448
|
"schema": JOB_SCHEMA,
|
|
376
449
|
"id": uuid.uuid4().hex,
|
|
@@ -380,7 +453,7 @@ def acquire(
|
|
|
380
453
|
"memory_bytes": memory_bytes,
|
|
381
454
|
"files": files,
|
|
382
455
|
"needs": list(needs if needs is not None else files),
|
|
383
|
-
"phase":
|
|
456
|
+
"phase": initial_phase,
|
|
384
457
|
"done": 0,
|
|
385
458
|
"total": 0,
|
|
386
459
|
"bytes_per_second": 0,
|
|
@@ -389,6 +462,12 @@ def acquire(
|
|
|
389
462
|
}
|
|
390
463
|
if port:
|
|
391
464
|
job["port"] = port
|
|
465
|
+
if custom is not None:
|
|
466
|
+
job["custom"] = custom
|
|
467
|
+
if catalog_entry is not None:
|
|
468
|
+
job["catalog_entry"] = catalog_entry
|
|
469
|
+
if base_dir is not None:
|
|
470
|
+
job["base_dir"] = base_dir
|
|
392
471
|
hosts.save_private(job_path(model), job)
|
|
393
472
|
try:
|
|
394
473
|
process_identity.save(pid_path(model), os.getpid())
|