@simplexai/localmodels-win32-x64 0.1.0-dev.58 → 0.1.0-dev.59
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 +57 -56
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +1 -1
- package/modules/localmodels/bifrost_admin.py +53 -8
- package/modules/localmodels/bifrost_config.py +103 -4
- package/modules/localmodels/bifrost_log.py +166 -0
- package/modules/localmodels/budget.py +1 -1
- package/modules/localmodels/catalog.json +55 -32
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +94 -0
- package/modules/localmodels/frontend.py +26 -21
- package/modules/localmodels/gateway_bifrost.py +30 -6
- package/modules/localmodels/hosts.py +99 -12
- package/modules/localmodels/library_convert.py +34 -0
- package/modules/localmodels/library_elastic.py +150 -123
- package/modules/localmodels/library_gateway.py +101 -10
- package/modules/localmodels/library_jobs.py +16 -7
- package/modules/localmodels/library_pricing.py +14 -4
- package/modules/localmodels/library_serve.py +84 -16
- package/modules/localmodels/library_state.py +4 -1
- package/modules/localmodels/library_status.py +18 -4
- package/modules/localmodels/metal.py +1 -1
- package/modules/localmodels/metal_probe.py +4 -4
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/process_identity_linux.py +39 -0
- package/modules/localmodels/remote_ops.py +4 -3
- package/modules/localmodels/remote_ops_download.py +37 -24
- package/modules/localmodels/remote_ops_mirrors.py +43 -2
- package/modules/localmodels/remote_ops_service.py +93 -36
- package/modules/localmodels/runtime_auth.py +4 -1
- package/modules/localmodels/service_wiring.py +238 -12
- 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 +6 -2
- 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 +24 -1
- 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/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.5.txt} +1 -1
- package/modules/localmodels/suite.py +43 -27
- package/modules/localmodels/transport.py +13 -2
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/RECORD +54 -53
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -32,35 +32,16 @@ from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
|
|
|
32
32
|
from localmodels.plan_envelope import PlanError
|
|
33
33
|
from localmodels.probe import HostFacts, Services
|
|
34
34
|
from localmodels.runtime_cli import inspect_runtimes
|
|
35
|
+
from localmodels.setup_inspection_harness import Reason as Reason
|
|
35
36
|
from localmodels.setup_text import Lang, text
|
|
36
37
|
from localmodels.stack_plan import (
|
|
37
38
|
StackError,
|
|
38
39
|
StackOptions,
|
|
39
40
|
StackPlan,
|
|
40
|
-
deployments,
|
|
41
41
|
platform_error,
|
|
42
42
|
)
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
class _ReasonSince014(TypedDict, total=False):
|
|
46
|
-
# Since 0.1.4 (roadmap decision 60), on gpu-memory-required and free-memory-required: the
|
|
47
|
-
# memory free now (measured) and the memory the install needs free (the plan's estimate,
|
|
48
|
-
# with the planner's safety reserve on a GPU), in bytes; gpuIndex names the card.
|
|
49
|
-
gpuIndex: int
|
|
50
|
-
freeBytes: int
|
|
51
|
-
requiredBytes: int
|
|
52
|
-
# On cuda-driver-update-required and cuda-driver-version-unknown: driver and CUDA versions.
|
|
53
|
-
detectedCudaVersion: str
|
|
54
|
-
requiredCudaVersion: str
|
|
55
|
-
requiredDriverVersion: str
|
|
56
|
-
driverVersion: str
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
class Reason(_ReasonSince014):
|
|
60
|
-
code: str
|
|
61
|
-
message: str
|
|
62
|
-
|
|
63
|
-
|
|
64
45
|
class StackMemory(TypedDict, total=False):
|
|
65
46
|
"""What the plan needs against what is free now, in bytes; VRAM only for discrete GPUs."""
|
|
66
47
|
|
|
@@ -164,7 +145,10 @@ def _fits_with_required_cuda(options: StackOptions, facts: HostFacts, required_c
|
|
|
164
145
|
if _plans_hardware(options, upgraded):
|
|
165
146
|
return True
|
|
166
147
|
roomy = _capacity_facts(upgraded)
|
|
167
|
-
|
|
148
|
+
if roomy is not None and _plans_hardware(options, roomy):
|
|
149
|
+
return True
|
|
150
|
+
alone = setup_inspection_harness.without_other_inference(roomy or upgraded)
|
|
151
|
+
return alone is not None and _plans_hardware(options, alone)
|
|
168
152
|
|
|
169
153
|
|
|
170
154
|
def _driver_block(
|
|
@@ -184,22 +168,23 @@ def _driver_block(
|
|
|
184
168
|
}
|
|
185
169
|
|
|
186
170
|
|
|
187
|
-
def
|
|
188
|
-
options: StackOptions, facts: HostFacts, lang: Lang
|
|
171
|
+
def _other_inference_availability(
|
|
172
|
+
options: StackOptions, facts: HostFacts, roomy: HostFacts | None, lang: Lang
|
|
189
173
|
) -> StackAvailability | None:
|
|
190
|
-
|
|
191
|
-
|
|
174
|
+
"""Hardware fits once foreign inference apps/GPU workloads exit: not counted as freeable
|
|
175
|
+
desktop memory (roadmap decision 43), but reported as blocked-now instead of incapable."""
|
|
176
|
+
alone_facts = setup_inspection_harness.without_other_inference(
|
|
177
|
+
roomy if roomy is not None else facts
|
|
178
|
+
)
|
|
179
|
+
if alone_facts is None:
|
|
192
180
|
return None
|
|
193
181
|
try:
|
|
194
|
-
plan = stack.build(options, facts=
|
|
195
|
-
except (PlanError, stack.StackError) as
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
# (roadmap decision 43), but the refusal names the app instead of blaming the hardware.
|
|
201
|
-
if alone := _fits_without_other_inference(options, roomy):
|
|
202
|
-
reason: Reason = {
|
|
182
|
+
plan = stack.build(options, facts=alone_facts, min_prompt_cache=True)
|
|
183
|
+
except (PlanError, stack.StackError) as alone_exc:
|
|
184
|
+
return _driver_block(alone_exc, options, alone_facts, lang)
|
|
185
|
+
if metal.supported(facts):
|
|
186
|
+
reasons: list[Reason] = [
|
|
187
|
+
{
|
|
203
188
|
"code": "plan-unavailable",
|
|
204
189
|
"message": text(
|
|
205
190
|
"inference-app-running",
|
|
@@ -207,21 +192,34 @@ def _capacity_availability(
|
|
|
207
192
|
apps="; ".join(metal.conflicts(facts)),
|
|
208
193
|
),
|
|
209
194
|
}
|
|
195
|
+
]
|
|
196
|
+
else:
|
|
197
|
+
reasons = setup_inspection_harness.gpu_conflict_reasons(
|
|
198
|
+
options, facts, roomy, plan, lang, _plans, _free_memory_reason
|
|
199
|
+
)
|
|
200
|
+
return {"available": False, "reasons": reasons, "plan": plan, "basis": "capacity"}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _capacity_availability(
|
|
204
|
+
options: StackOptions, facts: HostFacts, lang: Lang
|
|
205
|
+
) -> StackAvailability | None:
|
|
206
|
+
roomy = _capacity_facts(facts)
|
|
207
|
+
if roomy is not None:
|
|
208
|
+
try:
|
|
209
|
+
plan = stack.build(options, facts=roomy, min_prompt_cache=True)
|
|
210
|
+
except (PlanError, stack.StackError) as roomy_exc:
|
|
211
|
+
if blocked := _driver_block(roomy_exc, options, roomy, lang):
|
|
212
|
+
return blocked
|
|
213
|
+
else:
|
|
214
|
+
# Roadmap decision 56: an install now prices the memory free now and would refuse,
|
|
215
|
+
# so the stack is not available; the plan shows what it needs.
|
|
210
216
|
return {
|
|
211
217
|
"available": False,
|
|
212
|
-
"reasons":
|
|
213
|
-
"plan":
|
|
218
|
+
"reasons": _held_reasons(options, facts, roomy, plan, lang),
|
|
219
|
+
"plan": plan,
|
|
214
220
|
"basis": "capacity",
|
|
215
221
|
}
|
|
216
|
-
|
|
217
|
-
# Roadmap decision 56: an install now prices the memory free now and would refuse, so the stack
|
|
218
|
-
# is not available; the plan shows what it needs.
|
|
219
|
-
return {
|
|
220
|
-
"available": False,
|
|
221
|
-
"reasons": _held_reasons(options, facts, roomy, plan, lang),
|
|
222
|
-
"plan": plan,
|
|
223
|
-
"basis": "capacity",
|
|
224
|
-
}
|
|
222
|
+
return _other_inference_availability(options, facts, roomy, lang)
|
|
225
223
|
|
|
226
224
|
|
|
227
225
|
def _harness_availability(
|
|
@@ -313,18 +311,6 @@ def _stack(
|
|
|
313
311
|
return {"available": False, "reasons": [reason], "plan": None}
|
|
314
312
|
|
|
315
313
|
|
|
316
|
-
def _fits_without_other_inference(options: StackOptions, roomy: HostFacts) -> StackPlan | None:
|
|
317
|
-
"""A Mac's capacity plan once the inference apps this tool does not own on its GPU
|
|
318
|
-
(``metal.conflicts``) are quit as well, or None when it still does not fit."""
|
|
319
|
-
alone = setup_inspection_harness.without_other_inference(roomy)
|
|
320
|
-
if alone is None:
|
|
321
|
-
return None
|
|
322
|
-
try:
|
|
323
|
-
return stack.build(options, facts=alone)
|
|
324
|
-
except (PlanError, stack.StackError):
|
|
325
|
-
return None
|
|
326
|
-
|
|
327
|
-
|
|
328
314
|
def _plans(options: StackOptions, facts: HostFacts) -> bool:
|
|
329
315
|
try:
|
|
330
316
|
stack.build(options, facts=facts)
|
|
@@ -352,7 +338,7 @@ def _held_reasons(
|
|
|
352
338
|
reasons: list[Reason] = []
|
|
353
339
|
if gpu_short:
|
|
354
340
|
live = {g["index"]: g for g in facts.get("gpus") or []}
|
|
355
|
-
for index, vram in
|
|
341
|
+
for index, vram in setup_inspection_harness.vram_by_card(plan).items():
|
|
356
342
|
card = live.get(index)
|
|
357
343
|
required = vram + AGENT_VRAM_RESERVE_BYTES
|
|
358
344
|
if card is None or card["free_bytes"] >= required:
|
|
@@ -379,16 +365,6 @@ def _held_reasons(
|
|
|
379
365
|
return reasons
|
|
380
366
|
|
|
381
367
|
|
|
382
|
-
def _vram_by_card(plan: StackPlan) -> dict[int, int]:
|
|
383
|
-
"""GPU memory the plan's deployments reserve on each card; a split one counts on each."""
|
|
384
|
-
found: dict[int, int] = {}
|
|
385
|
-
for part in deployments(plan):
|
|
386
|
-
for gpu in decode(part["placement"].get("gpus") or [], list[stack_review.SelectedGPU]):
|
|
387
|
-
index = gpu["index"]
|
|
388
|
-
found[index] = found.get(index, 0) + int(str(part["launch"].get("vram_bytes") or 0))
|
|
389
|
-
return found
|
|
390
|
-
|
|
391
|
-
|
|
392
368
|
def _free_memory_reason(facts: HostFacts, roomy: HostFacts, lang: Lang = "zh") -> Reason:
|
|
393
369
|
"""Names the memory other programs hold now: each reading the capacity plan counted as freed."""
|
|
394
370
|
gib = budget.gib
|
|
@@ -553,8 +529,9 @@ INSPECT_REASONS = (
|
|
|
553
529
|
"hardwareCapable true when the hardware fits, but the gateway port is held or tool checks "
|
|
554
530
|
"failed; free the port or fix the tool issue and check again)\n"
|
|
555
531
|
"gpu-memory-required (stack.state is blocked-now, stack.basis is capacity: other programs "
|
|
556
|
-
"use the GPU memory the plan needs; close them and
|
|
557
|
-
"requiredBytes give the card and its free and needed
|
|
532
|
+
"or another inference app/GPU workload use the GPU memory the plan needs; close them and "
|
|
533
|
+
"check again; gpuIndex, freeBytes and requiredBytes give the card and its free and needed "
|
|
534
|
+
"VRAM)\n"
|
|
558
535
|
"free-memory-required (the same for RAM, freeBytes and requiredBytes in RAM; stack.memory "
|
|
559
536
|
"gives the RAM free and needed). On a Mac whose hardware fits only once another inference "
|
|
560
537
|
"app on its GPU is quit, plan-unavailable (blocked-now) names that app instead of the "
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import copy
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import TypedDict
|
|
6
8
|
|
|
7
9
|
from localmodels import (
|
|
8
10
|
budget,
|
|
@@ -13,12 +15,35 @@ from localmodels import (
|
|
|
13
15
|
stack_compose,
|
|
14
16
|
stack_gpu_memory,
|
|
15
17
|
stack_hardware,
|
|
18
|
+
stack_review,
|
|
16
19
|
stack_suite,
|
|
17
20
|
)
|
|
21
|
+
from localmodels.contracts import decode
|
|
22
|
+
from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
|
|
18
23
|
from localmodels.plan_envelope import PlanError
|
|
19
24
|
from localmodels.probe import HostFacts
|
|
20
25
|
from localmodels.setup_text import Lang, text
|
|
21
|
-
from localmodels.stack_plan import RAM_FLOOR, StackOptions, platform_error
|
|
26
|
+
from localmodels.stack_plan import RAM_FLOOR, StackOptions, StackPlan, deployments, platform_error
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class _ReasonOptional(TypedDict, total=False):
|
|
30
|
+
# Since 0.1.4 (roadmap decision 60), on gpu-memory-required and free-memory-required: the
|
|
31
|
+
# memory free now (measured) and the memory the install needs free (the plan's estimate,
|
|
32
|
+
# with the planner's safety reserve on a GPU), in bytes; gpuIndex names the card.
|
|
33
|
+
gpuIndex: int
|
|
34
|
+
freeBytes: int
|
|
35
|
+
requiredBytes: int
|
|
36
|
+
# On cuda-driver-update-required and cuda-driver-version-unknown: driver and CUDA versions.
|
|
37
|
+
detectedCudaVersion: str
|
|
38
|
+
requiredCudaVersion: str
|
|
39
|
+
requiredDriverVersion: str
|
|
40
|
+
driverVersion: str
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Reason(_ReasonOptional):
|
|
44
|
+
code: str
|
|
45
|
+
message: str
|
|
46
|
+
|
|
22
47
|
|
|
23
48
|
HARNESS_CODES = frozenset({"gateway-port-in-use", "harness-unavailable"})
|
|
24
49
|
_PORT_CONFLICT_HINTS = (
|
|
@@ -104,20 +129,139 @@ def fits_hardware_once(options: StackOptions, facts: HostFacts) -> bool:
|
|
|
104
129
|
|
|
105
130
|
|
|
106
131
|
def without_other_inference(roomy: HostFacts) -> HostFacts | None:
|
|
107
|
-
"""``roomy`` with foreign
|
|
108
|
-
|
|
132
|
+
"""``roomy`` with foreign inference apps/workloads stripped (and conflicted discrete GPUs
|
|
133
|
+
restored to idle VRAM), or None when none are present."""
|
|
134
|
+
if metal.supported(roomy):
|
|
135
|
+
if not metal.conflicts(roomy):
|
|
136
|
+
return None
|
|
137
|
+
alone = copy.deepcopy(roomy)
|
|
138
|
+
services = alone["services"]
|
|
139
|
+
assert services is not None # conflicts come from service discovery
|
|
140
|
+
services["compute_processes"] = [
|
|
141
|
+
p
|
|
142
|
+
for p in services.get("compute_processes") or []
|
|
143
|
+
if p["gpu_uuid"] != metal.METAL_UUID or p["owned"] is True
|
|
144
|
+
]
|
|
145
|
+
return alone
|
|
146
|
+
served = budget.gpu_conflicts(roomy)
|
|
147
|
+
if not served:
|
|
109
148
|
return None
|
|
110
149
|
alone = copy.deepcopy(roomy)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
150
|
+
for gpu in alone.get("gpus") or []:
|
|
151
|
+
if not served.get(gpu["uuid"]):
|
|
152
|
+
continue
|
|
153
|
+
idle = max(0, gpu["total_bytes"] - budget.IDLE_USED_BYTES)
|
|
154
|
+
if gpu["free_bytes"] < idle:
|
|
155
|
+
gpu["free_bytes"], gpu["used_bytes"] = idle, gpu["total_bytes"] - idle
|
|
156
|
+
gpu_services = alone.get("services")
|
|
157
|
+
if gpu_services is not None:
|
|
158
|
+
procs = gpu_services.get("compute_processes")
|
|
159
|
+
if procs is not None:
|
|
160
|
+
gpu_services["compute_processes"] = [
|
|
161
|
+
p for p in procs if not budget.foreign_work(p, alone)
|
|
162
|
+
]
|
|
163
|
+
boxes = gpu_services.get("containers")
|
|
164
|
+
if boxes is not None:
|
|
165
|
+
conflict_labels = {label for labels in served.values() for label in labels}
|
|
166
|
+
gpu_services["containers"] = [
|
|
167
|
+
box
|
|
168
|
+
for box in boxes
|
|
169
|
+
if f"container {box['name']} ({box['image']})" not in conflict_labels
|
|
170
|
+
]
|
|
118
171
|
return alone
|
|
119
172
|
|
|
120
173
|
|
|
174
|
+
def vram_by_card(plan: StackPlan) -> dict[int, int]:
|
|
175
|
+
"""GPU memory the plan's deployments reserve on each card; a split one counts on each."""
|
|
176
|
+
found: dict[int, int] = {}
|
|
177
|
+
for part in deployments(plan):
|
|
178
|
+
for gpu in decode(part["placement"].get("gpus") or [], list[stack_review.SelectedGPU]):
|
|
179
|
+
index = gpu["index"]
|
|
180
|
+
found[index] = found.get(index, 0) + int(str(part["launch"].get("vram_bytes") or 0))
|
|
181
|
+
return found
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def gpu_conflict_reasons(
|
|
185
|
+
options: StackOptions,
|
|
186
|
+
facts: HostFacts,
|
|
187
|
+
roomy: HostFacts | None,
|
|
188
|
+
plan: StackPlan,
|
|
189
|
+
lang: Lang,
|
|
190
|
+
plans_fn: Callable[[StackOptions, HostFacts], bool],
|
|
191
|
+
ram_reason_fn: Callable[[HostFacts, HostFacts, Lang], Reason],
|
|
192
|
+
) -> list[Reason]:
|
|
193
|
+
"""Structured capacity reasons when a discrete NVIDIA GPU is held by foreign GPU work."""
|
|
194
|
+
served = budget.gpu_conflicts(facts)
|
|
195
|
+
live = {g["index"]: g for g in facts.get("gpus") or []}
|
|
196
|
+
nvidia = [g for g in facts.get("gpus") or [] if g.get("vendor") == "nvidia"]
|
|
197
|
+
unified_uuid = (
|
|
198
|
+
nvidia[0]["uuid"] if nvidia and budget.unified_pool_bytes(facts) is not None else None
|
|
199
|
+
)
|
|
200
|
+
summary = stack_review.summarize(plan, lang)
|
|
201
|
+
gib = budget.gib
|
|
202
|
+
reasons: list[Reason] = []
|
|
203
|
+
for index, vram in vram_by_card(plan).items():
|
|
204
|
+
card = live.get(index)
|
|
205
|
+
required = vram + AGENT_VRAM_RESERVE_BYTES
|
|
206
|
+
if (
|
|
207
|
+
card is None
|
|
208
|
+
or card["total_bytes"] <= 0
|
|
209
|
+
or card["uuid"] == unified_uuid
|
|
210
|
+
or card["free_bytes"] >= required
|
|
211
|
+
):
|
|
212
|
+
continue
|
|
213
|
+
apps = "; ".join(served.get(card["uuid"]) or ())
|
|
214
|
+
message = (
|
|
215
|
+
text(
|
|
216
|
+
"gpu-inference-app-running",
|
|
217
|
+
lang,
|
|
218
|
+
index=index,
|
|
219
|
+
free=gib(card["free_bytes"]),
|
|
220
|
+
needed=gib(required),
|
|
221
|
+
apps=apps,
|
|
222
|
+
)
|
|
223
|
+
if apps
|
|
224
|
+
else text(
|
|
225
|
+
"gpu-memory-required",
|
|
226
|
+
lang,
|
|
227
|
+
index=index,
|
|
228
|
+
free=gib(card["free_bytes"]),
|
|
229
|
+
needed=gib(required),
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
reasons.append(
|
|
233
|
+
{
|
|
234
|
+
"code": "gpu-memory-required",
|
|
235
|
+
"message": message,
|
|
236
|
+
"gpuIndex": index,
|
|
237
|
+
"freeBytes": card["free_bytes"],
|
|
238
|
+
"requiredBytes": required,
|
|
239
|
+
}
|
|
240
|
+
)
|
|
241
|
+
ram = facts["ram"]["available_bytes"]
|
|
242
|
+
if roomy is not None and ram < roomy["ram"]["available_bytes"]:
|
|
243
|
+
gpu_only = without_other_inference(facts)
|
|
244
|
+
if gpu_only is None or not plans_fn(options, gpu_only):
|
|
245
|
+
ram_only = copy.deepcopy(facts)
|
|
246
|
+
ram_only["ram"] = copy.deepcopy(roomy["ram"])
|
|
247
|
+
reasons.append(
|
|
248
|
+
{
|
|
249
|
+
**ram_reason_fn(facts, ram_only, lang),
|
|
250
|
+
"freeBytes": ram,
|
|
251
|
+
"requiredBytes": summary["memoryBytes"],
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
if not reasons:
|
|
255
|
+
all_apps = "; ".join(label for labels in served.values() for label in labels)
|
|
256
|
+
reasons.append(
|
|
257
|
+
{
|
|
258
|
+
"code": "plan-unavailable",
|
|
259
|
+
"message": text("gpu-conflict-running", lang, apps=all_apps),
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
return reasons
|
|
263
|
+
|
|
264
|
+
|
|
121
265
|
def hardware_capable_without_harness(options: StackOptions, facts: HostFacts) -> bool:
|
|
122
266
|
"""True when the computer's hardware fits a stack once gateway/harness blockers clear."""
|
|
123
267
|
if fits_hardware_once(options, facts):
|
|
@@ -129,11 +273,11 @@ def hardware_capable_without_harness(options: StackOptions, facts: HostFacts) ->
|
|
|
129
273
|
and fits_hardware_once({**options, "share_gpu": True}, facts)
|
|
130
274
|
):
|
|
131
275
|
return True
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
276
|
+
roomy = capacity_facts(facts)
|
|
277
|
+
if roomy is not None and fits_hardware_once(options, roomy):
|
|
278
|
+
return True
|
|
279
|
+
if (alone := without_other_inference(roomy or facts)) is not None:
|
|
280
|
+
return fits_hardware_once(options, alone)
|
|
137
281
|
return False
|
|
138
282
|
|
|
139
283
|
|
|
@@ -72,6 +72,20 @@ MESSAGES: dict[str, tuple[str, str]] = {
|
|
|
72
72
|
"Mac's GPU and unified memory ({apps}). This tool does not count that memory as free; "
|
|
73
73
|
"quit the app and check again.",
|
|
74
74
|
),
|
|
75
|
+
"gpu-inference-app-running": (
|
|
76
|
+
"这台电脑的显卡可以运行本地模型,但其他推理程序或 GPU 任务目前占用了 GPU {index} 的显存"
|
|
77
|
+
"(空闲 {free},安装约需 {needed}:{apps})。请退出该程序后重新检查;本工具不会停止任何进程。",
|
|
78
|
+
"This computer's GPU can run local models, but another inference app or GPU workload is "
|
|
79
|
+
"using GPU {index}'s memory ({free} free; the install needs about {needed}: {apps}). "
|
|
80
|
+
"Quit that app and check again; this tool stops no process.",
|
|
81
|
+
),
|
|
82
|
+
"gpu-conflict-running": (
|
|
83
|
+
"这台电脑的显卡可以运行本地模型,但其他推理程序或 GPU 任务目前占用了显卡({apps})。"
|
|
84
|
+
"本工具不会把它的显存算作可释放;请退出该程序后重新检查。",
|
|
85
|
+
"This computer's GPU can run local models, but another inference app or GPU workload "
|
|
86
|
+
"holds the GPU ({apps}). This tool does not count that memory as free; quit that app "
|
|
87
|
+
"and check again.",
|
|
88
|
+
),
|
|
75
89
|
"cuda-driver-update-required": (
|
|
76
90
|
"这台电脑的显卡可以运行本地模型,但当前 NVIDIA 驱动支持的 CUDA 版本({detected})低于"
|
|
77
91
|
"本地模型引擎要求的最低版本(CUDA >= {required})。请更新 NVIDIA 驱动后重新检查。",
|
|
@@ -85,7 +85,7 @@ def upgrade_hint(
|
|
|
85
85
|
if roomy is None:
|
|
86
86
|
return None
|
|
87
87
|
try:
|
|
88
|
-
roomy_plan = stack.build(options, facts=roomy)
|
|
88
|
+
roomy_plan = stack.build(options, facts=roomy, min_prompt_cache=True)
|
|
89
89
|
except (PlanError, StackError, harness.HarnessError):
|
|
90
90
|
return None
|
|
91
91
|
live_id = str(live_plan["llm"]["model"]["id"])
|
|
@@ -497,13 +497,17 @@ def mount_byok(
|
|
|
497
497
|
providers = config.setdefault("providers", {})
|
|
498
498
|
providers[BYOK_PROVIDER] = render_byok_provider(creds)
|
|
499
499
|
governance = config.setdefault("governance", {})
|
|
500
|
+
existing_rules = governance.get("routing_rules")
|
|
500
501
|
rules = [
|
|
501
502
|
r
|
|
502
|
-
for r in (
|
|
503
|
-
if r
|
|
503
|
+
for r in (existing_rules if isinstance(existing_rules, list) else [])
|
|
504
|
+
if isinstance(r, dict)
|
|
505
|
+
and r.get("id") != bifrost_config.BYOK_RULE
|
|
506
|
+
and r.get("name") != bifrost_config.BYOK_RULE
|
|
504
507
|
]
|
|
505
508
|
rules.append(bifrost_config.byok_rule(creds["model_id"]))
|
|
506
509
|
governance["routing_rules"] = rules
|
|
510
|
+
bifrost_config.sanitize_governance(config)
|
|
507
511
|
names = (
|
|
508
512
|
[creds["model_id"]]
|
|
509
513
|
if creds["model_id"] == BYOK_MODEL
|
|
@@ -31,6 +31,7 @@ _REPLY_FIELD: dict[Protocol, str] = {
|
|
|
31
31
|
"anthropic": "content",
|
|
32
32
|
}
|
|
33
33
|
_WINDOW_FIELDS = ("context_length", "context_window", "max_input_tokens")
|
|
34
|
+
_USER_AGENT = "localmodels-byok"
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
class ByokModel(TypedDict):
|
|
@@ -47,7 +48,11 @@ class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
def _headers(protocol: Protocol, api_key: str) -> dict[str, str]:
|
|
50
|
-
headers = {
|
|
51
|
+
headers = {
|
|
52
|
+
"Accept": "application/json",
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"User-Agent": _USER_AGENT,
|
|
55
|
+
}
|
|
51
56
|
if protocol == "anthropic":
|
|
52
57
|
headers["anthropic-version"] = "2023-06-01"
|
|
53
58
|
if api_key:
|
|
@@ -83,7 +83,11 @@ __all__ = [ # this module's API, with the stack_plan names callers reach throug
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def build(
|
|
86
|
-
options: StackOptions,
|
|
86
|
+
options: StackOptions,
|
|
87
|
+
*,
|
|
88
|
+
facts: HostFacts | None = None,
|
|
89
|
+
approved: StackPlan | None = None,
|
|
90
|
+
min_prompt_cache: bool = False,
|
|
87
91
|
) -> StackPlan:
|
|
88
92
|
"""Probe this computer now, or take ``facts`` saved earlier, and compose the plan (read-only
|
|
89
93
|
apart from cached facts). With ``offline`` in the options every file's commit and SHA256 come
|
|
@@ -123,6 +127,10 @@ def build(
|
|
|
123
127
|
plan = compose(
|
|
124
128
|
seen, tools, options, resolver=resolver, approved=approved, previous=_attempted
|
|
125
129
|
)
|
|
130
|
+
elif min_prompt_cache:
|
|
131
|
+
plan = stack_update.with_replaced(
|
|
132
|
+
compose(seen, tools, options, resolver=resolver, min_prompt_cache=True)
|
|
133
|
+
)
|
|
126
134
|
else:
|
|
127
135
|
plan = stack_update.with_replaced(compose(seen, tools, options, resolver=resolver))
|
|
128
136
|
if approved is None and isinstance(plan, dict) and "ram" in raw and "disk" in raw:
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import hashlib
|
|
6
|
-
import json
|
|
7
6
|
import os
|
|
8
7
|
import stat
|
|
9
8
|
import sys
|
|
@@ -140,39 +139,6 @@ def _acceptance_ready(plan: StackPlan) -> bool:
|
|
|
140
139
|
return bool(view and view["ok"])
|
|
141
140
|
|
|
142
141
|
|
|
143
|
-
def _adopted(plan: StackPlan) -> set[str]:
|
|
144
|
-
"""The plan's LLM components the library adopted (``library_convert``): from then on the
|
|
145
|
-
library loads, unloads, wires and may remove them, so their deployments, gateway route and
|
|
146
|
-
pi selection are no longer the stack's to check. The conversion marker names them, and
|
|
147
|
-
stays when ``library remove`` deletes the model's record; a converted record (an earlier
|
|
148
|
-
one may lack ``stack_provider``: the main LLM's) names them too. Read only; it never
|
|
149
|
-
converts."""
|
|
150
|
-
from localmodels import library_convert, library_state, stack_verify
|
|
151
|
-
from localmodels.library_model import library_id
|
|
152
|
-
|
|
153
|
-
try:
|
|
154
|
-
marker = json.loads((library_state.root() / library_convert.MARKER).read_text("utf-8"))
|
|
155
|
-
except (OSError, ValueError):
|
|
156
|
-
return set()
|
|
157
|
-
if not isinstance(marker, dict) or marker.get("plan_id") != plan["plan_id"]:
|
|
158
|
-
return set()
|
|
159
|
-
ids = set(marker.get("adopted") or [])
|
|
160
|
-
providers = {
|
|
161
|
-
r.get("stack_provider") or harness.LLM_PROVIDER
|
|
162
|
-
for r in library_state.records()
|
|
163
|
-
if r.get("converted")
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
component
|
|
167
|
-
for component, part in stack_verify.parts(plan)
|
|
168
|
-
if component in library_convert.STACK_LLMS
|
|
169
|
-
and (
|
|
170
|
-
library_id(part["model"]["id"], part["model"]["quant"]) in ids
|
|
171
|
-
or library_convert.STACK_LLMS[component] in providers
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
142
|
def _deployments_ready(
|
|
177
143
|
plan: StackPlan, owned: hosts.Owned, adopted: frozenset[str] | set[str] = frozenset()
|
|
178
144
|
) -> bool:
|
|
@@ -445,8 +411,10 @@ def inspect_binding(path: Path, lang: Lang = "zh") -> BindingReport:
|
|
|
445
411
|
if not _acceptance_ready(plan):
|
|
446
412
|
report["reasons"] = [_reason("acceptance-unavailable", lang)]
|
|
447
413
|
return report
|
|
414
|
+
from localmodels import library_convert
|
|
415
|
+
|
|
448
416
|
owned = hosts.load_owned(plan["harness"]["tools_dir"])
|
|
449
|
-
adopted =
|
|
417
|
+
adopted = library_convert.adopted_components(plan)
|
|
450
418
|
if not _deployments_ready(plan, owned, adopted):
|
|
451
419
|
report["reasons"] = [_reason("deployment-unavailable", lang)]
|
|
452
420
|
return report
|
|
@@ -272,6 +272,10 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
|
|
|
272
272
|
f"- {name}: the manifest named another directory ({entry['deploy_dir']}); this "
|
|
273
273
|
"installation's record decides where it lives, and that directory is left alone"
|
|
274
274
|
)
|
|
275
|
+
# Keep the other directory's manifest entry untouched on disk; remove acts on this
|
|
276
|
+
# installation's own record in memory only.
|
|
277
|
+
doc["deployments"][name] = hosts.owned_entry(plan)
|
|
278
|
+
continue
|
|
275
279
|
if dry_run:
|
|
276
280
|
doc["deployments"][name] = hosts.owned_entry(plan)
|
|
277
281
|
else:
|
|
@@ -131,6 +131,7 @@ def compose(
|
|
|
131
131
|
owned_ram: Callable[[], int] = suite.slice_memory,
|
|
132
132
|
qa_cpu_decision: bool = False,
|
|
133
133
|
approved: StackPlan | None = None,
|
|
134
|
+
min_prompt_cache: bool = False,
|
|
134
135
|
) -> StackPlan:
|
|
135
136
|
"""The whole-stack plan from facts read now. Pure apart from the Hub lookups in resolver and
|
|
136
137
|
the local lookups each keyword stands for (tests replace them); who holds a GPU comes from
|
|
@@ -171,6 +172,7 @@ def compose(
|
|
|
171
172
|
qa_cpu_decision=qa_cpu_decision,
|
|
172
173
|
approved=approved,
|
|
173
174
|
check_strata=check_strata,
|
|
175
|
+
min_prompt_cache=min_prompt_cache,
|
|
174
176
|
)
|
|
175
177
|
parts["warnings"] = pressure_notes + capped_notes + parts["warnings"]
|
|
176
178
|
if options.get("route") == "fastest":
|
|
@@ -214,6 +216,7 @@ def choose_parts(
|
|
|
214
216
|
qa_cpu_decision: bool = False,
|
|
215
217
|
approved: StackPlan | None = None,
|
|
216
218
|
check_strata: Callable[[Parts, StackOptions], None] | None = None,
|
|
219
|
+
min_prompt_cache: bool = False,
|
|
217
220
|
) -> tuple[Parts, StackOptions]:
|
|
218
221
|
"""The planner's LLM selection and priced parts, shared with read-only upgrade advice.
|
|
219
222
|
|
|
@@ -265,7 +268,9 @@ def choose_parts(
|
|
|
265
268
|
)
|
|
266
269
|
if parts is None:
|
|
267
270
|
reads = (resolver, listening, previous, existing, owned_ram)
|
|
268
|
-
parts = _llama_parts(
|
|
271
|
+
parts = _llama_parts(
|
|
272
|
+
facts, options, *reads, qa_cpu_decision, approved, min_prompt_cache=min_prompt_cache
|
|
273
|
+
)
|
|
269
274
|
parts["warnings"] = passed_over + parts["warnings"]
|
|
270
275
|
return parts, options
|
|
271
276
|
|
|
@@ -440,6 +445,8 @@ def _llama_parts(
|
|
|
440
445
|
owned_ram: Callable[[], int],
|
|
441
446
|
qa_cpu_decision: bool,
|
|
442
447
|
approved: StackPlan | None = None,
|
|
448
|
+
*,
|
|
449
|
+
min_prompt_cache: bool = False,
|
|
443
450
|
) -> Parts:
|
|
444
451
|
"""A catalog llama.cpp LLM, the decision model on its card, the auxiliaries in the RAM left.
|
|
445
452
|
On unified memory the foundations ``--aux`` named are priced first: the LLM, the decision
|
|
@@ -535,6 +542,15 @@ def _llama_parts(
|
|
|
535
542
|
opts = stack_suite.suite_options(options)
|
|
536
543
|
candidates, llm = aux_gpu.place(facts, llm, choice, candidates, opts, price_llm, warnings)
|
|
537
544
|
approved_mib = llm_ram.approved_cache_mib(approved.get("llm") if approved else None, llm)
|
|
545
|
+
ram_posture = posture
|
|
546
|
+
if min_prompt_cache:
|
|
547
|
+
floor = (
|
|
548
|
+
int(str(llm["launch"].get("cache_floor_bytes") or 0)) if hardware.on_metal(llm) else 0
|
|
549
|
+
)
|
|
550
|
+
min_mib = min(
|
|
551
|
+
posture.prompt_cache_mib, -(-floor >> 20) if floor else posture.prompt_cache_min_mib
|
|
552
|
+
)
|
|
553
|
+
ram_posture = replace(posture, prompt_cache_mib=min_mib, prompt_cache_min_mib=min_mib)
|
|
538
554
|
aux, spill = stack_suite.fit_llama_ram(
|
|
539
555
|
facts,
|
|
540
556
|
options,
|
|
@@ -544,7 +560,7 @@ def _llama_parts(
|
|
|
544
560
|
entries,
|
|
545
561
|
(running_llm is not None, held, available),
|
|
546
562
|
warnings,
|
|
547
|
-
posture=
|
|
563
|
+
posture=ram_posture,
|
|
548
564
|
approved_mib=approved_mib,
|
|
549
565
|
)
|
|
550
566
|
return {
|