@simplexai/localmodels-linux-x64 0.1.0-dev.39 → 0.1.0-dev.40

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.
Files changed (49) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +48 -46
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/auth_proxy.py +74 -16
  5. package/modules/localmodels/budget.py +27 -18
  6. package/modules/localmodels/chat_template.py +35 -0
  7. package/modules/localmodels/deploy.py +7 -1
  8. package/modules/localmodels/gateway.py +2 -0
  9. package/modules/localmodels/gateway_bifrost.py +3 -0
  10. package/modules/localmodels/gateway_home.py +132 -0
  11. package/modules/localmodels/harness.py +48 -13
  12. package/modules/localmodels/harness_probe.py +5 -1
  13. package/modules/localmodels/library_gateway.py +13 -2
  14. package/modules/localmodels/library_jobs.py +7 -1
  15. package/modules/localmodels/library_serve.py +5 -0
  16. package/modules/localmodels/metal.py +29 -12
  17. package/modules/localmodels/probe.py +4 -0
  18. package/modules/localmodels/remote_ops_download.py +8 -1
  19. package/modules/localmodels/remote_ops_remove.py +15 -0
  20. package/modules/localmodels/remote_ops_service.py +10 -0
  21. package/modules/localmodels/runtime_cli.py +58 -38
  22. package/modules/localmodels/runtime_discovery.py +38 -10
  23. package/modules/localmodels/runtime_install.py +31 -10
  24. package/modules/localmodels/runtime_io.py +4 -3
  25. package/modules/localmodels/runtime_pi.py +61 -18
  26. package/modules/localmodels/runtime_process.py +4 -2
  27. package/modules/localmodels/service_deployment.py +5 -3
  28. package/modules/localmodels/service_probe.py +84 -27
  29. package/modules/localmodels/setup_inspection.py +104 -25
  30. package/modules/localmodels/setup_text.py +12 -5
  31. package/modules/localmodels/slot_cache.py +467 -0
  32. package/modules/localmodels/stack_binding.py +90 -13
  33. package/modules/localmodels/stack_capacity.py +3 -3
  34. package/modules/localmodels/stack_down.py +22 -7
  35. package/modules/localmodels/stack_events.py +59 -0
  36. package/modules/localmodels/stack_hardware.py +13 -24
  37. package/modules/localmodels/stack_lifecycle.py +12 -3
  38. package/modules/localmodels/stack_rollback.py +9 -4
  39. package/modules/localmodels/stack_up.py +27 -20
  40. package/modules/localmodels/stack_update.py +3 -1
  41. package/modules/localmodels/tools.json +1 -0
  42. package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/METADATA +1 -1
  43. package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/RECORD +45 -43
  44. package/package.json +1 -1
  45. package/tool.json +1 -1
  46. /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/WHEEL +0 -0
  47. /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/entry_points.txt +0 -0
  48. /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/licenses/NOTICE +0 -0
  49. /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev40.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -24,14 +24,31 @@ from localmodels import (
24
24
  stack_review,
25
25
  )
26
26
  from localmodels.contracts import decode
27
+ from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
27
28
  from localmodels.plan_envelope import PlanError
28
29
  from localmodels.probe import HostFacts, Services
29
30
  from localmodels.runtime_cli import inspect_runtimes
30
31
  from localmodels.setup_text import Lang, text
31
- from localmodels.stack_plan import RAM_FLOOR, StackError, StackOptions, StackPlan, platform_error
32
+ from localmodels.stack_plan import (
33
+ RAM_FLOOR,
34
+ StackError,
35
+ StackOptions,
36
+ StackPlan,
37
+ deployments,
38
+ platform_error,
39
+ )
40
+
41
+
42
+ class _ReasonSince014(TypedDict, total=False):
43
+ # Since 0.1.4 (roadmap decision 60), on gpu-memory-required and free-memory-required: the
44
+ # memory free now (measured) and the memory the install needs free (the plan's estimate,
45
+ # with the planner's safety reserve on a GPU), in bytes; gpuIndex names the card.
46
+ gpuIndex: int
47
+ freeBytes: int
48
+ requiredBytes: int
32
49
 
33
50
 
34
- class Reason(TypedDict):
51
+ class Reason(_ReasonSince014):
35
52
  code: str
36
53
  message: str
37
54
 
@@ -77,9 +94,7 @@ class SetupReport(TypedDict):
77
94
  recommendation: str
78
95
 
79
96
 
80
- def _plan_reason(error: PlanError | StackError | harness.HarnessError, lang: Lang) -> Reason:
81
- if isinstance(error, stack_hardware.GpuOwnershipError):
82
- return {"code": "gpu-ownership-unknown", "message": text("gpu-ownership-unknown", lang)}
97
+ def _plan_reason(error: PlanError | StackError | harness.HarnessError) -> Reason:
83
98
  return {"code": "plan-unavailable", "message": str(error)}
84
99
 
85
100
 
@@ -117,19 +132,18 @@ def _stack(
117
132
  try:
118
133
  plan = stack.build(options, facts=facts)
119
134
  except (PlanError, stack.StackError, harness.HarnessError) as exc:
120
- reason = _plan_reason(exc, lang)
135
+ reason = _plan_reason(exc)
136
+ # Consent decides by free VRAM whoever else uses a card (roadmap decision 60), so
137
+ # only a Mac, whose sharing still needs every discovery section, skips the retry.
121
138
  if (
122
139
  not share_gpu
123
140
  and budget.holders(facts)
124
- and (
125
- not budget.unknown_services(facts)
126
- or (not metal.supported(facts) and budget.gpu_conflicts(facts))
127
- )
141
+ and (not budget.unknown_services(facts) or not metal.supported(facts))
128
142
  ):
129
143
  try:
130
144
  stack.build({**options, "share_gpu": True}, facts=facts)
131
145
  except (PlanError, stack.StackError, harness.HarnessError) as shared_exc:
132
- reason = _plan_reason(shared_exc, lang)
146
+ reason = _plan_reason(shared_exc)
133
147
  else:
134
148
  reason = {
135
149
  "code": "gpu-sharing-required",
@@ -163,7 +177,7 @@ def _stack(
163
177
  # refuse, so the stack is not available; the plan shows what it needs.
164
178
  return {
165
179
  "available": False,
166
- "reasons": [_free_memory_reason(facts, roomy, lang)],
180
+ "reasons": _held_reasons(options, facts, roomy, plan, lang),
167
181
  "plan": plan,
168
182
  "basis": "capacity",
169
183
  }
@@ -218,6 +232,70 @@ def _fits_without_other_inference(options: StackOptions, roomy: HostFacts) -> St
218
232
  return None
219
233
 
220
234
 
235
+ def _plans(options: StackOptions, facts: HostFacts) -> bool:
236
+ try:
237
+ stack.build(options, facts=facts)
238
+ except (PlanError, stack.StackError, harness.HarnessError):
239
+ return False
240
+ return True
241
+
242
+
243
+ def _held_reasons(
244
+ options: StackOptions, facts: HostFacts, roomy: HostFacts, plan: StackPlan, lang: Lang
245
+ ) -> list[Reason]:
246
+ """What other programs must release for the capacity ``plan`` to install now: GPU memory
247
+ (``gpu-memory-required``, close programs that use the GPU), RAM (``free-memory-required``)
248
+ or both, each with the memory free now and needed. A resource counts as short when freeing
249
+ only the other one still plans nothing (roadmap decision 60)."""
250
+ gpu_only, ram_only = copy.deepcopy(facts), copy.deepcopy(facts)
251
+ gpu_only["gpus"] = copy.deepcopy(roomy.get("gpus") or [])
252
+ ram_only["ram"] = copy.deepcopy(roomy["ram"])
253
+ gpu_short = gpu_only != facts and not _plans(options, ram_only)
254
+ ram_short = ram_only != facts and not _plans(options, gpu_only)
255
+ if not gpu_short and not ram_short:
256
+ return [_free_memory_reason(facts, roomy, lang)]
257
+ summary = stack_review.summarize(plan, lang)
258
+ gib = budget.gib
259
+ reasons: list[Reason] = []
260
+ if gpu_short:
261
+ live = {g["index"]: g for g in facts.get("gpus") or []}
262
+ for index, vram in _vram_by_card(plan).items():
263
+ card = live.get(index)
264
+ required = vram + AGENT_VRAM_RESERVE_BYTES
265
+ if card is None or card["free_bytes"] >= required:
266
+ continue
267
+ reasons.append(
268
+ {
269
+ "code": "gpu-memory-required",
270
+ "message": text(
271
+ "gpu-memory-required",
272
+ lang,
273
+ index=index,
274
+ free=gib(card["free_bytes"]),
275
+ needed=gib(required),
276
+ ),
277
+ "gpuIndex": index,
278
+ "freeBytes": card["free_bytes"],
279
+ "requiredBytes": required,
280
+ }
281
+ )
282
+ if ram_short or not reasons:
283
+ ram = facts["ram"]["available_bytes"]
284
+ reason = _free_memory_reason(facts, ram_only if gpu_short else roomy, lang)
285
+ reasons.append({**reason, "freeBytes": ram, "requiredBytes": summary["memoryBytes"]})
286
+ return reasons
287
+
288
+
289
+ def _vram_by_card(plan: StackPlan) -> dict[int, int]:
290
+ """GPU memory the plan's deployments reserve on each card; a split one counts on each."""
291
+ found: dict[int, int] = {}
292
+ for part in deployments(plan):
293
+ for gpu in decode(part["placement"].get("gpus") or [], list[stack_review.SelectedGPU]):
294
+ index = gpu["index"]
295
+ found[index] = found.get(index, 0) + int(str(part["launch"].get("vram_bytes") or 0))
296
+ return found
297
+
298
+
221
299
  def _free_memory_reason(facts: HostFacts, roomy: HostFacts, lang: Lang = "zh") -> Reason:
222
300
  """Names the memory other programs hold now: each reading the capacity plan counted as freed."""
223
301
  gib = budget.gib
@@ -246,9 +324,7 @@ def _classify(availability: StackAvailability, facts: HostFacts) -> None:
246
324
  availability["state"], availability["hardwareCapable"] = "blocked-now", True
247
325
  else:
248
326
  availability["state"] = "unavailable"
249
- availability["hardwareCapable"] = (
250
- None if codes & {"facts-unavailable", "gpu-ownership-unknown"} else False
251
- )
327
+ availability["hardwareCapable"] = None if "facts-unavailable" in codes else False
252
328
  plan, summary = availability["plan"], availability.get("summary")
253
329
  if availability.get("basis") != "capacity" or plan is None or summary is None:
254
330
  return
@@ -357,13 +433,15 @@ INSPECT = (
357
433
  )
358
434
  INSPECT_REASONS = (
359
435
  "unsupported-platform · facts-unavailable · plan-unavailable · gpu-sharing-required\n"
360
- "(the last: a plan fits only beside known busy GPUs; ask, then rerun with --share-gpu)\n"
361
- "gpu-ownership-unknown: GPU ownership could not be checked, so sharing is refused. "
362
- "Current free VRAM is in facts.gpus[].free_bytes.\n"
363
- "free-memory-required (stack.state is blocked-now, stack.basis is capacity: the plan fits "
364
- "this computer once other programs release the memory they hold now; stack.memory gives "
365
- "the RAM free and needed). On a Mac whose hardware fits only once another inference app "
366
- "on its GPU is quit, plan-unavailable (blocked-now) names that app instead of the hardware"
436
+ "(the last: a plan fits only beside other GPU work, its owner known or not; ask, then rerun "
437
+ "with --share-gpu, which plans by the free VRAM)\n"
438
+ "gpu-memory-required (stack.state is blocked-now, stack.basis is capacity: other programs "
439
+ "use the GPU memory the plan needs; close them and check again; gpuIndex, freeBytes and "
440
+ "requiredBytes give the card and its free and needed VRAM)\n"
441
+ "free-memory-required (the same for RAM, freeBytes and requiredBytes in RAM; stack.memory "
442
+ "gives the RAM free and needed). On a Mac whose hardware fits only once another inference "
443
+ "app on its GPU is quit, plan-unavailable (blocked-now) names that app instead of the "
444
+ "hardware"
367
445
  )
368
446
  BINDING = (
369
447
  "Read-only handoff check of a stack that `stack apply` installed from --plan: the plan's "
@@ -375,7 +453,8 @@ BINDING = (
375
453
  )
376
454
  BINDING_REASONS = (
377
455
  "plan-invalid · acceptance-unavailable · deployment-unavailable · gateway-ownership\n"
378
- "gateway-unavailable · pi-model-unavailable · pi-config-changed · binding-unavailable"
456
+ "gateway-unavailable · pi-model-unavailable · pi-config-changed · binding-unavailable\n"
457
+ "pi-extensions-unavailable"
379
458
  )
380
459
  REVIEW = (
381
460
  "Read-only: verify the saved plan's digest and project it for the user to approve. The "
@@ -427,8 +506,8 @@ def _inspect_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]
427
506
  inspect.add_argument(
428
507
  "--share-gpu",
429
508
  action="store_true",
430
- help="consent to plan on known busy GPUs with their current free VRAM; nothing is "
431
- "stopped (without it busy GPUs are avoided)",
509
+ help="consent to plan beside other GPU work, its owner known or not, by the current "
510
+ "free VRAM; nothing is stopped (without it such GPUs are avoided)",
432
511
  )
433
512
  stack_hardware.add_arguments(inspect)
434
513
  setup_text.add_argument(inspect)
@@ -36,11 +36,13 @@ MESSAGES: dict[str, tuple[str, str]] = {
36
36
  "Other work is running on the GPUs. If you allow sharing them, the plan uses the GPU "
37
37
  "memory free now; no other process is stopped.",
38
38
  ),
39
- "gpu-ownership-unknown": (
40
- "无法核实哪些程序正在使用 GPU,暂不能安全共用。请确认显卡状态可读取,"
41
- "或先关闭你自己启动的 GPU 任务再重新检查。",
42
- "The installer could not verify what is using the GPU, so it cannot share it. "
43
- "Check that GPU status is readable, or close your own GPU workloads and inspect again.",
39
+ "gpu-memory-required": (
40
+ "这台电脑的显卡可以运行本地模型,但其他程序目前占用了 GPU {index} 的显存"
41
+ "(空闲 {free},安装约需 {needed})。请关闭正在使用显卡的程序(游戏、视频、其他 AI 应用)"
42
+ "后重新检查;本工具不会停止任何进程。",
43
+ "This computer's GPU can run local models, but other programs are using GPU {index}'s "
44
+ "memory ({free} free; the install needs about {needed}). Close programs that use the "
45
+ "GPU (games, video, other AI apps) and check again; this tool stops no process.",
44
46
  ),
45
47
  "free-memory-required": (
46
48
  "这台电脑的硬件可以运行本地模型,但其他程序目前占用了所需的内存(当前 {held})。"
@@ -92,6 +94,11 @@ MESSAGES: dict[str, tuple[str, str]] = {
92
94
  "检查期间 Pi 配置发生变化,请重新检查。",
93
95
  "Pi's configuration changed during the check. Check again.",
94
96
  ),
97
+ "pi-extensions-unavailable": (
98
+ "Pi 无法加载扩展(0.1.0.dev39 之前安装的 Pi 缺少依赖),请重新运行 stack apply。",
99
+ "Pi cannot load extensions (a Pi installed before 0.1.0.dev39 lacks its dependencies). "
100
+ "Run stack apply again to replace it.",
101
+ ),
95
102
  "binding-unavailable": (
96
103
  "Pi 配置或本机状态无法安全读取,请恢复已有安装后重试。",
97
104
  "Pi's configuration or this computer's state cannot be read safely. Restore the "