@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,123 @@
|
|
|
1
|
+
"""Weight formats: how many bits one parameter costs in a published file, and which engines and
|
|
2
|
+
devices run each format.
|
|
3
|
+
|
|
4
|
+
``bits`` is a typical file size over parameter count, all tensors included, not the nominal bit
|
|
5
|
+
width: a GGUF k-quant keeps some tensors (attention V, the output layer) at higher precision, and
|
|
6
|
+
group-quantized formats store a scale (and a zero point) per group. Small models with large
|
|
7
|
+
vocabularies run above these averages because embeddings are a bigger share of them; a real file
|
|
8
|
+
size always outranks the table. Sources for each number are in
|
|
9
|
+
research/2026-11-13-model-size-tools.md.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
|
|
16
|
+
# Format families and the engine each one runs on by default.
|
|
17
|
+
FAMILIES = ("float", "gguf", "mlx", "awq", "gptq", "fp8", "nvfp4", "mxfp4", "exl", "bnb")
|
|
18
|
+
DEFAULT_ENGINE = {
|
|
19
|
+
"float": "vllm",
|
|
20
|
+
"gguf": "llama.cpp",
|
|
21
|
+
"mlx": "mlx",
|
|
22
|
+
"awq": "vllm",
|
|
23
|
+
"gptq": "vllm",
|
|
24
|
+
"fp8": "vllm",
|
|
25
|
+
"nvfp4": "vllm",
|
|
26
|
+
"mxfp4": "llama.cpp",
|
|
27
|
+
"exl": "exllama",
|
|
28
|
+
"bnb": "transformers",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Where a bits figure comes from: "file" a whole Llama-3.1-8B file in llama.cpp's quantize README
|
|
33
|
+
# (output and some attention/FFN tensors kept at higher precision); "block" the ggml block or
|
|
34
|
+
# group layout alone, so whole files run 0.2-0.8 bits higher; "derived" the tensor layout plus
|
|
35
|
+
# the 16-bit embeddings and output layer such checkpoints keep, for a 30B-class model; "target"
|
|
36
|
+
# a variable-rate format's requested average, which leaves the embeddings out.
|
|
37
|
+
BASES = ("file", "block", "derived", "target", "exact")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class QuantFormat:
|
|
42
|
+
name: str
|
|
43
|
+
family: str
|
|
44
|
+
bits: float # typical file bits per parameter, every tensor included
|
|
45
|
+
basis: str = "block"
|
|
46
|
+
note: str = ""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _q(name: str, family: str, bits: float, basis: str, note: str = "") -> QuantFormat:
|
|
50
|
+
return QuantFormat(name, family, bits, basis, note)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
FORMATS: tuple[QuantFormat, ...] = (
|
|
54
|
+
_q("F32", "float", 32.0, "exact"),
|
|
55
|
+
_q("BF16", "float", 16.0, "exact", "the usual released checkpoint"),
|
|
56
|
+
_q("F16", "float", 16.0, "exact"),
|
|
57
|
+
_q("FP8", "fp8", 8.2, "derived", "E4M3 + fp32 block scales, 16-bit embeddings; Ada/Hopper+"),
|
|
58
|
+
_q("Q8_0", "gguf", 8.5, "file", "32 int8 + f16 scale per block"),
|
|
59
|
+
_q("MLX-8BIT", "mlx", 8.5, "block", "group 64, scale + bias; embeddings quantized too"),
|
|
60
|
+
_q("Q6_K", "gguf", 6.56, "file"),
|
|
61
|
+
_q("MLX-6BIT", "mlx", 6.5, "block"),
|
|
62
|
+
_q("Q5_K_M", "gguf", 5.7, "file"),
|
|
63
|
+
_q("Q5_K_S", "gguf", 5.57, "file"),
|
|
64
|
+
_q("Q4_K_M", "gguf", 4.89, "file", "the common default"),
|
|
65
|
+
_q("Q4_K_S", "gguf", 4.67, "file"),
|
|
66
|
+
_q("IQ4_NL", "gguf", 4.68, "file"),
|
|
67
|
+
_q("Q4_0", "gguf", 4.5, "block", "also the usual QAT release format"),
|
|
68
|
+
_q("MLX-4BIT", "mlx", 4.5, "block", "group 64, scale + bias; embeddings quantized too"),
|
|
69
|
+
_q("NVFP4", "nvfp4", 4.9, "derived", "FP4 + E4M3 scale per 16, 16-bit embeddings; Blackwell"),
|
|
70
|
+
_q("AWQ-INT4", "awq", 4.6, "derived", "int4 g128 is 4.16; 16-bit embeddings: 8B 5.7, 70B 4.5"),
|
|
71
|
+
_q(
|
|
72
|
+
"GPTQ-INT4", "gptq", 4.6, "derived", "int4 g128 is 4.16; 16-bit embeddings: 8B 5.7, 70B 4.5"
|
|
73
|
+
),
|
|
74
|
+
_q(
|
|
75
|
+
"NF4", "bnb", 4.9, "derived", "bitsandbytes 4-bit 4.5 (4.127 double-quant), bf16 embeddings"
|
|
76
|
+
),
|
|
77
|
+
_q("IQ4_XS", "gguf", 4.46, "file"),
|
|
78
|
+
_q("MXFP4", "mxfp4", 4.34, "file", "gpt-oss-120b: MXFP4 experts, Q8_0 elsewhere"),
|
|
79
|
+
_q("Q3_K_L", "gguf", 4.3, "file"),
|
|
80
|
+
_q("Q3_K_M", "gguf", 4.0, "file"),
|
|
81
|
+
_q("Q3_K_S", "gguf", 3.64, "file"),
|
|
82
|
+
_q("MLX-3BIT", "mlx", 3.5, "block"),
|
|
83
|
+
_q("IQ3_S", "gguf", 3.44, "block"),
|
|
84
|
+
_q("IQ3_XXS", "gguf", 3.25, "file"),
|
|
85
|
+
_q("Q2_K", "gguf", 3.16, "file"),
|
|
86
|
+
_q("IQ2_M", "gguf", 2.7, "block"),
|
|
87
|
+
_q("IQ2_XXS", "gguf", 2.38, "file"),
|
|
88
|
+
_q("IQ2_XS", "gguf", 2.31, "block"),
|
|
89
|
+
_q("IQ1_S", "gguf", 2.0, "file", "IQ1/IQ2 keep the output at Q5_K"),
|
|
90
|
+
_q("IQ1_M", "gguf", 1.75, "block"),
|
|
91
|
+
)
|
|
92
|
+
BY_NAME = {f.name: f for f in FORMATS}
|
|
93
|
+
QUANT_BITS = {f.name: f.bits for f in FORMATS}
|
|
94
|
+
# EXL2/EXL3 and other variable-rate formats carry their bit rate in the name: EXL3-4.0, EXL2-6.5.
|
|
95
|
+
EXL_PREFIXES = ("EXL2-", "EXL3-")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def normalize(name: str) -> str:
|
|
99
|
+
"""Upper case without an Unsloth dynamic ``UD-`` prefix: "ud-q4_k_m" reads "Q4_K_M"."""
|
|
100
|
+
key = name.strip().upper()
|
|
101
|
+
return key[3:] if key.startswith("UD-") else key
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def lookup(name: str) -> QuantFormat | None:
|
|
105
|
+
"""The format a name means, a variable-rate EXL name included; None when unknown."""
|
|
106
|
+
key = normalize(name)
|
|
107
|
+
if key in BY_NAME:
|
|
108
|
+
return BY_NAME[key]
|
|
109
|
+
for prefix in EXL_PREFIXES:
|
|
110
|
+
if key.startswith(prefix):
|
|
111
|
+
try:
|
|
112
|
+
bits = float(key[len(prefix) :])
|
|
113
|
+
except ValueError:
|
|
114
|
+
return None
|
|
115
|
+
if 1.0 <= bits <= 16.0:
|
|
116
|
+
return QuantFormat(key, "exl", bits, "target", "ExLlama: embeddings stay 16-bit")
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def nearest(bits: float, families: tuple[str, ...] = ("gguf",)) -> QuantFormat:
|
|
121
|
+
"""The listed format closest to ``bits`` among ``families`` (GGUF by default)."""
|
|
122
|
+
pool = [f for f in FORMATS if f.family in families] or list(FORMATS)
|
|
123
|
+
return min(pool, key=lambda f: (abs(f.bits - bits), f.name))
|
|
@@ -15,6 +15,7 @@ from localmodels import (
|
|
|
15
15
|
stack,
|
|
16
16
|
stack_hardware,
|
|
17
17
|
stack_summary,
|
|
18
|
+
suite,
|
|
18
19
|
)
|
|
19
20
|
from localmodels import catalog as cat
|
|
20
21
|
from localmodels.budget import gib, gpu_conflicts, unknown_services
|
|
@@ -143,7 +144,8 @@ def _show_parts(
|
|
|
143
144
|
f"磁盘 {gib(int(str(budget['disk_needed_bytes'])))}"
|
|
144
145
|
)
|
|
145
146
|
print(
|
|
146
|
-
" 理由
|
|
147
|
+
" 理由 只选窗口至少 64K、满足引擎内存门槛的已验证 LLM;llama.cpp 权重和 KV 全驻留 GPU,"
|
|
148
|
+
"Strata 允许专家驻留内存;能读图的默认开启图片输入"
|
|
147
149
|
"(决策 31,--vision off 关闭),装机后 SimplexAI 分优先、"
|
|
148
150
|
"预测解码速度其次(--prefer smartest);网页搜索默认安装(决策 37,--no-search 不装);"
|
|
149
151
|
"决策模型与 embedding/reranker/STT 是选装(--decision、--aux),按剩余资源装入,"
|
|
@@ -199,6 +201,7 @@ def _show_evidence(plan: stack.StackPlan, *, detailed: bool) -> None:
|
|
|
199
201
|
)
|
|
200
202
|
entries = {entry.id: entry for entry in cat.load_catalog_file()}
|
|
201
203
|
recipes = {recipe["id"]: recipe for recipe in cat.components()}
|
|
204
|
+
qualities = {recipe["id"]: recipe.get("quality") for recipe in suite.recipes()}
|
|
202
205
|
for part in [plan["llm"], *([plan["decision"]] if plan["decision"] else []), *plan["aux"]]:
|
|
203
206
|
model_id = part["model"]["id"]
|
|
204
207
|
entry = entries.get(model_id)
|
|
@@ -218,9 +221,10 @@ def _show_evidence(plan: stack.StackPlan, *, detailed: bool) -> None:
|
|
|
218
221
|
f" 运行时 {engine['build']},source={engine['source']},"
|
|
219
222
|
f"commit={engine.get('commit', '未固定')}"
|
|
220
223
|
)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
quality = qualities.get(model_id)
|
|
225
|
+
sources = entry.quality_sources if entry else tuple(quality["sources"]) if quality else ()
|
|
226
|
+
for source in sources:
|
|
227
|
+
print(f" 能力排序出处 [{source['type']}] {source['ref']} ({source['date']})")
|
|
224
228
|
|
|
225
229
|
|
|
226
230
|
STATUS_LABELS = {"candidate": "候选", "validated": "已验证", "deprecated": "已弃用"}
|
|
@@ -35,6 +35,7 @@ class PlannedFile(PinnedFile):
|
|
|
35
35
|
class ReusableFile(PlannedFile, total=False):
|
|
36
36
|
reuse: str # same name and size found on the host; verified there before hard-linking
|
|
37
37
|
mirrors: list[Source] # other sources of the same pinned bytes; the host uses the fastest
|
|
38
|
+
generated: bool # a pinned preparation output, never a network download
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
class Build(TypedDict):
|
|
@@ -7,7 +7,7 @@ ACTION`` exactly like probe.py, with the parameters prepended to the script sour
|
|
|
7
7
|
reports JSON lines on stdout: {"event": "log"|"progress"|"result"|"error", ...}.
|
|
8
8
|
|
|
9
9
|
The action handlers live in the sibling modules remote_ops_download, remote_ops_service,
|
|
10
|
-
remote_ops_verify and remote_ops_remove; transport ships
|
|
10
|
+
remote_ops_verify and remote_ops_remove; transport ships their helpers as one payload whose
|
|
11
11
|
in-memory loader resolves the same ``from localmodels import ...`` this package uses. This
|
|
12
12
|
entry module keeps the shared primitives (emit, fetch, unpack, paths, systemctl, http) and the
|
|
13
13
|
TypedDict parameter contract; siblings reach them as ``remote_ops.<name>`` — late binding that
|
|
@@ -31,7 +31,8 @@ import tarfile
|
|
|
31
31
|
import time
|
|
32
32
|
import urllib.error
|
|
33
33
|
import urllib.request
|
|
34
|
-
|
|
34
|
+
import zipfile
|
|
35
|
+
from collections.abc import Callable, Iterator
|
|
35
36
|
from typing import TypedDict, cast
|
|
36
37
|
|
|
37
38
|
if __name__ == "__main__":
|
|
@@ -70,6 +71,7 @@ class Download(TypedDict):
|
|
|
70
71
|
class Reusable(Download, total=False):
|
|
71
72
|
reuse: str # a copy already on the host; hard-linked only after its SHA256 matches
|
|
72
73
|
mirrors: list[Source] # other sources of the same pinned bytes; the fastest is used
|
|
74
|
+
generated: bool # a pinned output materialized by the approved preparation descriptor
|
|
73
75
|
|
|
74
76
|
|
|
75
77
|
class Archive(TypedDict):
|
|
@@ -96,10 +98,28 @@ class EngineParams(_Engine, total=False):
|
|
|
96
98
|
binary: str # the executable the engine archive must contain (default llama-server)
|
|
97
99
|
|
|
98
100
|
|
|
99
|
-
class
|
|
101
|
+
class StrataPreparation(TypedDict):
|
|
102
|
+
kind: str
|
|
103
|
+
engine_dir: str
|
|
104
|
+
model_dir: str
|
|
105
|
+
gguf: str
|
|
106
|
+
pack: str
|
|
107
|
+
experts_bin: bool
|
|
108
|
+
gguf_py: Archive
|
|
109
|
+
mtp_revision: str
|
|
110
|
+
download_bytes: int
|
|
111
|
+
scratch_bytes: int
|
|
112
|
+
hf_endpoint: str
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class _DownloadParams(TypedDict):
|
|
100
116
|
files: list[Reusable]
|
|
101
117
|
|
|
102
118
|
|
|
119
|
+
class DownloadParams(_DownloadParams, total=False):
|
|
120
|
+
preparation: StrataPreparation
|
|
121
|
+
|
|
122
|
+
|
|
103
123
|
class _Install(ServiceParams):
|
|
104
124
|
argv: list[str]
|
|
105
125
|
env: dict[str, str]
|
|
@@ -125,6 +145,7 @@ class VerifyParams(_Verify, total=False):
|
|
|
125
145
|
input_tokens: int # served just under it, refused (not truncated) just over it
|
|
126
146
|
vision: bool # the LLM loads a picture reader: a synthetic picture must be read too
|
|
127
147
|
window: int # stack agent LLM: /props n_ctx must be at least the planned window
|
|
148
|
+
weights_on_gpu: bool # none stay in host memory: Windows gets back what they were read through
|
|
128
149
|
|
|
129
150
|
|
|
130
151
|
class RemoveParams(ServiceParams, total=False):
|
|
@@ -132,11 +153,12 @@ class RemoveParams(ServiceParams, total=False):
|
|
|
132
153
|
purge_files: list[str] # model files a purge may delete besides the deployment dir
|
|
133
154
|
purge: list[str] # the listed files the operator approved deleting
|
|
134
155
|
config_files: list[str] # files install wrote from the plan's config_files
|
|
156
|
+
preparation_dir: str # the recorded model root whose failed preparation a purge may list
|
|
135
157
|
|
|
136
158
|
|
|
137
159
|
class Actions(TypedDict): # deploy.PerAction holds the parameter builders to these names
|
|
138
160
|
engine: Callable[[EngineParams], None] # fetch pinned engine archives, verify, unpack once
|
|
139
|
-
download: Callable[[DownloadParams], None] #
|
|
161
|
+
download: Callable[[DownloadParams], None] # fetch inputs and materialize pinned outputs
|
|
140
162
|
install: Callable[[InstallParams], None] # launch script and systemd --user unit (or nohup)
|
|
141
163
|
start: Callable[[ServiceParams], None]
|
|
142
164
|
stop: Callable[[ServiceParams], None]
|
|
@@ -175,6 +197,46 @@ def emit(event: str, **fields: object) -> None:
|
|
|
175
197
|
sys.stdout.flush()
|
|
176
198
|
|
|
177
199
|
|
|
200
|
+
# Where a multi-file step stands: act_download and act_engine set it around each file, so a
|
|
201
|
+
# download event also counts the component's bytes across them. Files before this one are on
|
|
202
|
+
# disk already.
|
|
203
|
+
_step: dict[str, int] = {}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def step_fields(done: int) -> dict[str, int]:
|
|
207
|
+
"""The component-wide counters of a download event: file i of n, bytes on disk of all."""
|
|
208
|
+
if not _step:
|
|
209
|
+
return {}
|
|
210
|
+
return {
|
|
211
|
+
"file_index": _step["index"],
|
|
212
|
+
"file_count": _step["count"],
|
|
213
|
+
"component_done": _step["before"] + done,
|
|
214
|
+
"component_total": _step["total"],
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def each_file(files: list[tuple[str, int]]) -> Iterator[int]:
|
|
219
|
+
"""Yield each file's position in order, tracking it for step_fields until the step ends."""
|
|
220
|
+
sizes = [size for _, size in files]
|
|
221
|
+
kept = [
|
|
222
|
+
size
|
|
223
|
+
if os.path.isfile(path) and os.path.getsize(path) == size
|
|
224
|
+
else min(size, remote_ops_download.kept_bytes(path + ".part", size))
|
|
225
|
+
for path, size in files
|
|
226
|
+
]
|
|
227
|
+
try:
|
|
228
|
+
for i in range(len(sizes)):
|
|
229
|
+
_step.update(
|
|
230
|
+
index=i + 1,
|
|
231
|
+
count=len(sizes),
|
|
232
|
+
before=sum(sizes[:i]) + sum(kept[i + 1 :]),
|
|
233
|
+
total=sum(sizes),
|
|
234
|
+
)
|
|
235
|
+
yield i
|
|
236
|
+
finally:
|
|
237
|
+
_step.clear()
|
|
238
|
+
|
|
239
|
+
|
|
178
240
|
def _home(value: str) -> str:
|
|
179
241
|
return os.path.expanduser(value) if value.startswith("~/") else value
|
|
180
242
|
|
|
@@ -273,8 +335,36 @@ def fetch(
|
|
|
273
335
|
raise error or RuntimeError(f"{label} has no download source")
|
|
274
336
|
|
|
275
337
|
|
|
338
|
+
def _relative(name: str) -> str:
|
|
339
|
+
while name.startswith("./"):
|
|
340
|
+
name = name[2:]
|
|
341
|
+
return name
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _unzip(archive: str, directory: str) -> None:
|
|
345
|
+
"""A Windows release zip: regular files only, each kept inside ``directory``."""
|
|
346
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
347
|
+
names = [_relative(i.filename.replace("\\", "/")) for i in bundle.infolist()]
|
|
348
|
+
tops = {n.split("/", 1)[0] for n in names if n}
|
|
349
|
+
strip = len(tops) == 1 and any("/" in n for n in names)
|
|
350
|
+
for info, name in zip(bundle.infolist(), names):
|
|
351
|
+
if strip:
|
|
352
|
+
name = name.split("/", 1)[1] if "/" in name else ""
|
|
353
|
+
if not name or info.is_dir() or name.startswith("/") or ".." in name.split("/"):
|
|
354
|
+
continue
|
|
355
|
+
if ":" in name or (info.external_attr >> 16) & 0o170000 == 0o120000:
|
|
356
|
+
continue # a drive letter or a symlink entry
|
|
357
|
+
target = os.path.join(directory, *name.split("/"))
|
|
358
|
+
os.makedirs(os.path.dirname(target), exist_ok=True)
|
|
359
|
+
with bundle.open(info) as source, open(target, "wb") as dest:
|
|
360
|
+
shutil.copyfileobj(source, dest)
|
|
361
|
+
|
|
362
|
+
|
|
276
363
|
def unpack(archive: str, directory: str) -> None:
|
|
277
364
|
"""Extract into ``directory``, dropping the archive's single top folder when it has one."""
|
|
365
|
+
if archive.endswith(".zip"):
|
|
366
|
+
_unzip(archive, directory)
|
|
367
|
+
return
|
|
278
368
|
with tarfile.open(archive) as tar:
|
|
279
369
|
members = tar.getmembers()
|
|
280
370
|
tops = {m.name.lstrip("./").split("/", 1)[0] for m in members if m.name.lstrip("./")}
|
|
@@ -299,7 +389,7 @@ def _paths(p: ServiceParams) -> dict[str, str]:
|
|
|
299
389
|
root = _expand(p["deploy_dir"])
|
|
300
390
|
return {
|
|
301
391
|
"root": root,
|
|
302
|
-
"script": os.path.join(root, "run.sh"),
|
|
392
|
+
"script": os.path.join(root, "run.cmd" if sys.platform == "win32" else "run.sh"),
|
|
303
393
|
"log": os.path.join(root, "server.log"),
|
|
304
394
|
"key": os.path.join(root, "api-key"),
|
|
305
395
|
"pid": os.path.join(root, "server.pid"),
|
|
@@ -321,8 +411,13 @@ def _systemctl_ok(*args: str) -> None:
|
|
|
321
411
|
raise RuntimeError(f"systemctl {args[0]} failed: " + out)
|
|
322
412
|
|
|
323
413
|
|
|
414
|
+
# macOS and Windows have no /proc: their nohup services keep process identity receipts.
|
|
415
|
+
def receipts() -> bool:
|
|
416
|
+
return sys.platform in ("darwin", "win32")
|
|
417
|
+
|
|
418
|
+
|
|
324
419
|
def _pid_alive(pid_path: str) -> int | None:
|
|
325
|
-
if
|
|
420
|
+
if receipts():
|
|
326
421
|
return process_identity.status(pid_path)[1]
|
|
327
422
|
try:
|
|
328
423
|
pid = int(_read(pid_path).strip())
|
|
@@ -334,6 +429,9 @@ def _pid_alive(pid_path: str) -> int | None:
|
|
|
334
429
|
|
|
335
430
|
def _port_owner(port: int) -> bool:
|
|
336
431
|
"""True when something already listens on 127.0.0.1:port."""
|
|
432
|
+
if sys.platform == "win32": # a refused loopback connect retries for seconds there
|
|
433
|
+
owners = process_identity.listener_pids(port)
|
|
434
|
+
return owners is None or bool(owners)
|
|
337
435
|
with socket.socket() as s:
|
|
338
436
|
s.settimeout(1)
|
|
339
437
|
return s.connect_ex(("127.0.0.1", port)) == 0
|
|
@@ -20,9 +20,10 @@ import urllib.request
|
|
|
20
20
|
from typing import Tuple
|
|
21
21
|
|
|
22
22
|
try:
|
|
23
|
-
from localmodels import remote_ops
|
|
23
|
+
from localmodels import remote_ops, remote_ops_prepare
|
|
24
24
|
except ImportError: # run as a bare file from this directory
|
|
25
25
|
import remote_ops # type: ignore[import-not-found,no-redef]
|
|
26
|
+
import remote_ops_prepare # type: ignore[import-not-found,no-redef]
|
|
26
27
|
|
|
27
28
|
_Ranked = Tuple["remote_ops.Source", bool] # a source and whether it serves byte ranges
|
|
28
29
|
|
|
@@ -38,7 +39,10 @@ def act_engine(p: remote_ops.EngineParams) -> None:
|
|
|
38
39
|
return
|
|
39
40
|
os.makedirs(directory, exist_ok=True)
|
|
40
41
|
cache = os.path.join(os.path.dirname(directory), ".archives")
|
|
41
|
-
for
|
|
42
|
+
for i in remote_ops.each_file(
|
|
43
|
+
[(os.path.join(cache, a["name"]), a["size_bytes"]) for a in p["assets"]]
|
|
44
|
+
):
|
|
45
|
+
a = p["assets"][i]
|
|
42
46
|
archive = os.path.join(cache, a["name"])
|
|
43
47
|
remote_ops.fetch(a["url"], archive, a["sha256"], a["size_bytes"], a["name"])
|
|
44
48
|
remote_ops.unpack(archive, directory)
|
|
@@ -72,16 +76,26 @@ def _link_copy(source: str, dest: str, sha256: str, size: int, label: str) -> No
|
|
|
72
76
|
|
|
73
77
|
|
|
74
78
|
def act_download(p: remote_ops.DownloadParams) -> None:
|
|
79
|
+
if any(f.get("generated") for f in p["files"]) and not p.get("preparation"):
|
|
80
|
+
raise RuntimeError("generated files need an approved Strata preparation descriptor")
|
|
75
81
|
for f in p["files"]:
|
|
76
82
|
dest, label = remote_ops._expand(f["dest"]), os.path.basename(f["dest"])
|
|
77
83
|
if f.get("reuse"):
|
|
78
84
|
reuse = os.path.realpath(remote_ops._expand(f["reuse"]))
|
|
79
85
|
_link_copy(reuse, dest, f["sha256"], f["size_bytes"], label)
|
|
86
|
+
files = [f for f in p["files"] if not f.get("generated")]
|
|
87
|
+
for i in remote_ops.each_file(
|
|
88
|
+
[(remote_ops._expand(f["dest"]), f["size_bytes"]) for f in files]
|
|
89
|
+
):
|
|
90
|
+
f = files[i]
|
|
91
|
+
dest, label = remote_ops._expand(f["dest"]), os.path.basename(f["dest"])
|
|
80
92
|
if not f["url"] and not os.path.exists(dest + ".sha256"):
|
|
81
93
|
raise RuntimeError(
|
|
82
94
|
f"{f['dest']} has no download URL, and the reusable copy failed the SHA256 check"
|
|
83
95
|
)
|
|
84
96
|
remote_ops.fetch(f["url"], dest, f["sha256"], f["size_bytes"], label, f.get("mirrors"))
|
|
97
|
+
if p.get("preparation"):
|
|
98
|
+
remote_ops_prepare.prepare(p["preparation"], p["files"])
|
|
85
99
|
remote_ops.emit("result", files=len(p["files"]))
|
|
86
100
|
|
|
87
101
|
|
|
@@ -342,6 +356,7 @@ def _run(job: _Transfer, source: remote_ops.Source, label: str, *, ranged: bool)
|
|
|
342
356
|
bytes_per_s=int((done - mark_done) / (now - mark)),
|
|
343
357
|
source=source["source"],
|
|
344
358
|
connections=len(alive),
|
|
359
|
+
**remote_ops.step_fields(done),
|
|
345
360
|
)
|
|
346
361
|
mark, mark_done = now, done
|
|
347
362
|
if ranged:
|