@simplexai/localmodels-darwin-x64 0.1.0-dev.63 → 0.1.0-dev.65

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 (142) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +140 -130
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +2 -2
  5. package/modules/localmodels/app.py +15 -2
  6. package/modules/localmodels/approval.py +5 -3
  7. package/modules/localmodels/bifrost_checks.py +2 -1
  8. package/modules/localmodels/catalog.json +36 -0
  9. package/modules/localmodels/catalog.py +28 -5
  10. package/modules/localmodels/catalog_recipes.py +40 -1
  11. package/modules/localmodels/component.py +1 -1
  12. package/modules/localmodels/context_policy.py +7 -2
  13. package/modules/localmodels/custom_probe.py +5 -5
  14. package/modules/localmodels/debug_mode.py +85 -103
  15. package/modules/localmodels/deploy.py +129 -18
  16. package/modules/localmodels/deployment_lifecycle.py +167 -0
  17. package/modules/localmodels/download-mirrors.json +126 -6
  18. package/modules/localmodels/draft_spec.py +164 -0
  19. package/modules/localmodels/engine_adapters/__init__.py +4 -0
  20. package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
  21. package/modules/localmodels/engine_adapters/base.py +40 -0
  22. package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
  23. package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
  24. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  25. package/modules/localmodels/gateway.py +124 -13
  26. package/modules/localmodels/gateway_accept.py +1 -6
  27. package/modules/localmodels/gateway_cli.py +13 -24
  28. package/modules/localmodels/gateway_ops.py +185 -0
  29. package/modules/localmodels/gateway_server.py +3 -2
  30. package/modules/localmodels/harness.py +13 -16
  31. package/modules/localmodels/harness_core.py +4 -9
  32. package/modules/localmodels/harness_gateway.py +4 -3
  33. package/modules/localmodels/hosts.py +22 -34
  34. package/modules/localmodels/install.py +15 -0
  35. package/modules/localmodels/library_convert.py +5 -11
  36. package/modules/localmodels/library_custom.py +6 -6
  37. package/modules/localmodels/library_elastic.py +24 -127
  38. package/modules/localmodels/library_jobs.py +14 -5
  39. package/modules/localmodels/library_order.py +4 -3
  40. package/modules/localmodels/library_poly.py +5 -4
  41. package/modules/localmodels/library_pricing.py +80 -255
  42. package/modules/localmodels/library_serve.py +13 -14
  43. package/modules/localmodels/library_smoke.py +8 -1
  44. package/modules/localmodels/library_status.py +16 -16
  45. package/modules/localmodels/llm_rank.py +1 -1
  46. package/modules/localmodels/magpie_legacy.py +160 -0
  47. package/modules/localmodels/magpie_setup.py +6 -1
  48. package/modules/localmodels/memcalc_cli.py +2 -2
  49. package/modules/localmodels/pi_profile.py +3 -7
  50. package/modules/localmodels/plan_envelope.py +1 -1
  51. package/modules/localmodels/planning/__init__.py +3 -0
  52. package/modules/localmodels/{budget.py → planning/budget.py} +48 -30
  53. package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
  54. package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
  55. package/modules/localmodels/planning/memory_pools.py +403 -0
  56. package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
  57. package/modules/localmodels/recommend.py +1 -1
  58. package/modules/localmodels/recommend_cli.py +3 -4
  59. package/modules/localmodels/residency_host.py +1 -1
  60. package/modules/localmodels/service_control.py +4 -4
  61. package/modules/localmodels/service_deployment.py +3 -2
  62. package/modules/localmodels/service_wiring.py +17 -19
  63. package/modules/localmodels/setup_inspection.py +1 -1
  64. package/modules/localmodels/setup_inspection_harness.py +1 -1
  65. package/modules/localmodels/setup_upgrade.py +3 -12
  66. package/modules/localmodels/sizecalc_cli.py +10 -2
  67. package/modules/localmodels/speech_admission.py +1 -1
  68. package/modules/localmodels/speech_jobs.py +2 -1
  69. package/modules/localmodels/speech_model.py +2 -0
  70. package/modules/localmodels/speech_server.py +130 -9
  71. package/modules/localmodels/speech_state.py +11 -0
  72. package/modules/localmodels/speech_worker_sensevoice.py +38 -0
  73. package/modules/localmodels/speech_workers.py +5 -1
  74. package/modules/localmodels/stack.py +4 -9
  75. package/modules/localmodels/stack_arena.py +2 -2
  76. package/modules/localmodels/stack_auto.py +5 -5
  77. package/modules/localmodels/stack_aux_gpu.py +5 -3
  78. package/modules/localmodels/stack_binding.py +24 -143
  79. package/modules/localmodels/stack_capacity.py +1 -1
  80. package/modules/localmodels/stack_card.py +3 -3
  81. package/modules/localmodels/stack_cleanup.py +6 -5
  82. package/modules/localmodels/stack_client_settings.py +9 -2
  83. package/modules/localmodels/stack_compose.py +43 -6
  84. package/modules/localmodels/stack_console.py +2 -2
  85. package/modules/localmodels/stack_debug.py +1 -1
  86. package/modules/localmodels/stack_decision.py +1 -1
  87. package/modules/localmodels/stack_doctor.py +10 -7
  88. package/modules/localmodels/stack_down.py +3 -3
  89. package/modules/localmodels/stack_gpu_memory.py +1 -1
  90. package/modules/localmodels/stack_hardware.py +3 -3
  91. package/modules/localmodels/stack_hardware_text.py +1 -1
  92. package/modules/localmodels/stack_ledger.py +2 -1
  93. package/modules/localmodels/stack_lifecycle.py +7 -7
  94. package/modules/localmodels/stack_mcp.py +1 -1
  95. package/modules/localmodels/stack_memory.py +4 -4
  96. package/modules/localmodels/stack_mlx.py +1 -1
  97. package/modules/localmodels/stack_plan.py +18 -13
  98. package/modules/localmodels/stack_ports.py +2 -2
  99. package/modules/localmodels/stack_preflight.py +4 -3
  100. package/modules/localmodels/stack_remove.py +13 -6
  101. package/modules/localmodels/stack_review.py +3 -5
  102. package/modules/localmodels/stack_rollback.py +1 -1
  103. package/modules/localmodels/stack_route.py +5 -4
  104. package/modules/localmodels/stack_run.py +16 -0
  105. package/modules/localmodels/stack_suite.py +14 -6
  106. package/modules/localmodels/stack_summary.py +1 -1
  107. package/modules/localmodels/stack_try.py +10 -14
  108. package/modules/localmodels/stack_up.py +25 -39
  109. package/modules/localmodels/stack_update.py +2 -1
  110. package/modules/localmodels/stack_verify.py +4 -30
  111. package/modules/localmodels/stack_view.py +6 -4
  112. package/modules/localmodels/stack_view_apply.py +2 -2
  113. package/modules/localmodels/stack_view_llm.py +12 -7
  114. package/modules/localmodels/stack_view_text.py +2 -6
  115. package/modules/localmodels/stack_view_tick.py +2 -2
  116. package/modules/localmodels/stack_view_words.py +5 -2
  117. package/modules/localmodels/stack_warm.py +7 -4
  118. package/modules/localmodels/stack_whatif.py +1 -1
  119. package/modules/localmodels/suite.py +6 -334
  120. package/modules/localmodels/tui_views.py +28 -7
  121. package/modules/localmodels/web/index.html +595 -226
  122. package/modules/localmodels/web/sizecalc/app.js +34 -40
  123. package/modules/localmodels/web/sizecalc/calc.js +3 -3
  124. package/modules/localmodels/web/sizecalc/page.html +4 -3
  125. package/modules/localmodels/web/view/fleet.html +18 -3
  126. package/modules/localmodels/web/view/fleet.js +135 -14
  127. package/modules/localmodels/web/view/i18n.js +4 -0
  128. package/modules/localmodels/web/view/index.html +16 -0
  129. package/modules/localmodels/web/view/nav.js +49 -0
  130. package/modules/localmodels/web/view/theme.js +1 -1
  131. package/modules/localmodels/web/view/view.css +51 -15
  132. package/modules/localmodels/web/view/view.js +22 -4
  133. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
  134. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +137 -127
  135. package/package.json +1 -1
  136. package/tool.json +1 -1
  137. package/modules/localmodels/library_vram.py +0 -123
  138. /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/WHEEL +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
  141. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
  142. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1431,6 +1431,24 @@
1431
1431
  "revision": "ae9327c5fbc7333116ba32eee78bb5d2bbefae4f",
1432
1432
  "sha256": "2c165c78790e78a3f45a2d1e9e931083e52ee69d45ff2a0dc9c281fdf1a666e7"
1433
1433
  },
1434
+ "draft": {
1435
+ "path": "dspark-Inkling-2-Mini-Q8_0.gguf",
1436
+ "size_bytes": 402278560,
1437
+ "local": "dspark-Inkling-2-Mini-Q8_0.gguf",
1438
+ "revision": "ae9327c5fbc7333116ba32eee78bb5d2bbefae4f",
1439
+ "sha256": "2ec78510da837e8fc3be54a14757a0c5fbd2d8d9e85a0d92853fafdf674f3773"
1440
+ },
1441
+ "draft_spec": {
1442
+ "spec_type": "draft-dspark",
1443
+ "n_max": 4,
1444
+ "overhead_bytes": 3057647616,
1445
+ "kv_bytes_per_token": 4096,
1446
+ "kv_swa_bytes": 18874368,
1447
+ "backends": [
1448
+ "metal"
1449
+ ],
1450
+ "min_engine": "b12757-mix-ef2df21"
1451
+ },
1434
1452
  "n_ctx_train": 1048576,
1435
1453
  "full_layers": 8,
1436
1454
  "recurrent_layers": 0,
@@ -1520,6 +1538,24 @@
1520
1538
  "revision": "ae9327c5fbc7333116ba32eee78bb5d2bbefae4f",
1521
1539
  "sha256": "2c165c78790e78a3f45a2d1e9e931083e52ee69d45ff2a0dc9c281fdf1a666e7"
1522
1540
  },
1541
+ "draft": {
1542
+ "path": "dspark-Inkling-2-Mini-Q8_0.gguf",
1543
+ "size_bytes": 402278560,
1544
+ "local": "dspark-Inkling-2-Mini-Q8_0.gguf",
1545
+ "revision": "ae9327c5fbc7333116ba32eee78bb5d2bbefae4f",
1546
+ "sha256": "2ec78510da837e8fc3be54a14757a0c5fbd2d8d9e85a0d92853fafdf674f3773"
1547
+ },
1548
+ "draft_spec": {
1549
+ "spec_type": "draft-dspark",
1550
+ "n_max": 4,
1551
+ "overhead_bytes": 3057647616,
1552
+ "kv_bytes_per_token": 4096,
1553
+ "kv_swa_bytes": 18874368,
1554
+ "backends": [
1555
+ "metal"
1556
+ ],
1557
+ "min_engine": "b12757-mix-ef2df21"
1558
+ },
1523
1559
  "n_ctx_train": 1048576,
1524
1560
  "full_layers": 8,
1525
1561
  "recurrent_layers": 0,
@@ -7,7 +7,7 @@ Every entry carries the estimator inputs (measured on real GGUFs) so the picker
7
7
  BEFORE the user downloads gigabytes; once a file is on disk, profile_from_gguf() is the authority.
8
8
 
9
9
  Differences from Hermes: the catalog is the vendored catalog.json only (no in-memory refresh from
10
- GitHub), and recommendation takes the placement budgets produced by localmodels.budget, so a
10
+ GitHub), and recommendation takes the placement budgets produced by localmodels.planning.budget, so a
11
11
  multi-GPU host is priced per card and as a pooled split.
12
12
  """
13
13
 
@@ -18,7 +18,7 @@ from collections.abc import Sequence
18
18
  from dataclasses import dataclass, field, replace
19
19
  from pathlib import Path, PurePosixPath
20
20
 
21
- from localmodels import decode_calibration, vision
21
+ from localmodels import decode_calibration, draft_spec, vision
22
22
  from localmodels.catalog_recipes import CATALOG_PATH as CATALOG_PATH
23
23
  from localmodels.catalog_recipes import EFFORT_LEVELS as EFFORT_LEVELS
24
24
  from localmodels.catalog_recipes import FIXTURE_DIR as FIXTURE_DIR
@@ -33,6 +33,7 @@ from localmodels.catalog_recipes import ComponentRecipe as ComponentRecipe
33
33
  from localmodels.catalog_recipes import DecisionFrontend as DecisionFrontend
34
34
  from localmodels.catalog_recipes import DecisionRecipe as DecisionRecipe
35
35
  from localmodels.catalog_recipes import DecisionTier as DecisionTier
36
+ from localmodels.catalog_recipes import DraftSpecData as DraftSpecData
36
37
  from localmodels.catalog_recipes import LlamaComponentRecipe as LlamaComponentRecipe
37
38
  from localmodels.catalog_recipes import ModelData as ModelData
38
39
  from localmodels.catalog_recipes import OptionalAssetData as OptionalAssetData
@@ -154,6 +155,7 @@ class CatalogEntry:
154
155
  kv_k_only: bool = False # MLA: per_layer_f16 is the K latent alone; -ctv does not apply
155
156
  mmproj: AssetFile | None = None
156
157
  draft: AssetFile | None = None
158
+ draft_spec: draft_spec.DraftSpec | None = None
157
159
  mtp_head: AssetFile | None = None
158
160
  sampling: dict[str, str] = field(default_factory=dict)
159
161
  min_engine: str = ""
@@ -236,7 +238,8 @@ class CatalogEntry:
236
238
  agent = self.agent_posture(agent)
237
239
  profile = eager(self.profile(variant)) # the agent argv has no --lazy-mode
238
240
  depth = self.mtp_draft_depth if self.agent_mtp and self.mtp_capable else 0
239
- return vision.priced(self.mmproj, profile, budget, agent, mtp_depth=depth)
241
+ planned = vision.priced(self.mmproj, profile, budget, agent, mtp_depth=depth)
242
+ return draft_spec.priced(self.draft_spec, planned, budget, agent)
240
243
  profile = as_loaded(self.profile(variant), budget)
241
244
  return plan_launch(
242
245
  profile,
@@ -247,7 +250,8 @@ class CatalogEntry:
247
250
  )
248
251
 
249
252
  def download_files(self, variant: QuantVariant) -> tuple[AssetFile, ...]:
250
- extras = tuple(a for a in (self.mmproj, self.draft, self.mtp_head) if a is not None)
253
+ optional_draft = None if self.draft_spec is not None else self.draft
254
+ extras = tuple(a for a in (self.mmproj, optional_draft, self.mtp_head) if a is not None)
251
255
  return tuple(variant.files) + extras
252
256
 
253
257
  def download_bytes(self, variant: QuantVariant) -> int:
@@ -407,6 +411,23 @@ def _asset_from(d: OptionalAssetData | None) -> AssetFile | None:
407
411
  )
408
412
 
409
413
 
414
+ def _draft_spec_from(
415
+ d: DraftSpecData | None, draft: AssetFile | None
416
+ ) -> draft_spec.DraftSpec | None:
417
+ if not d or draft is None:
418
+ return None
419
+ return draft_spec.DraftSpec(
420
+ spec_type=d["spec_type"],
421
+ n_max=int(d["n_max"]),
422
+ weights_bytes=draft.size_bytes,
423
+ overhead_bytes=int(d.get("overhead_bytes", 0)),
424
+ kv_bytes_per_token=int(d.get("kv_bytes_per_token", 0)),
425
+ kv_swa_bytes=int(d.get("kv_swa_bytes", 0)),
426
+ backends=tuple(d.get("backends", ("metal",))),
427
+ min_engine=str(d.get("min_engine") or ""),
428
+ )
429
+
430
+
410
431
  def _quality(value: int | QualityData) -> tuple[int, tuple[QualitySource, ...]]:
411
432
  """Schema 2 wrote a bare editorial integer; schema 3 cites where the score came from."""
412
433
  if isinstance(value, int):
@@ -437,6 +458,7 @@ def load_catalog(value: object) -> tuple[CatalogEntry, ...]:
437
458
  if not variants or any(not v.files for v in variants):
438
459
  raise ValueError("catalog model requires nonempty variants and files")
439
460
  quality, quality_sources = _quality(m.get("quality", 0))
461
+ draft_asset = _asset_from(m.get("draft"))
440
462
  entries.append(
441
463
  CatalogEntry(
442
464
  id=m["id"],
@@ -445,7 +467,8 @@ def load_catalog(value: object) -> tuple[CatalogEntry, ...]:
445
467
  repo=m["repo"],
446
468
  variants=variants,
447
469
  mmproj=_asset_from(m.get("mmproj")),
448
- draft=_asset_from(m.get("draft")),
470
+ draft=draft_asset,
471
+ draft_spec=_draft_spec_from(m.get("draft_spec"), draft_asset),
449
472
  mtp_head=_asset_from(m.get("mtp_head")),
450
473
  n_ctx_train=m["n_ctx_train"],
451
474
  full_layers=m["full_layers"],
@@ -105,6 +105,16 @@ class CardData(TypedDict, total=False):
105
105
  active_parameters: str
106
106
 
107
107
 
108
+ class DraftSpecData(TypedDict, total=False):
109
+ spec_type: str
110
+ n_max: int
111
+ overhead_bytes: int
112
+ kv_bytes_per_token: int
113
+ kv_swa_bytes: int
114
+ backends: list[str]
115
+ min_engine: str # oldest llama.cpp build that accepts spec_type, e.g. b12757-mix-ef2df21
116
+
117
+
108
118
  class OptionalModelData(ModelData, ProvenanceData, CardData, total=False):
109
119
  runtime: str
110
120
  max_agent_window: int # since 2026-11-16: the agent posture's window cap, tokens
@@ -134,6 +144,7 @@ class OptionalModelData(ModelData, ProvenanceData, CardData, total=False):
134
144
  kv_k_only: bool
135
145
  mmproj: OptionalAssetData | None
136
146
  draft: OptionalAssetData | None
147
+ draft_spec: DraftSpecData | None
137
148
  mtp_head: OptionalAssetData | None
138
149
 
139
150
 
@@ -360,6 +371,34 @@ def _pin_problems(model: OptionalModelData) -> list[str]:
360
371
  return found
361
372
 
362
373
 
374
+ def _draft_spec_problems(model: OptionalModelData) -> list[str]:
375
+ spec = model.get("draft_spec")
376
+ if spec is None:
377
+ return []
378
+ found = []
379
+ if not model.get("draft"):
380
+ found.append("draft_spec requires draft")
381
+ if not spec.get("spec_type"):
382
+ found.append("draft_spec.spec_type is missing")
383
+ if int(spec.get("n_max", 0)) <= 0:
384
+ found.append("draft_spec.n_max must be positive")
385
+ for key, val in (
386
+ ("overhead_bytes", spec.get("overhead_bytes", 0)),
387
+ ("kv_bytes_per_token", spec.get("kv_bytes_per_token", 0)),
388
+ ("kv_swa_bytes", spec.get("kv_swa_bytes", 0)),
389
+ ):
390
+ if int(val) < 0:
391
+ found.append(f"draft_spec.{key} must be non-negative")
392
+ backends = spec.get("backends")
393
+ if backends is not None and (
394
+ not backends or any(b not in ("metal", "cuda", "cpu") for b in backends)
395
+ ):
396
+ found.append("draft_spec.backends must name some of metal, cuda, cpu")
397
+ if "min_engine" in spec and not re.fullmatch(r"b\d+(-[\w.]+)*", str(spec["min_engine"])):
398
+ found.append("draft_spec.min_engine must be a llama.cpp build tag")
399
+ return found
400
+
401
+
363
402
  def problems(value: object) -> list[str]:
364
403
  """Why this catalog is not complete as schema 3, one line per entry and field (never values):
365
404
  every model and component names its license with an https link, status, tasks and evidence;
@@ -383,7 +422,7 @@ def problems(value: object) -> list[str]:
383
422
  issues.append("quality has no sources")
384
423
  elif any(s["type"] not in QUALITY_SOURCE_TYPES for s in quality["sources"]):
385
424
  issues.append("quality.sources[].type is unknown")
386
- issues += _pin_problems(m) + _card_problems(m)
425
+ issues += _pin_problems(m) + _card_problems(m) + _draft_spec_problems(m)
387
426
  found += [f"models.{m['id']}: {issue}" for issue in issues]
388
427
  for c in doc.get("components", []):
389
428
  issues = _entry_problems(c, c["task"], c["runtime"])
@@ -17,7 +17,6 @@ from pathlib import Path
17
17
 
18
18
  from localmodels import catalog as cat
19
19
  from localmodels import hosts
20
- from localmodels.budget import gib
21
20
  from localmodels.deploy import DEFAULT_BASE_DIR, HF_API
22
21
  from localmodels.engines import (
23
22
  EngineUnavailableError,
@@ -35,6 +34,7 @@ from localmodels.plan_envelope import (
35
34
  require_disk,
36
35
  require_free_port,
37
36
  )
37
+ from localmodels.planning.budget import gib
38
38
  from localmodels.probe import GPU, HostFacts
39
39
  from localmodels.records import Plan, ReleaseEngine, ReusableFile
40
40
 
@@ -81,7 +81,7 @@ class AgentPosture:
81
81
  # those checkpoints sit in host RAM outside the cache too (estimator.llama_host_bytes). The
82
82
  # minimum is guaranteed ahead of the decision model and the auxiliaries; the cache above it
83
83
  # comes after them (2026-11-07, V16C: 2048 no slower, multi-turn quality indistinguishable),
84
- # so a host short of RAM gets a smaller cache and a warning (stack_llm_ram).
84
+ # so a host short of RAM gets a smaller cache and a warning (planning.llm_ram).
85
85
  prompt_cache_mib: int = 8192
86
86
  prompt_cache_min_mib: int = 2048
87
87
  # MTP draft depth for an entry the catalog marks agent_mtp. MTP_AUTO: the entry's depth
@@ -102,6 +102,7 @@ class AgentPosture:
102
102
  ubatch_pinned: bool = False
103
103
  # llama-server --ctx-checkpoints; None keeps b11370's 32. Metal sets METAL_CTX_CHECKPOINTS.
104
104
  ctx_checkpoints: int | None = None
105
+ draft: str = "auto" # optional external drafter (e.g. Metal DSpark): "auto" or "off"
105
106
 
106
107
 
107
108
  MTP_AUTO = -1
@@ -172,6 +173,9 @@ class WindowDecision:
172
173
  vision_reader: str = "off" # agent posture: where the picture reader runs (vision.READERS)
173
174
  vision_bytes: int = 0 # the reader's device memory, included in vram_bytes
174
175
  ubatch: int = DEFAULT_UBATCH # -ub priced and launched in agent posture
176
+ draft_type: str = "" # optional external drafter --spec-type (e.g. "draft-dspark")
177
+ draft_n_max: int = 0 # optional external drafter --spec-draft-n-max; 0 = off
178
+ draft_bytes: int = 0 # drafter device memory, included in vram_bytes
175
179
 
176
180
  @property
177
181
  def spilled(self) -> bool:
@@ -193,7 +197,8 @@ def agent_unified_bytes(
193
197
  )
194
198
  host = 0 if profile.tied_embeddings else profile.embd_table_bytes
195
199
  checkpoints = metal_checkpoint_bytes(profile, posture, decision.slots, decision.kv_types)
196
- return device + decision.vision_bytes + host + cache_floor_bytes(posture, profile) + checkpoints
200
+ extras = decision.vision_bytes + decision.draft_bytes + host + checkpoints
201
+ return device + extras + cache_floor_bytes(posture, profile)
197
202
 
198
203
 
199
204
  def metal_host_bytes(profile: ModelProfile, posture: AgentPosture) -> int:
@@ -14,7 +14,6 @@ from dataclasses import replace
14
14
  from typing import cast
15
15
 
16
16
  from localmodels import (
17
- budget,
18
17
  custom_hub,
19
18
  estimator,
20
19
  library_elastic,
@@ -41,6 +40,7 @@ from localmodels.library_model import (
41
40
  MemoryEstimateBasis,
42
41
  MemoryStatus,
43
42
  )
43
+ from localmodels.planning import budget, memory_pools
44
44
  from localmodels.probe import HostFacts
45
45
 
46
46
  SWEET_SPOT_QUANTS: tuple[str, ...] = (
@@ -112,19 +112,19 @@ def _memory_status(
112
112
 
113
113
  def _select_target_pool(facts: HostFacts) -> tuple[str, int, int, int]:
114
114
  """Return ``(pool_id, total_bytes, soft_budget_bytes, hard_ceiling_bytes)``."""
115
- pool_map = library_pricing.pools(facts)
115
+ pool_map = memory_pools.pools(facts)
116
116
  preferred = [p for p in pool_map if p != "system"]
117
117
  if preferred:
118
118
  target = max(
119
119
  preferred,
120
120
  key=lambda p: (
121
- library_pricing.pool_free(facts, p),
122
- library_pricing.pool_total(facts, p),
121
+ memory_pools.pool_free(facts, p),
122
+ memory_pools.pool_total(facts, p),
123
123
  ),
124
124
  )
125
125
  else:
126
126
  target = "system"
127
- total = library_pricing.pool_total(facts, target)
127
+ total = memory_pools.pool_total(facts, target)
128
128
  adm = budget.admission_budget(facts, target)
129
129
  if adm is None:
130
130
  return target, total, 0, 0
@@ -27,7 +27,18 @@ from dataclasses import dataclass, field
27
27
  from pathlib import Path
28
28
  from typing import Any, Literal, cast
29
29
 
30
- from localmodels import hosts, process_identity
30
+ from localmodels import (
31
+ bifrost_models,
32
+ hosts,
33
+ library_gateway,
34
+ library_state,
35
+ probe,
36
+ process_identity,
37
+ service_probe,
38
+ )
39
+ from localmodels import catalog as cat
40
+ from localmodels.library_state import Registration
41
+ from localmodels.transport import Result
31
42
 
32
43
  Mode = Literal["off", "simulate", "tiny"]
33
44
  MODES: tuple[str, ...] = ("off", "simulate", "tiny")
@@ -195,8 +206,6 @@ def _ensure_isolated_gateway() -> None:
195
206
 
196
207
 
197
208
  def _install_tiny_mode(config: DebugConfig) -> None:
198
- from localmodels import catalog as cat
199
-
200
209
  cache_path = Path(config.cache_dir).expanduser() if config.cache_dir else default_cache_dir()
201
210
  os.environ.setdefault("LOCALMODELS_CACHE_DIR", str(cache_path))
202
211
  original_load = cat.load_catalog_file
@@ -297,8 +306,6 @@ def _synthetic_facts(real: dict[str, Any] | None, vram_gb: int) -> dict[str, Any
297
306
 
298
307
 
299
308
  def _apply_simulated_occupancy(facts: dict[str, Any]) -> dict[str, Any]:
300
- from localmodels import library_state
301
-
302
309
  adjusted = copy.deepcopy(facts)
303
310
  adjusted.setdefault("disk", {})["free_bytes"] = max(
304
311
  int(adjusted.get("disk", {}).get("free_bytes") or 0), 1000 * GIB
@@ -534,8 +541,6 @@ class SimulatedExecutor:
534
541
  timeout: float = 60,
535
542
  on_event: Callable[[dict[str, object]], None] | None = None,
536
543
  ) -> tuple[dict[str, object], Any]:
537
- from localmodels.transport import Result
538
-
539
544
  if reason := self.config.fail.get(action):
540
545
  return {"event": "error", "message": reason}, Result(1, "", reason)
541
546
  if action == "engine":
@@ -564,37 +569,37 @@ class SimulatedExecutor:
564
569
  return {"event": "result"}, Result(0, "", "")
565
570
 
566
571
 
572
+ def _direct_register(
573
+ model: str,
574
+ entry: cat.CatalogEntry,
575
+ plan: Any,
576
+ key: str,
577
+ facts: Any,
578
+ *,
579
+ stack_provider: str | None = None,
580
+ ) -> Registration:
581
+ """Register a simulated server straight into pi, without Bifrost."""
582
+ _ = key, facts
583
+ added = library_gateway.planned(model, plan, stack_provider=stack_provider)
584
+ facts_ = library_gateway.model_facts(model, entry, plan)
585
+ base_url = str(plan["endpoint"]["base_url"]).removesuffix("/v1").rstrip("/")
586
+ served = str(plan["endpoint"]["model"])
587
+ pi_entry = bifrost_models.pi_provider(facts_, served, base_url)["models"][0]
588
+ with library_gateway.gateway_locked():
589
+ library_gateway.pi_add(added["pi_provider"], pi_entry, base_url)
590
+ return {**added, "model": served, "pi_model": f"{added['pi_provider']}/{served}"}
591
+
592
+
593
+ def _direct_unregister(registration: Registration) -> None:
594
+ with library_gateway.gateway_locked():
595
+ library_gateway.pi_drop(registration["pi_provider"], registration["model"])
596
+
597
+
567
598
  def _install_direct_pi_gateway() -> None:
568
599
  """Offline fallback for ``simulate`` when Bifrost is unavailable or ``offline_gateway`` is set."""
569
- from localmodels import bifrost_models, library_gateway
570
- from localmodels import catalog as cat
571
- from localmodels.library_state import Registration
572
-
573
600
  original_register = library_gateway.register
574
601
  original_unregister = library_gateway.unregister
575
602
 
576
- def direct_register(
577
- model: str,
578
- entry: cat.CatalogEntry,
579
- plan: Any,
580
- key: str,
581
- facts: Any,
582
- *,
583
- stack_provider: str | None = None,
584
- ) -> Registration:
585
- added = library_gateway.planned(model, plan, stack_provider=stack_provider)
586
- facts_ = library_gateway.model_facts(model, entry, plan)
587
- base_url = str(plan["endpoint"]["base_url"]).removesuffix("/v1").rstrip("/")
588
- served = str(plan["endpoint"]["model"])
589
- pi_entry = bifrost_models.pi_provider(facts_, served, base_url)["models"][0]
590
- with library_gateway.gateway_locked():
591
- library_gateway.pi_add(added["pi_provider"], pi_entry, base_url)
592
- return {**added, "model": served, "pi_model": f"{added['pi_provider']}/{served}"}
593
-
594
- def direct_unregister(registration: Registration) -> None:
595
- with library_gateway.gateway_locked():
596
- library_gateway.pi_drop(registration["pi_provider"], registration["model"])
597
-
598
603
  def register_with_fallback(
599
604
  model: str,
600
605
  entry: cat.CatalogEntry,
@@ -607,11 +612,11 @@ def _install_direct_pi_gateway() -> None:
607
612
  try:
608
613
  return original_register(model, entry, plan, key, facts, stack_provider=stack_provider)
609
614
  except Exception:
610
- return direct_register(model, entry, plan, key, facts, stack_provider=stack_provider)
615
+ return _direct_register(model, entry, plan, key, facts, stack_provider=stack_provider)
611
616
 
612
617
  def unregister_with_fallback(registration: Registration) -> None:
613
618
  if "/" not in registration.get("model", ""):
614
- direct_unregister(registration)
619
+ _direct_unregister(registration)
615
620
  return
616
621
  with contextlib.suppress(Exception):
617
622
  original_unregister(registration)
@@ -630,86 +635,57 @@ def _empty_services() -> dict[str, Any]:
630
635
  }
631
636
 
632
637
 
633
- def _install_simulate_mode(config: DebugConfig) -> None:
634
- from localmodels import (
635
- app,
636
- library_gateway,
637
- library_pricing,
638
- library_serve,
639
- probe,
640
- service_probe,
641
- stack_warm,
642
- )
638
+ def simulated_local_facts(config: DebugConfig, real_loader: Callable[[], Any]) -> dict[str, Any]:
639
+ """This computer's facts under ``simulate``: the real GPU or Metal reading when no
640
+ ``vram_gb`` is set and one answers, else synthetic facts; no services, loaded library
641
+ models held."""
642
+ real: dict[str, Any] | None = None
643
+ if config.vram_gb is None:
644
+ with contextlib.suppress(Exception):
645
+ probed = real_loader()
646
+ if probed and (probed.get("gpus") or probed.get("metal")):
647
+ real = copy.deepcopy(dict(probed))
648
+ real["llama_servers"] = []
649
+ real["services"] = _empty_services()
650
+ facts = real if real is not None else _synthetic_facts(real, config.vram_gb or 24)
651
+ facts["services"] = _empty_services()
652
+ return _apply_simulated_occupancy(facts)
653
+
654
+
655
+ def simulated_disk_free(config: DebugConfig) -> int:
656
+ """Free disk bytes under ``simulate``: nearly none when ``fail`` names ``disk``."""
657
+ return 1024 if "disk" in config.fail else 1000 * GIB
658
+
659
+
660
+ def simulated_port() -> int:
661
+ """A free loopback port for a simulated server."""
662
+ return int(_free_loopback_addr().rsplit(":", 1)[1])
663
+
664
+
665
+ def simulated_warm(config: DebugConfig) -> dict[str, Any]:
666
+ """A simulated warm-up: waits ``load_ms`` and reports a fixed decode speed."""
667
+ if config.load_ms > 0:
668
+ time.sleep(config.load_ms / 1000.0)
669
+ return {"decode_tok_s": 120.0, "ok": True}
643
670
 
671
+
672
+ def _install_simulate_mode(config: DebugConfig) -> None:
673
+ """Replace the host-reading and gateway parts below this module. Modules above it ask
674
+ ``simulating()`` at their own seams (app.probe, library_pricing.base_free,
675
+ library_serve's port choice, stack_warm.warm_llm) instead of being patched from here."""
644
676
  if config.vram_gb is not None and os.environ.get("CUDA_VISIBLE_DEVICES") == "":
645
677
  os.environ.pop("CUDA_VISIBLE_DEVICES", None)
646
- original_probe = app.probe
647
678
  original_collect = probe.collect
648
679
  executor = SimulatedExecutor(config)
649
680
 
650
- def _simulated_local_facts(real_loader: Callable[[], Any]) -> Any:
651
- real: dict[str, Any] | None = None
652
- if config.vram_gb is None:
653
- with contextlib.suppress(Exception):
654
- probed = real_loader()
655
- if probed and (probed.get("gpus") or probed.get("metal")):
656
- real = copy.deepcopy(dict(probed))
657
- real["llama_servers"] = []
658
- real["services"] = _empty_services()
659
- facts = real if real is not None else _synthetic_facts(real, config.vram_gb or 24)
660
- facts["services"] = _empty_services()
661
- return _apply_simulated_occupancy(facts)
662
-
663
- def simulated_probe(dev_id: str, **kwargs: Any) -> Any:
664
- if dev_id != hosts.LOCAL_ID:
665
- return original_probe(dev_id, **kwargs)
666
- return _simulated_local_facts(lambda: original_probe(dev_id, **kwargs))
667
-
668
681
  def simulated_collect(*args: Any, **kwargs: Any) -> Any:
669
- return _simulated_local_facts(lambda: original_collect(*args, **kwargs))
670
-
671
- def simulated_base_free(base_dir: str) -> int:
672
- _ = base_dir
673
- return 1024 if "disk" in config.fail else 1000 * GIB
682
+ return simulated_local_facts(config, lambda: original_collect(*args, **kwargs))
674
683
 
675
- app.probe = simulated_probe
676
684
  probe.collect = simulated_collect
677
685
  service_probe.collect = lambda *_a, **_kw: _empty_services()
678
- library_pricing.base_free = simulated_base_free
679
- library_serve._port = lambda facts: int(_free_loopback_addr().rsplit(":", 1)[1])
680
686
  cast(Any, hosts).executor = lambda _dev: executor
681
-
682
- def simulated_warm(_part: Any) -> dict[str, Any]:
683
- if config.load_ms > 0:
684
- time.sleep(config.load_ms / 1000.0)
685
- return {"decode_tok_s": 120.0, "ok": True}
686
-
687
- cast(Any, stack_warm).warm_llm = simulated_warm
688
687
  if config.offline_gateway:
689
- from localmodels import bifrost_models
690
- from localmodels import catalog as cat
691
- from localmodels.library_state import Registration
692
-
693
- def offline_only_register(
694
- model: str,
695
- entry: cat.CatalogEntry,
696
- plan: Any,
697
- key: str,
698
- facts: Any,
699
- *,
700
- stack_provider: str | None = None,
701
- ) -> Registration:
702
- _ = key, facts
703
- added = library_gateway.planned(model, plan, stack_provider=stack_provider)
704
- facts_ = library_gateway.model_facts(model, entry, plan)
705
- base_url = str(plan["endpoint"]["base_url"]).removesuffix("/v1").rstrip("/")
706
- served = str(plan["endpoint"]["model"])
707
- pi_entry = bifrost_models.pi_provider(facts_, served, base_url)["models"][0]
708
- with library_gateway.gateway_locked():
709
- library_gateway.pi_add(added["pi_provider"], pi_entry, base_url)
710
- return {**added, "model": served, "pi_model": f"{added['pi_provider']}/{served}"}
711
-
712
- library_gateway.register = offline_only_register
688
+ library_gateway.register = _direct_register
713
689
  else:
714
690
  _install_direct_pi_gateway()
715
691
 
@@ -722,6 +698,12 @@ def current() -> DebugConfig:
722
698
  return _ACTIVE if _ACTIVE is not None else resolve_config()
723
699
 
724
700
 
701
+ def simulating() -> DebugConfig | None:
702
+ """The ``simulate`` config once ``activate()`` applied it, else None: the seam the modules
703
+ above this one check before they read the host, pick a port or warm a server."""
704
+ return _ACTIVE if _ACTIVE is not None and _ACTIVE.mode == "simulate" else None
705
+
706
+
725
707
  def status_info() -> dict[str, str] | None:
726
708
  """Structured debug summary for ``library-status/v1`` when debug mode is active, else None."""
727
709
  cfg = current()