@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 0.1.0-dev.38

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 (134) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +132 -110
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_checks.py +9 -6
  7. package/modules/localmodels/bifrost_config.py +203 -0
  8. package/modules/localmodels/bifrost_datasheet.py +12 -2
  9. package/modules/localmodels/budget.py +13 -2
  10. package/modules/localmodels/catalog.json +137 -2
  11. package/modules/localmodels/catalog.py +70 -321
  12. package/modules/localmodels/catalog_add.py +2 -8
  13. package/modules/localmodels/catalog_recipes.py +352 -0
  14. package/modules/localmodels/cli_parser.py +4 -1
  15. package/modules/localmodels/console.py +5 -4
  16. package/modules/localmodels/contracts.py +13 -3
  17. package/modules/localmodels/debug_cli.py +158 -0
  18. package/modules/localmodels/debug_mode.py +727 -0
  19. package/modules/localmodels/debug_stub_server.py +192 -0
  20. package/modules/localmodels/decode_calibration.json +1 -1
  21. package/modules/localmodels/decode_calibration.py +34 -17
  22. package/modules/localmodels/gateway.py +21 -155
  23. package/modules/localmodels/gateway_accept.py +201 -0
  24. package/modules/localmodels/gateway_bifrost.py +30 -193
  25. package/modules/localmodels/gateway_cli.py +15 -6
  26. package/modules/localmodels/gateway_foundations.py +2 -4
  27. package/modules/localmodels/gateway_probe.py +0 -1
  28. package/modules/localmodels/gateway_server.py +2 -3
  29. package/modules/localmodels/gpu_specs.py +12 -0
  30. package/modules/localmodels/guard.py +2 -7
  31. package/modules/localmodels/harness.py +16 -129
  32. package/modules/localmodels/harness_cleanup.py +135 -0
  33. package/modules/localmodels/harness_gateway.py +16 -14
  34. package/modules/localmodels/harness_probe.py +12 -4
  35. package/modules/localmodels/hosts.py +25 -2
  36. package/modules/localmodels/http_local.py +59 -0
  37. package/modules/localmodels/install.py +23 -8
  38. package/modules/localmodels/library_gateway.py +20 -9
  39. package/modules/localmodels/library_jobs.py +125 -28
  40. package/modules/localmodels/library_model.py +10 -0
  41. package/modules/localmodels/library_pricing.py +29 -22
  42. package/modules/localmodels/library_serve.py +17 -1
  43. package/modules/localmodels/library_state.py +15 -2
  44. package/modules/localmodels/library_status.py +30 -0
  45. package/modules/localmodels/llm_rank.py +185 -39
  46. package/modules/localmodels/probe.py +108 -174
  47. package/modules/localmodels/process_identity.py +120 -154
  48. package/modules/localmodels/process_windows.py +86 -0
  49. package/modules/localmodels/recommend.py +6 -3
  50. package/modules/localmodels/recommend_cli.py +14 -6
  51. package/modules/localmodels/remote_ops.py +65 -0
  52. package/modules/localmodels/remote_ops_service.py +14 -2
  53. package/modules/localmodels/runtime_args.py +10 -3
  54. package/modules/localmodels/runtime_auth.py +5 -9
  55. package/modules/localmodels/runtime_cli.py +128 -129
  56. package/modules/localmodels/runtime_discovery.py +84 -0
  57. package/modules/localmodels/runtime_install.py +101 -0
  58. package/modules/localmodels/runtime_releases.py +302 -0
  59. package/modules/localmodels/search_server.py +5 -1
  60. package/modules/localmodels/service_stop.py +8 -108
  61. package/modules/localmodels/service_upgrade.py +394 -63
  62. package/modules/localmodels/services_cli.py +24 -14
  63. package/modules/localmodels/setup_inspection.py +97 -9
  64. package/modules/localmodels/setup_text.py +7 -0
  65. package/modules/localmodels/sizecalc.py +0 -1
  66. package/modules/localmodels/stack.py +45 -235
  67. package/modules/localmodels/stack_arena.py +732 -0
  68. package/modules/localmodels/stack_args.py +21 -12
  69. package/modules/localmodels/stack_auto.py +384 -3
  70. package/modules/localmodels/stack_aux_gpu.py +4 -3
  71. package/modules/localmodels/stack_capacity.py +138 -0
  72. package/modules/localmodels/stack_cleanup.py +9 -4
  73. package/modules/localmodels/stack_cli.py +288 -0
  74. package/modules/localmodels/stack_compose.py +63 -30
  75. package/modules/localmodels/stack_console.py +9 -6
  76. package/modules/localmodels/stack_hardware.py +95 -265
  77. package/modules/localmodels/stack_hardware_text.py +263 -0
  78. package/modules/localmodels/stack_journal.py +3 -9
  79. package/modules/localmodels/stack_ledger.py +48 -18
  80. package/modules/localmodels/stack_lifecycle.py +33 -312
  81. package/modules/localmodels/stack_llm_ram.py +16 -6
  82. package/modules/localmodels/stack_mcp.py +729 -0
  83. package/modules/localmodels/stack_memory.py +0 -2
  84. package/modules/localmodels/stack_picks.py +62 -15
  85. package/modules/localmodels/stack_plan.py +19 -1
  86. package/modules/localmodels/stack_preflight.py +11 -19
  87. package/modules/localmodels/stack_progress.py +9 -1
  88. package/modules/localmodels/stack_remove.py +373 -0
  89. package/modules/localmodels/stack_route.py +101 -17
  90. package/modules/localmodels/stack_run.py +29 -0
  91. package/modules/localmodels/stack_suite.py +21 -10
  92. package/modules/localmodels/stack_summary.py +14 -0
  93. package/modules/localmodels/stack_try.py +238 -24
  94. package/modules/localmodels/stack_try_client.py +53 -15
  95. package/modules/localmodels/stack_try_docs.py +2 -2
  96. package/modules/localmodels/stack_view.py +24 -171
  97. package/modules/localmodels/stack_view_access.py +114 -1
  98. package/modules/localmodels/stack_view_agent.py +3 -13
  99. package/modules/localmodels/stack_view_hub.py +9 -10
  100. package/modules/localmodels/stack_view_llm.py +1 -1
  101. package/modules/localmodels/stack_view_sandbox.py +2 -2
  102. package/modules/localmodels/stack_view_schema.py +183 -0
  103. package/modules/localmodels/stack_view_serve.py +7 -1
  104. package/modules/localmodels/stack_view_service.py +1 -2
  105. package/modules/localmodels/stack_view_text.py +13 -9
  106. package/modules/localmodels/stack_warm.py +48 -4
  107. package/modules/localmodels/stack_warm_store.py +517 -0
  108. package/modules/localmodels/tools.json +32 -18
  109. package/modules/localmodels/transport.py +38 -13
  110. package/modules/localmodels/tui.py +28 -4
  111. package/modules/localmodels/tui_dialogs.py +136 -0
  112. package/modules/localmodels/tui_modals.py +279 -0
  113. package/modules/localmodels/tui_screen.py +113 -154
  114. package/modules/localmodels/tui_views.py +134 -203
  115. package/modules/localmodels/web/index.html +510 -101
  116. package/modules/localmodels/web/sizecalc/app.js +363 -10
  117. package/modules/localmodels/web/sizecalc/page.html +27 -3
  118. package/modules/localmodels/web/view/fleet.html +11 -2
  119. package/modules/localmodels/web/view/fleet.js +191 -17
  120. package/modules/localmodels/web/view/i18n.js +3 -2
  121. package/modules/localmodels/web/view/index.html +1 -1
  122. package/modules/localmodels/web/view/nav.js +22 -3
  123. package/modules/localmodels/web/view/view.css +63 -18
  124. package/modules/localmodels/web/view/view.js +169 -32
  125. package/modules/localmodels/windows_job.py +69 -0
  126. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
  127. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
  128. package/package.json +1 -1
  129. package/tool.json +1 -1
  130. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  131. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
  132. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
  133. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
  134. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -12,8 +12,10 @@ from __future__ import annotations
12
12
 
13
13
  import os
14
14
  import signal
15
+ import threading
15
16
  import time
16
- from collections.abc import Callable
17
+ from collections.abc import Callable, Iterator
18
+ from contextlib import contextmanager
17
19
  from pathlib import Path
18
20
 
19
21
  from localmodels import (
@@ -25,6 +27,7 @@ from localmodels import (
25
27
  library_state,
26
28
  library_status,
27
29
  plan_envelope,
30
+ process_identity,
28
31
  remote_ops_download,
29
32
  )
30
33
  from localmodels.deploy_steps import Action
@@ -35,7 +38,7 @@ from localmodels.library_model import (
35
38
  progress,
36
39
  )
37
40
  from localmodels.library_pricing import Model
38
- from localmodels.library_state import JobHandle, Record
41
+ from localmodels.library_state import Job, JobHandle, Record
39
42
  from localmodels.probe import HostFacts
40
43
  from localmodels.records import Plan
41
44
  from localmodels.transport import Executor
@@ -50,8 +53,54 @@ def executor() -> Executor:
50
53
 
51
54
 
52
55
  def cancel_on_sigterm() -> None:
53
- """A cancel's SIGTERM ends this job like Ctrl+C, so its cleanup runs."""
54
- signal.signal(signal.SIGTERM, signal.default_int_handler)
56
+ """A cancel's SIGTERM ends this job like Ctrl+C, so its cleanup runs. Only the first one:
57
+ a second cancel of the same job signals it again, and that SIGTERM must not cut short the
58
+ cleanup the first started (cancel escalates to SIGKILL if the job never ends)."""
59
+
60
+ def once(_signum: int, _frame: object) -> None:
61
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
62
+ raise KeyboardInterrupt
63
+
64
+ signal.signal(signal.SIGTERM, once)
65
+
66
+
67
+ WATCH_S = 0.2 # how often a Windows download looks for its cancel mark
68
+ CANCEL_BY_MARK = os.name == "nt" # Windows: no signal reaches a job; it watches its mark
69
+
70
+
71
+ @contextmanager
72
+ def watch_cancel(job: Job) -> Iterator[None]:
73
+ """Windows: a cancel cannot signal this process (another console process can only end it,
74
+ which would leave no CANCELLED line and no cleanup), so ``cancel`` marks the job and waits.
75
+ While the body runs, a thread looks for the mark and ends the download helper this process
76
+ runs, again until the body is over: the transfer then fails, the job sees its mark
77
+ (``_cancelled``) and ends as a cancel does on POSIX. POSIX gets SIGTERM instead."""
78
+ if not CANCEL_BY_MARK:
79
+ yield
80
+ return
81
+ done = threading.Event()
82
+
83
+ def watch() -> None:
84
+ while not done.wait(WATCH_S):
85
+ if library_state.cancelled(job):
86
+ try:
87
+ process_identity.stop_children(os.getpid())
88
+ except (OSError, RuntimeError, ValueError):
89
+ pass # the cancel ends the whole tree after its grace
90
+
91
+ thread = threading.Thread(target=watch, name="cancel-watch", daemon=True)
92
+ thread.start()
93
+ try:
94
+ yield
95
+ finally:
96
+ done.set()
97
+ thread.join(timeout=5)
98
+
99
+
100
+ def _cancelled(job: Job) -> None:
101
+ """Windows: a cancel marked this job; end it the way a cancel's SIGTERM ends it on POSIX."""
102
+ if CANCEL_BY_MARK and library_state.cancelled(job):
103
+ raise KeyboardInterrupt
55
104
 
56
105
 
57
106
  def dests(plan: Plan) -> list[str]:
@@ -183,6 +232,7 @@ def _shared(model: str, plan: Plan, handle: JobHandle, run: Executor, waiting: l
183
232
  or claim and fetch one when its download ended without it."""
184
233
  by_dest = {os.path.expanduser(f["dest"]): f for f in plan["files"]}
185
234
  while waiting:
235
+ _cancelled(handle.job)
186
236
  for dest in list(waiting):
187
237
  if plan_envelope.verified_in_place(by_dest[dest]):
188
238
  waiting.remove(dest)
@@ -219,6 +269,60 @@ def _refuse_download(lib: library_status.Library, model: Model) -> library_prici
219
269
  return priced
220
270
 
221
271
 
272
+ def leftovers(job: Job) -> list[str]:
273
+ """Every file a download wrote or relied on: what it claimed, and what it waited for while
274
+ another download fetched it. A cancelled download deletes all of them that nothing else
275
+ needs (``in_use``); deleting only its claims would leave a shared file another cancelled
276
+ download kept for it with no owner at all."""
277
+ return list(dict.fromkeys([*job["files"], *job.get("needs", [])]))
278
+
279
+
280
+ def _give_up(model: str, job: Job, handle: JobHandle) -> None:
281
+ """Under ``locked()``: a cancelled download deletes its files, unless something else needs
282
+ them now, and ends its job in the same step. A job left behind would still claim the files
283
+ it kept, so a remove of a model that shares them would keep them too, for nobody."""
284
+ delete_weights(leftovers(handle.job), in_use(model))
285
+ if library_state.current(job):
286
+ library_state.clear_job(model)
287
+
288
+
289
+ def _fetch_and_commit(
290
+ model: Model,
291
+ plan: Plan,
292
+ handle: JobHandle,
293
+ pool: str,
294
+ memory: int,
295
+ base_dir: str,
296
+ mine: list[str],
297
+ files: list[str],
298
+ ) -> None:
299
+ """Fetch the files this job claimed, wait for the ones another download claimed, then
300
+ record the model as this job, unless a cancel marked it."""
301
+ job = handle.job
302
+ try:
303
+ with watch_cancel(job):
304
+ fetch(model.id, plan, handle, executor(), set(mine))
305
+ _shared(model.id, plan, handle, executor(), [f for f in files if f not in mine])
306
+ except LibraryError:
307
+ _cancelled(job) # the failure is the helper a cancel ended (Windows)
308
+ raise
309
+ selector = library_gateway.pi_model(model.id, str(plan["endpoint"]["model"]))
310
+ record: Record = library_state.new_record(
311
+ model.id, model.entry.id, model.variant.quant, pool, plan, selector
312
+ )
313
+ record["memory_bytes"] = memory
314
+ record["base_dir"] = base_dir
315
+ with library_state.locked(): # commit only as this job, and only if not cancelled
316
+ found = library_state.read_job(model.id)
317
+ if found is None or found.get("id") != job["id"] or library_state.cancelled(job):
318
+ _give_up(model.id, job, handle)
319
+ raise LibraryError("CANCELLED", "the download was cancelled")
320
+ # The record and the end of this download are one step: from here the files are
321
+ # the record's, and no download job is left for a cancel to act on.
322
+ library_state.save(record)
323
+ library_state.clear_job(model.id)
324
+
325
+
222
326
  def download(
223
327
  model_id: str,
224
328
  base_dir: str,
@@ -247,27 +351,14 @@ def download(
247
351
  with library_state.held([job]):
248
352
  handle = library_state.JobHandle(job)
249
353
  try:
250
- fetch(model.id, plan, handle, executor(), set(mine))
251
- _shared(model.id, plan, handle, executor(), [f for f in files if f not in mine])
252
- except KeyboardInterrupt: # what it claimed, unless something else needs it now
354
+ _fetch_and_commit(model, plan, handle, priced.pool, memory, base_dir, mine, files)
355
+ except KeyboardInterrupt: # anywhere before the commit (a cancel's SIGTERM may land
356
+ # after the transfer, while waiting to commit): what it claimed, unless the record
357
+ # took the files or something else needs them now
253
358
  with library_state.locked():
254
- delete_weights(handle.job["files"], in_use(model.id))
359
+ if library_state.load(model.id) is None:
360
+ _give_up(model.id, job, handle)
255
361
  raise LibraryError("CANCELLED", "the download was cancelled") from None
256
- selector = library_gateway.pi_model(model.id, str(plan["endpoint"]["model"]))
257
- record: Record = library_state.new_record(
258
- model.id, model.entry.id, model.variant.quant, priced.pool, plan, selector
259
- )
260
- record["memory_bytes"] = memory
261
- record["base_dir"] = base_dir
262
- with library_state.locked(): # commit only as this job, and only if not cancelled
263
- found = library_state.read_job(model.id)
264
- if found is None or found.get("id") != job["id"] or library_state.cancelled(job):
265
- delete_weights(handle.job["files"], in_use(model.id))
266
- raise LibraryError("CANCELLED", "the download was cancelled")
267
- # The record and the end of this download are one step: from here the files are
268
- # the record's, and no download job is left for a cancel to act on.
269
- library_state.save(record)
270
- library_state.clear_job(model.id)
271
362
  if not autoload:
272
363
  return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
273
364
  try:
@@ -275,10 +366,16 @@ def download(
275
366
  except LibraryError as exc:
276
367
  if exc.code != "LOAD_NO_ROOM":
277
368
  raise
278
- record_ = library_state.load(model.id)
279
- if record_ is not None:
280
- record_["note"] = {"code": NO_ROOM_TO_LOAD}
281
- library_state.save(record_)
369
+ with library_state.locked(): # a load or remove admitted since then owns the record now:
370
+ # this note must never put a record it changed back (loaded to idle, removed to present)
371
+ record_ = library_state.load(model.id)
372
+ if (
373
+ record_ is not None
374
+ and record_["state"] == "idle"
375
+ and library_state.read_job(model.id) is None
376
+ ):
377
+ record_["note"] = {"code": NO_ROOM_TO_LOAD}
378
+ library_state.save(record_)
282
379
  return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
283
380
 
284
381
 
@@ -305,7 +402,7 @@ def cancel(model_id: str, base_dir: str) -> Row:
305
402
  with library_state.locked(): # it ended without cleaning up after itself (killed)
306
403
  committed = library_state.load(model.id) is not None
307
404
  if library_state.current(job) and not library_state.job_alive(model.id) and not committed:
308
- delete_weights(job["files"], in_use(model.id))
405
+ delete_weights(leftovers(job), in_use(model.id))
309
406
  library_state.clear_job(model.id)
310
407
  return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
311
408
 
@@ -169,6 +169,16 @@ class Row(_Row, total=False):
169
169
  endpoint: Endpoint # loaded only
170
170
  pi_model: str # every model not absent: <pi provider>/<pi model id> once it is loaded
171
171
  tokens_per_second: float # the last measured warm speed; absent when unknown
172
+ # The model card (Linger's LocalModel fields): from the catalog, each absent when unknown.
173
+ family: str
174
+ publisher: str
175
+ architecture: str # dense | moe
176
+ parameters: str
177
+ active_parameters: str
178
+ capabilities: list[str]
179
+ license: str
180
+ source_url: str
181
+ prompt_tokens_per_second: float # the last load's measured prefill speed
172
182
  error: Problem # failed only
173
183
  note: Note # idle only, when autoload was skipped
174
184
 
@@ -63,11 +63,18 @@ def is_chat(entry: cat.CatalogEntry) -> bool:
63
63
 
64
64
 
65
65
  def shown(facts: HostFacts, catalog: Iterable[cat.CatalogEntry]) -> list[Model]:
66
- """The chat models validated for this platform, one row per variant."""
66
+ """The chat models validated for this platform, and the candidates ``stack --llm auto``
67
+ picks here too (the Mac small-memory ladder, the Windows NVIDIA fallback): one row per
68
+ variant. Ling-3.0-tiny, which the ladder replaces in automatic selection, stays listed."""
67
69
  return [
68
70
  Model(e, v)
69
71
  for e in catalog
70
- if is_chat(e) and cat.validated_here(e, facts["platform"])
72
+ if is_chat(e)
73
+ and (
74
+ cat.validated_here(e, facts["platform"])
75
+ or llm_rank.mac_rung(e, facts)
76
+ or llm_rank.windows_fallback(e, facts)
77
+ )
71
78
  for v in e.variants
72
79
  ]
73
80
 
@@ -320,28 +327,28 @@ def download_reason(facts: HostFacts, priced: Priced, disk_free: int) -> Reason
320
327
  return None
321
328
 
322
329
 
323
- def rank(facts: HostFacts, model: Model, pool: str) -> tuple[int, float]:
324
- """``llm_rank``'s order (the installed score, then predicted decode speed on that card)."""
325
- index = gpu_index(pool)
326
- try:
327
- if index is None:
328
- index = (metal.device(facts) or {"index": 0})["index"]
329
- from localmodels import stack
330
+ def smartest(facts: HostFacts) -> tuple[str, str] | None:
331
+ """(catalog id, quant) of the smartest pick ``stack hardware`` shows for this computer with
332
+ its memory free (stack_picks, decision 45): what ``stack plan --llm auto`` installs on it,
333
+ the Mac ladder and the Windows fallback included. None when nothing fits automatically."""
334
+ from localmodels import stack
330
335
 
331
- card, _ = stack_hardware.llm_budget(
332
- capacity(facts), index, stack.default_options(), entry=model.entry, posture=posture()
333
- )
334
- return llm_rank.rank_key(model.entry, model.variant, card)
335
- except (KeyError, StopIteration, ValueError, TypeError):
336
- return (model.entry.quality, 0.0)
336
+ seen = capacity(facts)
337
+ seen["disk"] = facts["disk"] # Strata's fit still sees the real disk
338
+ if seen["ram"].get("pressure_level") is not None: # a Mac with its memory free: no pressure
339
+ seen["ram"]["pressure_level"] = 1
340
+ try:
341
+ view = stack_hardware.view(seen, stack.default_options(), posture())
342
+ except (KeyError, ValueError, TypeError, OSError):
343
+ return None
344
+ pick = next((p for p in view.get("picks") or [] if p["role"] == "smartest"), None)
345
+ return (pick["id"], pick["quant"]) if pick is not None else None
337
346
 
338
347
 
339
348
  def recommend(facts: HostFacts, candidates: list[tuple[Model, str]]) -> str | None:
340
- """The one model to suggest among absent, downloadable ones: the smartest by llm_rank."""
341
- if not candidates:
349
+ """The one model to suggest: the CLI's smartest pick, when it is among the absent,
350
+ downloadable ``candidates``. None when it is already on disk, not a library model (a
351
+ Strata recipe) or nothing fits: never a runner-up in its place."""
352
+ if not candidates or (pick := smartest(facts)) is None:
342
353
  return None
343
- ranked = [(rank(facts, m, pool), m.id, 0) for m, pool in candidates]
344
- small_mac = llm_rank.mac_default(facts)
345
- default = next((m.id for m, _ in candidates if m.entry.id == small_mac), None)
346
- chosen, _ = llm_rank.choose(ranked, "smartest", default)
347
- return chosen
354
+ return next((m.id for m, _ in candidates if (m.entry.id, m.variant.quant) == pick), None)
@@ -147,9 +147,20 @@ def _fail(record: Record, error: LibraryError) -> LibraryError:
147
147
 
148
148
  def stop(record: Record, run: Executor) -> None:
149
149
  """Unregister, then stop and remove the model's server; its weights stay. Either failing
150
- raises with the record unchanged, so the next unload or remove tries both again."""
150
+ raises, so the next unload or remove tries again. Once unregistered the record says so
151
+ before the server stops: a process killed in between leaves a failed model with no
152
+ registration, which status shows and the next load registers again, never a loaded one
153
+ the gateway and pi no longer route to."""
151
154
  if registration := record.get("registration"):
152
155
  library_gateway.unregister(registration)
156
+ record.pop("registration")
157
+ if record["state"] == "loaded":
158
+ record["state"] = "failed"
159
+ record["error"] = {
160
+ "code": "ENGINE_START_FAILED",
161
+ "detail": "stopping the model server did not finish; unload or load it again",
162
+ }
163
+ library_state.save(record)
153
164
  if record["state"] != "idle": # loaded, failed, or starting when a load was cut short
154
165
  _remove_service(record["plan"], run)
155
166
  record["state"] = "idle"
@@ -211,9 +222,14 @@ def _start(
211
222
  progress(model.id, "load", len(steps), len(steps))
212
223
  progress(model.id, "warm", 0, 2)
213
224
  speed = stack_warm.warm_llm(plan)["decode_tok_s"]
225
+ prefill = stack_warm.prompt_speed(plan) # one more request; warm still counts two steps
214
226
  progress(model.id, "warm", 2, 2)
215
227
  if speed is not None:
216
228
  record["tokens_per_second"] = float(speed)
229
+ if prefill is not None:
230
+ record["prompt_tokens_per_second"] = prefill
231
+ else: # the last load's measurement, or none
232
+ record.pop("prompt_tokens_per_second", None)
217
233
  key = stack_verify.key(plan) or ""
218
234
  member = stack_member(record)
219
235
  record["registration"] = library_gateway.planned(model.id, plan, stack_provider=member)
@@ -60,6 +60,7 @@ class Record(_RecordRequired, total=False):
60
60
  base_dir: str # where it was downloaded: its weights, engine and deployments live there
61
61
  memory_bytes: int # the footprint priced at download (on the pool's whole capacity)
62
62
  tokens_per_second: float
63
+ prompt_tokens_per_second: float
63
64
  registration: Registration
64
65
  error: Problem
65
66
  note: Note
@@ -251,7 +252,10 @@ class JobHandle:
251
252
 
252
253
  def refuse_busy(model: str, kind: str) -> None:
253
254
  """Under ``locked()``: refuse when a live process holds ``model``; clear a job whose
254
- process ended (killed, or the machine restarted) so it cannot outlive this operation."""
255
+ process ended (killed, or the machine restarted) so it cannot outlive this operation.
256
+ A download that ended before it recorded the model is kept for anything but a new
257
+ download: its partial files are only reachable through it (status shows it failed, and
258
+ cancel deletes them, or a download resumes them)."""
255
259
  job = read_job(model)
256
260
  if job is None:
257
261
  return
@@ -259,6 +263,8 @@ def refuse_busy(model: str, kind: str) -> None:
259
263
  if job["kind"] == "download" and kind != "download":
260
264
  raise LibraryError("INVALID_STATE", f"{model} is downloading; cancel it first")
261
265
  raise LibraryError("JOB_RUNNING", f"{model} has a running {job['kind']}")
266
+ if job["kind"] == "download" and kind != "download" and load(model) is None:
267
+ return
262
268
  clear_job(model)
263
269
 
264
270
 
@@ -352,13 +358,20 @@ def receipt(model: str) -> process_identity.Identity | None:
352
358
  def stop_process(saved: process_identity.Identity, grace: float = 20.0) -> str:
353
359
  """Stop exactly the process group ``saved`` names (SIGTERM, then SIGKILL), whatever job
354
360
  file now sits at its path: "gone" when it had ended, "stopped" otherwise. RuntimeError
355
- when it outlives SIGKILL."""
361
+ when it outlives SIGKILL. Windows has no signal one console process can send another, so
362
+ there the job ends itself once it sees its cancel mark (``library_jobs.watch_cancel``): it
363
+ is given ``grace`` to, and only then its tree is ended by force."""
356
364
  import signal
357
365
  import time
358
366
 
359
367
  if process_identity.inspect(saved["pid"]) != saved:
360
368
  return "gone"
361
369
  if os.name == "nt":
370
+ deadline = time.monotonic() + grace
371
+ while time.monotonic() < deadline:
372
+ if process_identity.inspect(saved["pid"]) != saved:
373
+ return "stopped"
374
+ time.sleep(0.1)
362
375
  if process_identity.windows_stop_tree(saved["pid"], saved, grace):
363
376
  return "stopped"
364
377
  raise RuntimeError(f"process {saved['pid']} is still running")
@@ -5,8 +5,10 @@ probe's; the web formats them and infers nothing."""
5
5
  from __future__ import annotations
6
6
 
7
7
  import datetime as dt
8
+ import re
8
9
  import urllib.request
9
10
  from dataclasses import dataclass, field
11
+ from typing import cast
10
12
 
11
13
  from localmodels import (
12
14
  __version__,
@@ -162,6 +164,31 @@ def pi_model_of(model: Model, record: Record | None) -> str | None:
162
164
  return library_gateway.pi_model(model.id, model.variant.model_id)
163
165
 
164
166
 
167
+ HUB_REPO = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*")
168
+
169
+
170
+ def card(model: Model, vision_on: bool) -> Row:
171
+ """The model card fields of a row, each only when the catalog states it: family,
172
+ publisher and parameter scales as written there, the architecture from its MoE flag, its
173
+ license, the Hugging Face page of the repository the weights come from, and vision when
174
+ this deployment reads images (its projector is pinned and priced). Nothing is guessed from
175
+ a name; Linger rejects a whole status document over one value outside its sets."""
176
+ entry = model.entry
177
+ found: dict[str, object] = {
178
+ "family": entry.family,
179
+ "publisher": entry.publisher.strip()[:120],
180
+ "architecture": "moe" if entry.moe else "dense",
181
+ "parameters": entry.parameters,
182
+ "active_parameters": entry.active_parameters if entry.moe else "",
183
+ "license": entry.license.strip()[:120],
184
+ }
185
+ if HUB_REPO.fullmatch(entry.repo):
186
+ found["source_url"] = f"https://huggingface.co/{entry.repo}"
187
+ if vision_on:
188
+ found["capabilities"] = ["vision"]
189
+ return cast(Row, {k: v for k, v in found.items() if v})
190
+
191
+
165
192
  def row(lib: Library, model: Model) -> Row:
166
193
  record = lib.records.get(model.id)
167
194
  priced = lib.judge(model)
@@ -210,6 +237,7 @@ def row(lib: Library, model: Model) -> Row:
210
237
  "total_bytes": job["total"],
211
238
  "bytes_per_second": job["bytes_per_second"],
212
239
  }
240
+ found.update(card(model, found["vision"]))
213
241
  if state != "absent":
214
242
  if (selector := pi_model_of(model, record)) is not None:
215
243
  found["pi_model"] = selector
@@ -221,6 +249,8 @@ def row(lib: Library, model: Model) -> Row:
221
249
  }
222
250
  if (speed := record.get("tokens_per_second")) is not None:
223
251
  found["tokens_per_second"] = round(speed, 1)
252
+ if (prefill := record.get("prompt_tokens_per_second")) is not None:
253
+ found["prompt_tokens_per_second"] = round(prefill, 1)
224
254
  if state == "idle" and (note := record.get("note")):
225
255
  found["note"] = note
226
256
  if state == "failed" and problem is not None: