@simplexai/localmodels-darwin-x64 0.1.0-dev.103 → 0.1.0-dev.105

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 (172) hide show
  1. package/LICENSE +201 -0
  2. package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
  3. package/README.md +10 -0
  4. package/bootstrap.identity +1 -1
  5. package/bootstrap.sha256 +159 -158
  6. package/modules/localmodels/__init__.py +1 -1
  7. package/modules/localmodels/__main__.py +204 -86
  8. package/modules/localmodels/apple_sensors.py +23 -0
  9. package/modules/localmodels/approval.py +25 -2
  10. package/modules/localmodels/catalog.json +584 -158
  11. package/modules/localmodels/catalog.py +18 -3
  12. package/modules/localmodels/catalog_recipes.py +64 -6
  13. package/modules/localmodels/cli_help.py +10 -0
  14. package/modules/localmodels/cli_parser.py +313 -230
  15. package/modules/localmodels/component.py +21 -3
  16. package/modules/localmodels/console.py +1 -1
  17. package/modules/localmodels/context_policy.py +6 -5
  18. package/modules/localmodels/custom_probe.py +4 -2
  19. package/modules/localmodels/debug_cli.py +0 -12
  20. package/modules/localmodels/debug_mode.py +0 -6
  21. package/modules/localmodels/decode_calibration.json +3 -4
  22. package/modules/localmodels/decode_calibration.py +5 -2
  23. package/modules/localmodels/deploy.py +11 -1
  24. package/modules/localmodels/deployment_lifecycle.py +1 -1
  25. package/modules/localmodels/download-mirrors.json +1 -1
  26. package/modules/localmodels/engine_adapters/base.py +11 -1
  27. package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
  28. package/modules/localmodels/engine_adapters/suite_plan.py +61 -24
  29. package/modules/localmodels/engines-b11583.json +6 -26
  30. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
  31. package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
  32. package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
  33. package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
  34. package/modules/localmodels/engines-strata-0.1.47.json +1 -5
  35. package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
  36. package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
  37. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
  38. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
  39. package/modules/localmodels/engines-whisper-b5454.json +6 -30
  40. package/modules/localmodels/engines.json +13 -61
  41. package/modules/localmodels/estimator.py +10 -5
  42. package/modules/localmodels/gpu_specs.py +1 -1
  43. package/modules/localmodels/host_sensors.py +25 -2
  44. package/modules/localmodels/hosts.py +38 -21
  45. package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
  46. package/modules/localmodels/library_cli.py +34 -16
  47. package/modules/localmodels/library_custom.py +9 -1
  48. package/modules/localmodels/library_direct.py +41 -1
  49. package/modules/localmodels/library_elastic.py +135 -6
  50. package/modules/localmodels/library_jobs.py +23 -4
  51. package/modules/localmodels/library_kept.py +9 -1
  52. package/modules/localmodels/library_model.py +174 -2
  53. package/modules/localmodels/library_order.py +175 -69
  54. package/modules/localmodels/library_poly.py +150 -21
  55. package/modules/localmodels/library_presentation.py +485 -0
  56. package/modules/localmodels/library_pricing.py +15 -4
  57. package/modules/localmodels/library_serve.py +342 -70
  58. package/modules/localmodels/library_smoke.py +63 -5
  59. package/modules/localmodels/library_state.py +48 -10
  60. package/modules/localmodels/library_status.py +37 -17
  61. package/modules/localmodels/llm_rank.py +22 -11
  62. package/modules/localmodels/metal.py +1 -2
  63. package/modules/localmodels/plan_envelope.py +40 -13
  64. package/modules/localmodels/planning/budget.py +14 -12
  65. package/modules/localmodels/planning/memory_pools.py +7 -1
  66. package/modules/localmodels/privacy_acceptance.py +6 -5
  67. package/modules/localmodels/probe.py +34 -7
  68. package/modules/localmodels/py.typed +0 -0
  69. package/modules/localmodels/quant_formats.py +10 -3
  70. package/modules/localmodels/recommend_cli.py +1 -1
  71. package/modules/localmodels/records.py +19 -2
  72. package/modules/localmodels/remote_ops_launchd.py +8 -1
  73. package/modules/localmodels/remote_ops_verify.py +91 -24
  74. package/modules/localmodels/runtime_index.py +303 -0
  75. package/modules/localmodels/runtime_process.py +1 -1
  76. package/modules/localmodels/service_deployment.py +2 -4
  77. package/modules/localmodels/service_probe.py +59 -13
  78. package/modules/localmodels/setup_inspection.py +94 -73
  79. package/modules/localmodels/setup_text.py +7 -56
  80. package/modules/localmodels/sidecar_downloads.py +34 -0
  81. package/modules/localmodels/sidecar_http.py +61 -5
  82. package/modules/localmodels/sidecar_state.py +52 -2
  83. package/modules/localmodels/speech_admission.py +20 -4
  84. package/modules/localmodels/speech_catalog.py +23 -0
  85. package/modules/localmodels/speech_cli.py +30 -16
  86. package/modules/localmodels/speech_jobs.py +42 -17
  87. package/modules/localmodels/speech_serve.py +9 -2
  88. package/modules/localmodels/speech_server.py +185 -81
  89. package/modules/localmodels/speech_state.py +4 -1
  90. package/modules/localmodels/speech_workers.py +11 -0
  91. package/modules/localmodels/stack.py +1 -1
  92. package/modules/localmodels/stack_args.py +276 -145
  93. package/modules/localmodels/stack_auto.py +91 -6
  94. package/modules/localmodels/stack_aux_gpu.py +1 -1
  95. package/modules/localmodels/stack_cleanup.py +21 -18
  96. package/modules/localmodels/stack_cli.py +120 -115
  97. package/modules/localmodels/stack_compose.py +16 -5
  98. package/modules/localmodels/stack_debug.py +15 -6
  99. package/modules/localmodels/stack_decision.py +4 -4
  100. package/modules/localmodels/stack_doctor.py +2 -2
  101. package/modules/localmodels/stack_down.py +2 -0
  102. package/modules/localmodels/stack_events.py +1 -1
  103. package/modules/localmodels/stack_gpu_memory.py +1 -1
  104. package/modules/localmodels/stack_hardware.py +17 -15
  105. package/modules/localmodels/stack_mcp.py +1 -2
  106. package/modules/localmodels/stack_mlx.py +8 -1
  107. package/modules/localmodels/stack_picks.py +20 -21
  108. package/modules/localmodels/stack_plan.py +12 -11
  109. package/modules/localmodels/stack_ports.py +31 -4
  110. package/modules/localmodels/stack_review.py +28 -7
  111. package/modules/localmodels/stack_rollback.py +1 -1
  112. package/modules/localmodels/stack_run.py +1 -1
  113. package/modules/localmodels/stack_suite.py +72 -21
  114. package/modules/localmodels/stack_up.py +2 -0
  115. package/modules/localmodels/stack_view.py +180 -35
  116. package/modules/localmodels/stack_view_agent.py +1 -1
  117. package/modules/localmodels/stack_view_demo.py +2 -0
  118. package/modules/localmodels/stack_view_gpu.py +36 -2
  119. package/modules/localmodels/stack_view_schema.py +26 -3
  120. package/modules/localmodels/stack_view_serve.py +0 -2
  121. package/modules/localmodels/stack_view_slots.py +3 -1
  122. package/modules/localmodels/stack_view_telemetry.py +90 -4
  123. package/modules/localmodels/stack_view_tick.py +246 -40
  124. package/modules/localmodels/stack_view_words.py +9 -2
  125. package/modules/localmodels/stack_warm.py +2 -2
  126. package/modules/localmodels/stack_whatif.py +524 -41
  127. package/modules/localmodels/stack_whatif_html.py +900 -0
  128. package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
  129. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
  130. package/modules/localmodels/strata_poly_server.py +114 -3
  131. package/modules/localmodels/suite.py +265 -6
  132. package/modules/localmodels/telemetry_math.py +458 -18
  133. package/modules/localmodels/transport.py +8 -1
  134. package/modules/localmodels/tts_admission.py +2 -17
  135. package/modules/localmodels/tts_catalog.py +29 -1
  136. package/modules/localmodels/tts_cli.py +45 -22
  137. package/modules/localmodels/tts_http.py +10 -4
  138. package/modules/localmodels/tts_jobs.py +49 -19
  139. package/modules/localmodels/tts_serve.py +9 -2
  140. package/modules/localmodels/tts_server.py +1 -1
  141. package/modules/localmodels/tts_sidecar.py +69 -28
  142. package/modules/localmodels/tts_state.py +7 -2
  143. package/modules/localmodels/vision.py +5 -3
  144. package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
  145. package/modules/localmodels/web/view/view.css +0 -1
  146. package/modules/localmodels/web/view/view.js +2 -5
  147. package/modules/localmodels/web/whatif/app.js +730 -0
  148. package/modules/localmodels/web/whatif/page.html +1172 -0
  149. package/modules/localmodels/web/whatif/sim.js +297 -0
  150. package/modules/localmodels/win_probe.py +89 -16
  151. package/modules/localmodels/windows_job.py +179 -11
  152. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/METADATA +14 -0
  153. package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +151 -145
  154. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/LICENSE +201 -0
  155. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/NOTICE +126 -0
  156. package/package.json +11 -2
  157. package/tool.json +1 -1
  158. package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
  159. package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
  160. package/modules/localmodels/stack_research.py +0 -716
  161. package/modules/localmodels/stack_research_demo.py +0 -125
  162. package/modules/localmodels/stack_research_plan.py +0 -146
  163. package/modules/localmodels/web/index.html +0 -2605
  164. package/modules/localmodels/web/sizecalc/app.js +0 -1306
  165. package/modules/localmodels/web/sizecalc/calc.js +0 -269
  166. package/modules/localmodels/web/sizecalc/page.html +0 -520
  167. package/modules/localmodels/web/view/logo-claude.svg +0 -3
  168. package/modules/localmodels/web/view/logo-codex.png +0 -0
  169. package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
  170. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
  171. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
  172. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -8,13 +8,17 @@ import json
8
8
  import re
9
9
  import sys
10
10
  from pathlib import Path
11
- from typing import Literal, TypedDict
11
+ from typing import TYPE_CHECKING, Literal, TypedDict
12
+
13
+ if TYPE_CHECKING:
14
+ from localmodels.library_model import Status as LibraryStatus
12
15
 
13
16
  from localmodels import (
14
17
  app,
15
18
  cli_help,
16
19
  deploy,
17
20
  metal,
21
+ plan_envelope,
18
22
  probe,
19
23
  service_probe,
20
24
  setup_capacity,
@@ -65,7 +69,11 @@ class StackAvailability(_Basis):
65
69
  plan: StackPlan | None
66
70
 
67
71
 
68
- class SetupReport(TypedDict):
72
+ class _SetupReportOptional(TypedDict, total=False):
73
+ library: LibraryStatus
74
+
75
+
76
+ class SetupReport(_SetupReportOptional):
69
77
  schema: str
70
78
  facts: HostFacts
71
79
  stack: StackAvailability
@@ -80,6 +88,24 @@ def _plan_reason(error: PlanError | StackError) -> Reason:
80
88
  return {"code": "plan-unavailable", "message": str(error)}
81
89
 
82
90
 
91
+ PortCode = Literal["port-check-failed", "ports-in-use"]
92
+
93
+
94
+ def _port_code(error: BaseException) -> PortCode | None:
95
+ """``port-check-failed`` when no port of a range could be confirmed free
96
+ (stack_ports.PortProbeError), ``ports-in-use`` when every one is in use (PORTS_IN_USE)."""
97
+ if isinstance(error, stack_ports.PortProbeError):
98
+ return "port-check-failed"
99
+ return "ports-in-use" if stack_ports.ports_in_use(error) else None
100
+
101
+
102
+ def _unless_ports(error: PlanError | StackError) -> None:
103
+ """A refusal for ports says nothing about the hardware: it leaves pricing to _plan_stack,
104
+ which prices again with every port taken as free."""
105
+ if _port_code(error) is not None:
106
+ raise error
107
+
108
+
83
109
  def _cuda_driver_reason(error: CudaDriverError, lang: Lang) -> Reason:
84
110
  detected = error.detected_cuda if _VERSION_RE.fullmatch(error.detected_cuda) else ""
85
111
  required = error.required_cuda if _VERSION_RE.fullmatch(error.required_cuda) else ""
@@ -117,7 +143,8 @@ def _cuda_driver_reason(error: CudaDriverError, lang: Lang) -> Reason:
117
143
  def _plans_hardware(options: StackOptions, facts: HostFacts) -> bool:
118
144
  try:
119
145
  stack.build(options, facts=facts)
120
- except (PlanError, stack.StackError):
146
+ except (PlanError, stack.StackError) as exc:
147
+ _unless_ports(exc)
121
148
  return False
122
149
  return True
123
150
 
@@ -163,6 +190,7 @@ def _other_inference_availability(
163
190
  try:
164
191
  plan = stack.build(options, facts=alone_facts, min_prompt_cache=True)
165
192
  except (PlanError, stack.StackError) as alone_exc:
193
+ _unless_ports(alone_exc)
166
194
  return _driver_block(alone_exc, options, alone_facts, lang)
167
195
  if metal.supported(facts):
168
196
  reasons: list[Reason] = [
@@ -192,6 +220,7 @@ def _capacity_availability(
192
220
  try:
193
221
  plan = stack.build(options, facts=roomy, min_prompt_cache=True)
194
222
  except (PlanError, stack.StackError) as roomy_exc:
223
+ _unless_ports(roomy_exc)
195
224
  if blocked := _driver_block(roomy_exc, options, roomy, lang):
196
225
  return blocked
197
226
  else:
@@ -204,79 +233,51 @@ def _capacity_availability(
204
233
  return _other_inference_availability(options, facts, roomy, lang)
205
234
 
206
235
 
207
- def _fits_without_ports(options: StackOptions, facts: HostFacts) -> bool:
208
- """Whether ``facts`` fits a stack once loopback ports can be probed."""
209
- resolver = deploy.catalog_pins if options.get("offline") else deploy.resolve_files
210
-
211
- def once(opts: StackOptions, seen: HostFacts) -> bool:
212
- try:
213
- stack.compose(
214
- seen,
215
- opts,
216
- resolver=resolver,
217
- listening=lambda _port: False,
218
- previous=lambda _name, _port: None,
219
- existing=lambda _recipes: [],
220
- copies=lambda _wanted: {},
221
- owned_ram=lambda: 0,
222
- )
223
- except (PlanError, stack.StackError):
224
- return False
225
- return True
226
-
227
- if once(options, facts):
228
- return True
229
- if (
230
- not options.get("share_gpu")
231
- and budget.holders(facts)
232
- and (not budget.unknown_services(facts) or not metal.supported(facts))
233
- and once({**options, "share_gpu": True}, facts)
234
- ):
235
- return True
236
- roomy = _capacity_facts(facts)
237
- if roomy is not None and once(options, roomy):
238
- return True
239
- if (alone := setup_capacity.without_other_inference(roomy or facts)) is not None:
240
- return once(options, alone)
241
- return False
242
-
243
-
244
- def _port_check_availability(
245
- options: StackOptions, facts: HostFacts, exc: StackError, lang: Lang
246
- ) -> StackAvailability:
247
- """No port of a range could be confirmed free (stack_ports.PortProbeError): blocked now and
248
- retryable, never a reason to recommend another runtime when the hardware fits."""
249
- capable = _fits_without_ports(options, facts)
250
- return {
251
- "available": False,
252
- "reasons": [
253
- {
254
- "code": "port-check-failed",
255
- "message": text("port-check-failed", lang, detail=str(exc))
256
- if capable
257
- else str(exc),
258
- }
259
- ],
260
- "plan": None,
261
- "hardwareCapable": capable,
262
- }
263
-
264
-
265
236
  def _plan_stack(
266
237
  options: StackOptions,
267
238
  facts: HostFacts,
268
239
  share_gpu: bool,
269
240
  lang: Lang,
241
+ ) -> StackAvailability:
242
+ """Price the stack. A refusal for loopback ports anywhere on the way says nothing about the
243
+ hardware, so the stack is priced again as if every port were free: a host that would then be
244
+ ready is blocked now by its ports alone (``port-check-failed`` / ``ports-in-use``, retryable,
245
+ hardwareCapable true); one blocked now for something else gets the port reason after its own;
246
+ one that cannot run local models keeps its own reason. Busy ports never make
247
+ hardwareCapable false."""
248
+ try:
249
+ return _priced(options, facts, share_gpu, lang)
250
+ except (PlanError, stack.StackError) as exc:
251
+ if (code := _port_code(exc)) is None:
252
+ raise
253
+ refused = exc
254
+ with plan_envelope.assume_ports_free():
255
+ try:
256
+ freed = _priced(options, facts, share_gpu, lang)
257
+ except (PlanError, stack.StackError) as exc:
258
+ return {"available": False, "reasons": [_plan_reason(exc)], "plan": None}
259
+ reason: Reason = {"code": code, "message": text(code, lang, detail=str(refused))}
260
+ if freed["available"]:
261
+ return {"available": False, "reasons": [reason], "plan": None, "hardwareCapable": True}
262
+ if _capable_now(freed):
263
+ return {**freed, "reasons": [*freed["reasons"], reason]}
264
+ return freed
265
+
266
+
267
+ def _priced(
268
+ options: StackOptions,
269
+ facts: HostFacts,
270
+ share_gpu: bool,
271
+ lang: Lang,
270
272
  ) -> StackAvailability:
271
273
  try:
272
274
  plan = stack.build(options, facts=facts)
273
- except stack_ports.PortProbeError as exc:
274
- return _port_check_availability(options, facts, exc, lang)
275
275
  except (PlanError, stack.StackError) as exc:
276
+ _unless_ports(exc)
276
277
  last_error: PlanError | StackError | None = exc
277
278
  last_options = options
278
279
  reason = _plan_reason(exc)
279
- # Consent decides by free VRAM whoever else uses a card (roadmap decision 60), so
280
+ # Consent decides by free VRAM whoever else uses a card, so
280
281
  # only a Mac, whose sharing still needs every discovery section, skips the retry.
281
282
  if (
282
283
  not share_gpu
@@ -287,6 +288,7 @@ def _plan_stack(
287
288
  try:
288
289
  stack.build(shared_options, facts=facts)
289
290
  except (PlanError, stack.StackError) as shared_exc:
291
+ _unless_ports(shared_exc)
290
292
  last_error, last_options = shared_exc, shared_options
291
293
  reason = _plan_reason(shared_exc)
292
294
  else:
@@ -340,7 +342,8 @@ def _stack(
340
342
  def _plans(options: StackOptions, facts: HostFacts) -> bool:
341
343
  try:
342
344
  stack.build(options, facts=facts)
343
- except (PlanError, stack.StackError):
345
+ except (PlanError, stack.StackError) as exc:
346
+ _unless_ports(exc)
344
347
  return False
345
348
  return True
346
349
 
@@ -408,16 +411,22 @@ def _free_memory_reason(facts: HostFacts, roomy: HostFacts, lang: Lang = "zh") -
408
411
  }
409
412
 
410
413
 
411
- def _classify(availability: StackAvailability, facts: HostFacts) -> None:
414
+ def _capable_now(availability: StackAvailability) -> bool:
415
+ """Refused now, but the hardware can run local models once what the reasons name changes."""
412
416
  codes = {reason["code"] for reason in availability["reasons"]}
413
- if availability["available"]:
414
- availability["state"], availability["hardwareCapable"] = "ready", True
415
- elif (
417
+ return (
416
418
  availability.get("basis") == "capacity"
417
419
  or "gpu-sharing-required" in codes
418
420
  or bool(codes & _DRIVER_REASON_CODES)
419
- or ("port-check-failed" in codes and availability.get("hardwareCapable") is True)
420
- ):
421
+ or availability.get("hardwareCapable") is True
422
+ )
423
+
424
+
425
+ def _classify(availability: StackAvailability, facts: HostFacts) -> None:
426
+ codes = {reason["code"] for reason in availability["reasons"]}
427
+ if availability["available"]:
428
+ availability["state"], availability["hardwareCapable"] = "ready", True
429
+ elif _capable_now(availability):
421
430
  availability["state"], availability["hardwareCapable"] = "blocked-now", True
422
431
  else:
423
432
  availability["state"] = "unavailable"
@@ -462,6 +471,7 @@ def inspect_setup(
462
471
  share_gpu: bool = False,
463
472
  unified_memory: str | None = None,
464
473
  lang: Lang = "zh",
474
+ include_models: bool = False,
465
475
  ) -> SetupReport:
466
476
  """Inspect hardware and local-model eligibility without probing external harnesses,
467
477
  caching facts, saving plans, downloading models, or starting services."""
@@ -492,11 +502,16 @@ def inspect_setup(
492
502
  facts = stack_hardware.assumed(facts, unified_memory)
493
503
  except StackError:
494
504
  pass
495
- return {
505
+ report: SetupReport = {
496
506
  "schema": "localmodels.setup-report/v1",
497
507
  "facts": facts,
498
508
  "stack": availability,
499
509
  }
510
+ if include_models:
511
+ from localmodels import library_status
512
+
513
+ report["library"] = library_status.build(library_status.Library.read(facts, str(base)))
514
+ return report
500
515
 
501
516
 
502
517
  def _absolute(value: str) -> Path:
@@ -522,7 +537,7 @@ INSPECT = (
522
537
  INSPECT_REASONS = (
523
538
  "unsupported-platform · facts-unavailable · plan-unavailable · gpu-sharing-required\n"
524
539
  "cuda-driver-update-required · cuda-driver-version-unknown · port-check-failed · "
525
- "gpu-memory-required · free-memory-required"
540
+ "ports-in-use · gpu-memory-required · free-memory-required"
526
541
  )
527
542
  REVIEW = (
528
543
  "Read-only: verify the saved plan's digest and project it for the user to approve. The "
@@ -573,6 +588,11 @@ def _inspect_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]
573
588
  )
574
589
  stack_hardware.add_arguments(inspect)
575
590
  setup_text.add_argument(inspect)
591
+ inspect.add_argument(
592
+ "--include-models",
593
+ action="store_true",
594
+ help="also include localmodels.library-status/v1 under `library` using the same hardware probe",
595
+ )
576
596
  inspect.add_argument(
577
597
  "--json", action="store_true", help="accepted for installers; the report is JSON either way"
578
598
  )
@@ -652,6 +672,7 @@ def cli(args: argparse.Namespace) -> int:
652
672
  share_gpu=getattr(args, "share_gpu", False),
653
673
  unified_memory=getattr(args, "unified_memory", None),
654
674
  lang=getattr(args, "lang", "zh"),
675
+ include_models=bool(getattr(args, "include_models", False)),
655
676
  )
656
677
  )
657
678
  json.dump(report, sys.stdout, ensure_ascii=False, indent=1)
@@ -1,4 +1,4 @@
1
- """The messages ``setup inspect``, ``review`` and ``binding`` show a user, in Chinese and English.
1
+ """The messages ``setup inspect`` and ``review`` show a user, in Chinese and English.
2
2
 
3
3
  Chinese stays the default: it is what installers built before ``--lang`` show. Reason codes and
4
4
  every other field are the same in both languages, so a caller may also show its own text per
@@ -100,67 +100,18 @@ MESSAGES: dict[str, tuple[str, str]] = {
100
100
  "(requires CUDA {required} or newer). Update or reinstall the NVIDIA driver and check "
101
101
  "again.",
102
102
  ),
103
- "gateway-port-in-use": (
104
- "这台电脑的硬件可以运行本地模型,但网关端口当前被其他程序占用({detail})。"
105
- "请停止占用该端口的程序,或设置其他网关地址后重新检查。",
106
- "This computer's hardware can run local models, but the gateway port is currently in use "
107
- "({detail}). Stop that program or set another gateway address, then check again.",
108
- ),
109
103
  "port-check-failed": (
110
104
  "这台电脑的硬件可以运行本地模型,但暂时无法确认本地端口是否空闲({detail})。"
111
105
  "请稍后重新检查。",
112
106
  "This computer's hardware can run local models, but whether a local port is free could "
113
107
  "not be confirmed right now ({detail}). Check again in a moment.",
114
108
  ),
115
- "harness-unavailable": (
116
- "这台电脑的硬件可以运行本地模型,但网关或工具环境检查未通过({detail})。"
117
- "请先处理该问题后重新检查。",
118
- "This computer's hardware can run local models, but gateway or tool preparation is "
119
- "currently blocked ({detail}). Resolve this issue and check again.",
120
- ),
121
- "plan-invalid": (
122
- "批准计划不存在、无效或摘要不一致。",
123
- "The approved plan is missing or invalid, or its digest does not match.",
124
- ),
125
- "acceptance-unavailable": (
126
- "批准计划缺少完整成功的套件验收记录,请完成已有安装的验收后重试。",
127
- "The approved plan has no complete, successful stack acceptance record. Finish "
128
- "accepting the existing install and try again.",
129
- ),
130
- "deployment-unavailable": (
131
- "计划中的部署尚未全部就绪,或当前记录与归属不一致。",
132
- "Not every deployment in the plan is ready yet, or the current records do not match "
133
- "their ownership.",
134
- ),
135
- "gateway-ownership": (
136
- "网关或 Pi 的归属与批准计划不一致。",
137
- "The gateway or Pi is not the one the approved plan set up.",
138
- ),
139
- "gateway-record": (
140
- "网关归属与批准计划不一致。",
141
- "The gateway is not the one the approved plan set up.",
142
- ),
143
- "gateway-unavailable": (
144
- "计划中的网关或 Pi 默认模型当前不可用。",
145
- "The plan's gateway or Pi's default model is not available now.",
146
- ),
147
- "pi-model-unavailable": (
148
- "Pi 当前没有列出计划中的网关模型。",
149
- "Pi does not list the plan's gateway model now.",
150
- ),
151
- "pi-config-changed": (
152
- "检查期间 Pi 配置发生变化,请重新检查。",
153
- "Pi's configuration changed during the check. Check again.",
154
- ),
155
- "pi-extensions-unavailable": (
156
- "Pi 无法加载扩展(0.1.0.dev39 之前安装的 Pi 缺少依赖),请重新运行 stack apply。",
157
- "Pi cannot load extensions (a Pi installed before 0.1.0.dev39 lacks its dependencies). "
158
- "Run stack apply again to replace it.",
159
- ),
160
- "binding-unavailable": (
161
- "无法安全验证 Pi 配置或本机状态,请检查本地模型安装,或先改用其他 AI 运行时。",
162
- "Pi's configuration or this computer's state could not be verified safely. Check the "
163
- "local model installation or choose another AI runtime.",
109
+ "ports-in-use": (
110
+ "这台电脑的硬件可以运行本地模型,但本地模型需要的本地端口都已被其他程序占用({detail})。"
111
+ "请关闭占用这些端口的程序后重新检查。",
112
+ "This computer's hardware can run local models, but every local port the local models "
113
+ "can use is held by other programs ({detail}). Close the programs that hold them, then "
114
+ "check again.",
164
115
  ),
165
116
  # The plan summary: the model, where it runs and what it needs.
166
117
  "summary": (
@@ -25,6 +25,8 @@ from localmodels import (
25
25
  region,
26
26
  remote_ops_download,
27
27
  reuse,
28
+ speech_catalog,
29
+ tts_catalog,
28
30
  )
29
31
  from localmodels.records import ReleaseEngine, ReusableFile
30
32
  from localmodels.remote_ops import DownloadParams, EngineParams, Reusable
@@ -379,6 +381,29 @@ def run_fetch(
379
381
  emit_fn(model_id, "verify", tracker.total, tracker.total, 0, handle.job["source"], 0)
380
382
 
381
383
 
384
+ def _legacy_job_uses_engine(store: SidecarStore, job: SidecarJob, target: str) -> bool:
385
+ """Fallback for pre-fix live job files that do not persist ``engine_dir``."""
386
+ if "engine_dir" in job or not job.get("base_dir"):
387
+ return False
388
+ engine_tag: str | None = None
389
+ try:
390
+ if store.namespace == "speech":
391
+ engine_tag = speech_catalog.speech_model(job["model"]).engine_tag
392
+ elif store.namespace == "tts":
393
+ engine_tag = tts_catalog.tts_model(job["model"]).engine_tag
394
+ except KeyError:
395
+ return False
396
+ if not engine_tag:
397
+ return False
398
+ engines_root = Path(
399
+ os.path.realpath(os.path.join(os.path.expanduser(job["base_dir"]), "engines"))
400
+ )
401
+ target_path = Path(target)
402
+ return target_path.parent == engines_root and (
403
+ target_path.name == engine_tag or target_path.name.startswith(f"{engine_tag}-")
404
+ )
405
+
406
+
382
407
  def engine_in_use_elsewhere(
383
408
  store: SidecarStore,
384
409
  engine_dir: str,
@@ -392,6 +417,15 @@ def engine_in_use_elsewhere(
392
417
  other = rec.get("engine_dir")
393
418
  if other and os.path.realpath(os.path.expanduser(other)) == target:
394
419
  return True
420
+ for job, alive in store.jobs(state_dir).values():
421
+ if not alive or job["model"] == skip_model_id:
422
+ continue
423
+ other = job.get("engine_dir")
424
+ if other:
425
+ if os.path.realpath(os.path.expanduser(other)) == target:
426
+ return True
427
+ elif _legacy_job_uses_engine(store, job, target):
428
+ return True
395
429
  for owned in hosts.load_owned()["deployments"].values():
396
430
  if deployment_lifecycle.holds_service(owned):
397
431
  for path in owned.get("files") or ():
@@ -24,10 +24,12 @@ from collections.abc import Mapping
24
24
  from http import HTTPStatus
25
25
  from http.server import BaseHTTPRequestHandler
26
26
  from pathlib import Path
27
- from typing import Any, Literal
27
+ from typing import Any, Literal, TypeVar
28
28
 
29
29
  from localmodels import http_local, windows_job
30
30
 
31
+ _RowT = TypeVar("_RowT", bound=Mapping[str, Any])
32
+
31
33
  RequestedDevice = Literal["gpu", "cpu"]
32
34
  REQUESTED_DEVICES: tuple[RequestedDevice, ...] = ("gpu", "cpu")
33
35
 
@@ -40,7 +42,10 @@ LoadStep = Literal["prepare", "start", "load", "warm"]
40
42
  WORKER_STOP_GRACE_S = 3.0
41
43
  WORKER_READY_TIMEOUT_S = 60.0
42
44
  WINDOWS_CREATE_NO_WINDOW = 0x08000000
45
+ WINDOWS_ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000
43
46
  DETAIL_LIMIT = 500
47
+ VOICE_INCLUDE_GPU_ENV = "LOCALMODELS_VOICE_INCLUDE_GPU"
48
+ _TRUTHY_ENV: frozenset[str] = frozenset(("1", "true", "yes", "on"))
44
49
 
45
50
  _POSIX_WATCHDOG_SH = (
46
51
  'read _; kill -TERM "$0" 2>/dev/null; n=0; '
@@ -237,13 +242,18 @@ def sidecar_request(
237
242
  class ChildWatchdog:
238
243
  """Binds a child worker's lifetime to this sidecar via POSIX pipe guard or Windows Job."""
239
244
 
240
- def __init__(self, proc: subprocess.Popen[bytes]) -> None:
245
+ def __init__(
246
+ self,
247
+ proc: subprocess.Popen[bytes],
248
+ *,
249
+ affinity_mask: int | None = None,
250
+ ) -> None:
241
251
  self._guard: subprocess.Popen[bytes] | None = None
242
252
  self._write_fd: int | None = None
243
253
  if sys.platform == "win32":
244
254
  handle = getattr(proc, "_handle", None)
245
255
  if isinstance(handle, int):
246
- windows_job.end_with_this_process(handle)
256
+ windows_job.end_with_this_process(handle, affinity_mask=affinity_mask)
247
257
  return
248
258
  if os.name == "posix":
249
259
  read_fd, write_fd = os.pipe()
@@ -346,11 +356,16 @@ def launch_worker_subprocess(
346
356
  *,
347
357
  ready_paths: tuple[str, ...] = ("/health",),
348
358
  timeout_s: float = WORKER_READY_TIMEOUT_S,
359
+ above_normal_priority: bool = False,
360
+ affinity_mask: int | None = None,
349
361
  ) -> tuple[subprocess.Popen[bytes], ChildWatchdog]:
350
362
  """Spawn, watchdog-bind, and health-check a loopback sidecar child worker."""
351
363
  kwargs: dict[str, Any] = {"cwd": str(run_cwd), "env": env}
352
364
  if sys.platform == "win32":
353
- kwargs["creationflags"] = WINDOWS_CREATE_NO_WINDOW
365
+ flags = WINDOWS_CREATE_NO_WINDOW
366
+ if above_normal_priority:
367
+ flags |= WINDOWS_ABOVE_NORMAL_PRIORITY_CLASS
368
+ kwargs["creationflags"] = flags
354
369
  with stderr_path.open("wb") as err_stream:
355
370
  try:
356
371
  proc = subprocess.Popen(
@@ -362,7 +377,7 @@ def launch_worker_subprocess(
362
377
  )
363
378
  except OSError as exc:
364
379
  raise SidecarWorkerError(f"failed to launch {engine} worker: {exc}") from None
365
- watchdog = ChildWatchdog(proc)
380
+ watchdog = ChildWatchdog(proc, affinity_mask=affinity_mask)
366
381
  try:
367
382
  wait_worker_ready(proc, port, engine, stderr_path, timeout_s=timeout_s, paths=ready_paths)
368
383
  except Exception:
@@ -394,3 +409,44 @@ def idle_remaining_seconds(
394
409
  if active_sessions > 0:
395
410
  return ttl
396
411
  return max(0, int(math.ceil(ttl - max(0.0, now - last_used))))
412
+
413
+
414
+ def should_sweep_worker(
415
+ worker_alive: bool,
416
+ ttl: int,
417
+ active_sessions: int,
418
+ idle_seconds: float,
419
+ *,
420
+ stopped: bool = False,
421
+ loading: bool = False,
422
+ ) -> bool:
423
+ """Return True when an idle or exited worker may be swept without disrupting active sessions."""
424
+ if stopped or loading or active_sessions > 0:
425
+ return False
426
+ return not worker_alive or (ttl > 0 and idle_seconds >= ttl)
427
+
428
+
429
+ def include_hidden_voice_models(
430
+ environ: Mapping[str, str] | None = None,
431
+ *,
432
+ extra_envs: tuple[str, ...] = (),
433
+ ) -> bool:
434
+ """Return True when ``LOCALMODELS_VOICE_INCLUDE_GPU`` (or fallback alias) is truthy."""
435
+ env = os.environ if environ is None else environ
436
+ for name in (VOICE_INCLUDE_GPU_ENV, *extra_envs):
437
+ raw = (env.get(name) or "").strip()
438
+ if raw:
439
+ return raw.lower() in _TRUTHY_ENV
440
+ return False
441
+
442
+
443
+ def filter_visible_status_rows(
444
+ rows: list[_RowT],
445
+ hidden_ids: frozenset[str],
446
+ *,
447
+ show_hidden: bool,
448
+ ) -> list[_RowT]:
449
+ """Omit hidden GPU voice models whose computed row state is ``absent``."""
450
+ if show_hidden:
451
+ return rows
452
+ return [row for row in rows if row["id"] not in hidden_ids or row["state"] != "absent"]
@@ -11,6 +11,7 @@ import contextlib
11
11
  import json
12
12
  import os
13
13
  import re
14
+ import threading
14
15
  import time
15
16
  import uuid
16
17
  from collections.abc import Callable, Iterator, Mapping
@@ -24,6 +25,28 @@ from localmodels.contracts import decode
24
25
  from localmodels.plan_envelope import utc_now
25
26
 
26
27
  JOB_WRITE_EVERY_S = 1.0
28
+ _GPU_EFFECTIVE_DEVICES = frozenset(("cuda", "metal", "vulkan", "directml"))
29
+ _HELD_LOCKS = threading.local()
30
+
31
+
32
+ def loading_vram_by_pool(rec: Mapping[str, Any] | None) -> dict[str, int]:
33
+ """VRAM or unified memory reserved by an in-flight ``loading`` GPU sidecar record.
34
+
35
+ Already-``loaded`` VRAM is reflected in live host ``free_bytes`` and Metal available memory,
36
+ so only ``state == "loading"`` reservations are returned to avoid double-counting.
37
+ """
38
+ if rec is None or not rec.get("running", True) or rec.get("state") != "loading":
39
+ return {}
40
+ eff = rec.get("effective_device")
41
+ if eff not in _GPU_EFFECTIVE_DEVICES:
42
+ return {}
43
+ used = rec.get("vram_used_bytes")
44
+ if isinstance(used, bool) or not isinstance(used, int) or used <= 0:
45
+ return {}
46
+ pool = rec.get("pool")
47
+ if not isinstance(pool, str) or not pool:
48
+ pool = "unified" if eff == "metal" else "gpu:0"
49
+ return {pool: used}
27
50
 
28
51
 
29
52
  class SidecarModelError(TypedDict):
@@ -49,6 +72,7 @@ class SidecarModelRecord(_ModelRecordOptional):
49
72
 
50
73
  class _SidecarJobOptional(TypedDict, total=False):
51
74
  error: SidecarModelError
75
+ engine_dir: str | None
52
76
 
53
77
 
54
78
  class SidecarJob(_SidecarJobOptional):
@@ -129,8 +153,21 @@ class SidecarStore:
129
153
 
130
154
  @contextmanager
131
155
  def locked(self, state_dir: Path | None = None) -> Iterator[None]:
132
- with hosts.file_lock(self.root(state_dir) / ".lock"):
156
+ lock_path = self.root(state_dir) / ".lock"
157
+ key = os.path.realpath(lock_path)
158
+ held: set[str] | None = getattr(_HELD_LOCKS, "paths", None)
159
+ if held is None:
160
+ held = set()
161
+ _HELD_LOCKS.paths = held
162
+ if key in held:
133
163
  yield
164
+ return
165
+ with hosts.file_lock(lock_path):
166
+ held.add(key)
167
+ try:
168
+ yield
169
+ finally:
170
+ held.discard(key)
134
171
 
135
172
  def ensure_api_key(self, state_dir: Path | None = None) -> tuple[Path, str]:
136
173
  return sidecar_http.ensure_api_key(self.api_key_path(state_dir))
@@ -383,6 +420,7 @@ class SidecarStore:
383
420
  total_bytes: int,
384
421
  *,
385
422
  state_dir: Path | None = None,
423
+ engine_dir: str | None = None,
386
424
  ) -> SidecarJob | None:
387
425
  """Under ``locked()``: claim a download job, returning None if one is already alive."""
388
426
  existing = self.read_job(model_id, state_dir)
@@ -407,6 +445,8 @@ class SidecarStore:
407
445
  "started_at": now,
408
446
  "updated_at": now,
409
447
  }
448
+ if engine_dir:
449
+ job["engine_dir"] = engine_dir
410
450
  hosts.save_private(self.job_path(model_id, state_dir), job)
411
451
  try:
412
452
  process_identity.save(self.pid_path(model_id, state_dir), os.getpid())
@@ -463,4 +503,14 @@ class SidecarJobHandle:
463
503
  self._written = now
464
504
  self.job["updated_at"] = utc_now()
465
505
  with contextlib.suppress(OSError):
466
- hosts.save_private(self.store.job_path(self.job["model"], self.state_dir), self.job)
506
+ with self.store.locked(self.state_dir):
507
+ found = self.store.read_job(self.job["model"], self.state_dir)
508
+ if (
509
+ found is not None
510
+ and found["id"] == self.job["id"]
511
+ and not found.get("error")
512
+ and not self.store.is_cancelled(self.job, self.state_dir)
513
+ ):
514
+ hosts.save_private(
515
+ self.store.job_path(self.job["model"], self.state_dir), self.job
516
+ )