@simplexai/localmodels-darwin-x64 0.1.0-dev.56 → 0.1.0-dev.58

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 (55) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +54 -52
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/bifrost_admin.py +2 -1
  5. package/modules/localmodels/bifrost_checks.py +11 -8
  6. package/modules/localmodels/bifrost_models.py +2 -1
  7. package/modules/localmodels/budget.py +161 -1
  8. package/modules/localmodels/catalog.json +10 -8
  9. package/modules/localmodels/catalog.py +5 -2
  10. package/modules/localmodels/gateway_accept.py +4 -3
  11. package/modules/localmodels/gateway_bifrost.py +2 -1
  12. package/modules/localmodels/gateway_cli.py +4 -3
  13. package/modules/localmodels/gateway_server.py +3 -1
  14. package/modules/localmodels/gpu_specs.py +38 -13
  15. package/modules/localmodels/harness.py +2 -2
  16. package/modules/localmodels/hf_repo.py +27 -4
  17. package/modules/localmodels/library_cli.py +8 -1
  18. package/modules/localmodels/library_elastic.py +720 -0
  19. package/modules/localmodels/library_model.py +101 -4
  20. package/modules/localmodels/library_pricing.py +31 -39
  21. package/modules/localmodels/library_serve.py +238 -42
  22. package/modules/localmodels/library_state.py +31 -0
  23. package/modules/localmodels/library_status.py +95 -2
  24. package/modules/localmodels/llm_rank.py +16 -5
  25. package/modules/localmodels/metal.py +141 -0
  26. package/modules/localmodels/metal_probe.py +167 -0
  27. package/modules/localmodels/probe.py +2 -2
  28. package/modules/localmodels/recommend.py +6 -1
  29. package/modules/localmodels/remote_ops_download.py +36 -261
  30. package/modules/localmodels/remote_ops_ranges.py +447 -0
  31. package/modules/localmodels/runtime_auth.py +2 -1
  32. package/modules/localmodels/runtime_cli.py +1 -1
  33. package/modules/localmodels/runtime_install.py +5 -2
  34. package/modules/localmodels/runtime_io.py +3 -2
  35. package/modules/localmodels/runtime_pi.py +2 -1
  36. package/modules/localmodels/runtime_windows_acl.py +39 -0
  37. package/modules/localmodels/source_byok_probe.py +2 -1
  38. package/modules/localmodels/stack.py +13 -3
  39. package/modules/localmodels/stack_cli.py +1 -0
  40. package/modules/localmodels/stack_compose.py +6 -1
  41. package/modules/localmodels/stack_events.py +15 -0
  42. package/modules/localmodels/stack_hardware.py +3 -1
  43. package/modules/localmodels/stack_picks.py +16 -2
  44. package/modules/localmodels/stack_plan.py +5 -1
  45. package/modules/localmodels/stack_progress.py +30 -5
  46. package/modules/localmodels/stack_run.py +117 -0
  47. package/modules/localmodels/transport.py +1 -0
  48. package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/METADATA +1 -1
  49. package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/RECORD +51 -49
  50. package/package.json +1 -1
  51. package/tool.json +1 -1
  52. /package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/WHEEL +0 -0
  53. /package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/entry_points.txt +0 -0
  54. /package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/licenses/NOTICE +0 -0
  55. /package/modules/{simplex_localmodels-0.1.0.dev56.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -62,8 +62,21 @@ RESERVE_MAX_BYTES = 8 * GIB
62
62
  # it kills processes (a 73.4 GB plan against 73.8 GB available was aborted on local-119,
63
63
  # 2026-10-29). A shared Mac can sit at warning for hours with tens of GB free, so warning plans
64
64
  # keep this share of the RAM available back instead of refusing.
65
+ PRESSURE_NORMAL = 1
65
66
  PRESSURE_WARN = 2
67
+ PRESSURE_CRITICAL = 4
66
68
  WARN_KEEP_FRACTION = 0.25
69
+ # Dual-tier admission constants for Apple Silicon unified memory:
70
+ # - Hard ceiling: Metal wired ceiling minus live AGX wired usage, scaled by a safety fraction.
71
+ # - Soft budget: scales host keep down for 16 GiB Macs (1.0 GiB + 0.5 GiB display = 1.5 GiB vs
72
+ # 2.5 GiB on 24 GiB+ Macs) and accounts for compressible inactive anonymous pages when macOS
73
+ # VM memory pressure is Normal or Warn (never when Critical).
74
+ SMALL_HOST_THRESHOLD_BYTES = 16 * GIB
75
+ SMALL_HOST_KEEP_BYTES = 1 * GIB
76
+ HARD_OS_FLOOR_BYTES = 1 * GIB
77
+ WIRED_HEADROOM_SAFETY_FRACTION = 0.92
78
+ INACTIVE_ANON_RECLAIM_NORMAL = 0.50
79
+ INACTIVE_ANON_RECLAIM_WARN = 0.25
67
80
 
68
81
 
69
82
  class Metal(TypedDict, total=False):
@@ -75,6 +88,8 @@ class Metal(TypedDict, total=False):
75
88
  recommended_max_working_set_bytes: int | None
76
89
  unified_memory: bool
77
90
  assumed_total_bytes: int # set by ``assume`` (--unified-memory), never by the probe
91
+ wired_limit_bytes: int | None # sysctl iogpu.wired_limit_mb in bytes when explicitly set (> 0)
92
+ gpu_in_use_bytes: int | None # live AGXAccelerator "In use system memory" in bytes
78
93
 
79
94
 
80
95
  def reading(facts: HostFacts) -> Metal | None:
@@ -135,6 +150,132 @@ def working_set_bytes(facts: HostFacts) -> int:
135
150
  return read_working_set(facts) or default_working_set(facts["ram"]["total_bytes"])
136
151
 
137
152
 
153
+ def wired_ceiling_bytes(facts: HostFacts) -> int:
154
+ """Effective Metal wired ceiling: explicit ``iogpu.wired_limit_mb`` when set, else
155
+ ``recommendedMaxWorkingSetSize``, else Apple's default share of physical RAM."""
156
+ found = reading(facts)
157
+ wired = found.get("wired_limit_bytes") if found else None
158
+ if wired is not None and wired > 0:
159
+ return int(wired)
160
+ return working_set_bytes(facts)
161
+
162
+
163
+ def gpu_in_use_reading(facts: HostFacts) -> int | None:
164
+ """Live AGXAccelerator wired GPU usage reading in bytes when available, else None."""
165
+ found = reading(facts)
166
+ in_use = found.get("gpu_in_use_bytes") if found else None
167
+ if in_use is not None and in_use >= 0:
168
+ return int(in_use)
169
+ return None
170
+
171
+
172
+ def gpu_in_use_bytes(facts: HostFacts) -> int:
173
+ """Live system-wide GPU wired usage in bytes: AGXAccelerator reading when available,
174
+ otherwise the non-cached resident memory of observed Metal inference processes."""
175
+ direct = gpu_in_use_reading(facts)
176
+ if direct is not None:
177
+ return direct
178
+ return sum(
179
+ max(0, int(p.get("used_bytes") or 0) - int(p.get("cached_bytes") or 0))
180
+ for p in _metal_processes(facts)
181
+ )
182
+
183
+
184
+ def is_critical_pressure(facts: HostFacts) -> bool:
185
+ """True when macOS ``kern.memorystatus_vm_pressure_level`` reports Critical (4)."""
186
+ level = facts["ram"].get("pressure_level")
187
+ return level is not None and level not in (PRESSURE_NORMAL, PRESSURE_WARN)
188
+
189
+
190
+ def wired_headroom_bytes(facts: HostFacts) -> int:
191
+ """Hard Metal wired headroom ceiling for new allocations:
192
+ ``min((wired_ceiling - gpu_in_use) * WIRED_HEADROOM_SAFETY_FRACTION, physical_safety_cap)``,
193
+ or 0 off Apple Silicon or under Critical VM memory pressure."""
194
+ if not supported(facts) or is_critical_pressure(facts):
195
+ return 0
196
+ ceiling = wired_ceiling_bytes(facts)
197
+ in_use = gpu_in_use_bytes(facts)
198
+ wired_room = int(max(0, ceiling - in_use) * WIRED_HEADROOM_SAFETY_FRACTION)
199
+ total = int(facts["ram"]["total_bytes"])
200
+ wired_ram = facts["ram"].get("wired_bytes")
201
+ if wired_ram is not None and wired_ram >= 0:
202
+ phys_cap = max(0, total - int(wired_ram) - HARD_OS_FLOOR_BYTES)
203
+ else:
204
+ phys_cap = max(0, total - HOST_KEEP_BYTES)
205
+ return min(wired_room, phys_cap)
206
+
207
+
208
+ def inactive_anon_bytes(facts: HostFacts) -> int:
209
+ """Inactive anonymous memory in bytes from ``facts['ram']`` when present, else 0."""
210
+ ram = facts["ram"]
211
+ direct = ram.get("inactive_anon_bytes")
212
+ if direct is not None and direct >= 0:
213
+ return int(direct)
214
+ req = (
215
+ "active_bytes",
216
+ "inactive_bytes",
217
+ "file_backed_bytes",
218
+ "anonymous_bytes",
219
+ "purgeable_bytes",
220
+ )
221
+ if all(ram.get(k) is not None for k in req):
222
+ active = max(0, int(ram["active_bytes"]))
223
+ inactive = max(0, int(ram["inactive_bytes"]))
224
+ speculative = max(0, int(ram.get("speculative_bytes") or 0))
225
+ file_backed = max(0, int(ram["file_backed_bytes"]))
226
+ anonymous = max(0, int(ram["anonymous_bytes"]))
227
+ purgeable = max(0, int(ram["purgeable_bytes"]))
228
+ non_purgeable_anon = max(0, anonymous - purgeable)
229
+ lower = max(0, inactive - max(0, file_backed - speculative))
230
+ upper = min(inactive, non_purgeable_anon)
231
+ if active + inactive > 0:
232
+ est = int(non_purgeable_anon * (inactive / (active + inactive)))
233
+ return max(lower, min(upper, est))
234
+ return upper
235
+ return 0
236
+
237
+
238
+ def reclaimable_inactive_anon_bytes(facts: HostFacts) -> int:
239
+ """Estimated compressible/reclaimable share of inactive anonymous pages on macOS.
240
+ Zero when pressure is Critical or when no inactive anonymous breakdown was probed."""
241
+ if is_critical_pressure(facts):
242
+ return 0
243
+ anon = inactive_anon_bytes(facts)
244
+ if anon <= 0:
245
+ return 0
246
+ level = facts["ram"].get("pressure_level")
247
+ factor = INACTIVE_ANON_RECLAIM_WARN if level == PRESSURE_WARN else INACTIVE_ANON_RECLAIM_NORMAL
248
+ raw = int(anon * factor)
249
+ ram = facts["ram"]
250
+ total = int(ram["total_bytes"])
251
+ avail = int(ram["available_bytes"])
252
+ wired = ram.get("wired_bytes")
253
+ compressed = ram.get("compressed_bytes")
254
+ if wired is not None and wired >= 0:
255
+ hard_used = int(wired) + max(0, int(compressed or 0)) + HARD_OS_FLOOR_BYTES
256
+ max_avail = max(0, total - hard_used)
257
+ else:
258
+ max_avail = max(0, total - HOST_KEEP_BYTES)
259
+ return min(raw, max(0, max_avail - avail))
260
+
261
+
262
+ def soft_host_keep_bytes(facts: HostFacts) -> int:
263
+ """Soft host/gateway RAM reserve for library admission: 1 GiB on <=16 GiB Macs, 2 GiB above."""
264
+ total = int(facts["ram"]["total_bytes"])
265
+ return SMALL_HOST_KEEP_BYTES if 0 < total <= SMALL_HOST_THRESHOLD_BYTES else HOST_KEEP_BYTES
266
+
267
+
268
+ def soft_available_bytes(facts: HostFacts) -> int:
269
+ """Soft available unified memory: ``pressured`` available bytes plus reclaimable inactive
270
+ anonymous headroom (0 under Critical pressure)."""
271
+ if is_critical_pressure(facts):
272
+ return 0
273
+ pressured_facts, _ = pressured(facts)
274
+ base_avail = int(pressured_facts["ram"]["available_bytes"])
275
+ reclaim = reclaimable_inactive_anon_bytes(facts)
276
+ return min(int(facts["ram"]["total_bytes"]), base_avail + reclaim)
277
+
278
+
138
279
  def assumed_total(facts: HostFacts) -> int | None:
139
280
  """The unified memory ``assume`` priced these facts at; None for a reading of this Mac."""
140
281
  found = reading(facts)
@@ -22,6 +22,19 @@ from typing import Any
22
22
 
23
23
  OBJC = "/usr/lib/libobjc.A.dylib"
24
24
  METAL = "/System/Library/Frameworks/Metal.framework/Metal"
25
+ _LAST_VM_DETAILS: dict[str, int] = {}
26
+
27
+
28
+ def last_vm_details() -> dict[str, int]:
29
+ """Return the vm_stat byte breakdown recorded by the latest ``available_memory`` call."""
30
+ return dict(_LAST_VM_DETAILS)
31
+
32
+
33
+ def ram_status() -> dict[str, int]:
34
+ """Pop recorded vm_stat breakdown and merge sysctl pressure/swap status for ``probe.collect``."""
35
+ details = dict(_LAST_VM_DETAILS)
36
+ _LAST_VM_DETAILS.clear()
37
+ return {**details, **memory_status()}
25
38
 
26
39
 
27
40
  def available_memory(total_text: str, vm_stat: str) -> tuple[int, int]:
@@ -49,9 +62,163 @@ def available_memory(total_text: str, vm_stat: str) -> tuple[int, int]:
49
62
  available = sum(n for n in pages if n is not None) * int(page[1])
50
63
  if total <= 0 or int(page[1]) <= 0 or available > total:
51
64
  raise OSError("RAM measurement unavailable")
65
+ _LAST_VM_DETAILS.clear()
66
+ _LAST_VM_DETAILS.update(parse_vm_stat_details(vm_stat))
52
67
  return total, available
53
68
 
54
69
 
70
+ def _vm_stat_counts(vm_stat: str) -> tuple[int, dict[str, int]] | None:
71
+ """Parse page size and integer page counts from macOS ``vm_stat`` output."""
72
+ page = re.search(r"page size of (\d+) bytes\)", vm_stat)
73
+ if not page:
74
+ return None
75
+ page_size = int(page[1])
76
+ if page_size <= 0:
77
+ return None
78
+ counts: dict[str, int] = {}
79
+ for match in re.finditer(
80
+ r"^([A-Za-z][A-Za-z0-9 -]+):[ \t]+(\d+)\.[ \t]*$", vm_stat, re.MULTILINE
81
+ ):
82
+ counts[match[1]] = int(match[2])
83
+ return page_size, counts
84
+
85
+
86
+ def parse_vm_stat_details(vm_stat: str) -> dict[str, int]:
87
+ """Byte breakdown of macOS ``vm_stat`` counters, including estimated inactive anonymous memory.
88
+
89
+ Returns an empty dict when ``vm_stat`` is unreadable. Inactive anonymous pages are bounded
90
+ between ``max(0, inactive - max(0, file_backed - speculative))`` and
91
+ ``min(inactive, max(0, anonymous - purgeable))``, estimated proportionally by the inactive
92
+ share of active+inactive paged memory.
93
+ """
94
+ parsed = _vm_stat_counts(vm_stat)
95
+ if parsed is None:
96
+ return {}
97
+ page_size, counts = parsed
98
+ mapping = {
99
+ "Pages free": "free_bytes",
100
+ "Pages active": "active_bytes",
101
+ "Pages inactive": "inactive_bytes",
102
+ "Pages speculative": "speculative_bytes",
103
+ "Pages wired down": "wired_bytes",
104
+ "Pages purgeable": "purgeable_bytes",
105
+ "File-backed pages": "file_backed_bytes",
106
+ "Anonymous pages": "anonymous_bytes",
107
+ "Pages occupied by compressor": "compressed_bytes",
108
+ }
109
+ details = {key: counts[label] * page_size for label, key in mapping.items() if label in counts}
110
+ req = (
111
+ "Pages active",
112
+ "Pages inactive",
113
+ "File-backed pages",
114
+ "Anonymous pages",
115
+ "Pages purgeable",
116
+ )
117
+ if all(label in counts for label in req):
118
+ active = counts["Pages active"]
119
+ inactive = counts["Pages inactive"]
120
+ speculative = counts.get("Pages speculative", 0)
121
+ file_backed = counts["File-backed pages"]
122
+ anonymous = counts["Anonymous pages"]
123
+ purgeable = counts["Pages purgeable"]
124
+ non_purgeable_anon = max(0, anonymous - purgeable)
125
+ lower = max(0, inactive - max(0, file_backed - speculative))
126
+ upper = min(inactive, non_purgeable_anon)
127
+ if active + inactive > 0:
128
+ est = int(non_purgeable_anon * (inactive / (active + inactive)))
129
+ inactive_anon = max(lower, min(upper, est))
130
+ else:
131
+ inactive_anon = upper
132
+ details["inactive_anon_bytes"] = inactive_anon * page_size
133
+ return details
134
+
135
+
136
+ def vm_memory_details() -> dict[str, int]:
137
+ """Read macOS ``vm_stat`` breakdown; returns empty dict off macOS or on error."""
138
+ try:
139
+ result = subprocess.run(
140
+ ["/usr/bin/vm_stat"],
141
+ capture_output=True,
142
+ text=True,
143
+ timeout=10,
144
+ check=False,
145
+ )
146
+ if result.returncode:
147
+ return {}
148
+ return parse_vm_stat_details(result.stdout)
149
+ except (OSError, ValueError, subprocess.TimeoutExpired):
150
+ return {}
151
+
152
+
153
+ def parse_wired_limit_mb(text: str) -> int | None:
154
+ """Parse ``sysctl -n iogpu.wired_limit_mb`` into bytes; None when 0, unset, or invalid."""
155
+ try:
156
+ mb = int(text.strip())
157
+ except ValueError:
158
+ return None
159
+ return (mb << 20) if mb > 0 else None
160
+
161
+
162
+ def wired_limit_bytes() -> int | None:
163
+ """Read ``iogpu.wired_limit_mb`` in bytes when set (> 0), else None."""
164
+ try:
165
+ result = subprocess.run(
166
+ ["/usr/sbin/sysctl", "-n", "iogpu.wired_limit_mb"],
167
+ capture_output=True,
168
+ text=True,
169
+ timeout=10,
170
+ check=False,
171
+ )
172
+ if result.returncode:
173
+ return None
174
+ return parse_wired_limit_mb(result.stdout)
175
+ except (OSError, ValueError, subprocess.TimeoutExpired):
176
+ return None
177
+
178
+
179
+ def parse_agx_in_use_bytes(text: str) -> int | None:
180
+ """Parse live AGXAccelerator ``In use system memory`` bytes from ``ioreg`` output."""
181
+ matches = [int(m) for m in re.findall(r'"In use system memory"\s*=\s*(\d+)', text)]
182
+ return max(matches) if matches else None
183
+
184
+
185
+ def agx_in_use_bytes() -> int | None:
186
+ """Read live system-wide Apple GPU wired usage via ``ioreg -r -c AGXAccelerator``."""
187
+ try:
188
+ result = subprocess.run(
189
+ ["/usr/sbin/ioreg", "-r", "-c", "AGXAccelerator"],
190
+ capture_output=True,
191
+ text=True,
192
+ timeout=10,
193
+ check=False,
194
+ )
195
+ if result.returncode:
196
+ return None
197
+ return parse_agx_in_use_bytes(result.stdout)
198
+ except (OSError, ValueError, subprocess.TimeoutExpired):
199
+ return None
200
+
201
+
202
+ def metal_telemetry() -> dict[str, int]:
203
+ """Optional Apple Silicon wired-limit and AGX live-usage telemetry for ``facts['metal']``."""
204
+ found: dict[str, int] = {}
205
+ wired = wired_limit_bytes()
206
+ if wired is not None:
207
+ found["wired_limit_bytes"] = wired
208
+ in_use = agx_in_use_bytes()
209
+ if in_use is not None:
210
+ found["gpu_in_use_bytes"] = in_use
211
+ return found
212
+
213
+
214
+ def metal_device_with_telemetry() -> dict[str, Any] | None:
215
+ """Read ``metal_device()`` and attach available wired-limit/AGX telemetry when present."""
216
+ device = metal_device()
217
+ if device is not None:
218
+ device.update(metal_telemetry())
219
+ return device
220
+
221
+
55
222
  def memory_status() -> dict[str, int]:
56
223
  """Missing sysctl readings stay unknown, not zero pressure or zero swap."""
57
224
  values = {}
@@ -712,9 +712,9 @@ def collect(
712
712
  "python": platform.python_version(),
713
713
  "cpu": {"model": _cpu_model(), "logical_cores": os.cpu_count()},
714
714
  "ram": {
715
+ **(metal_probe.ram_status() if sys.platform == "darwin" else {}),
715
716
  "total_bytes": ram_total,
716
717
  "available_bytes": ram_avail,
717
- **(metal_probe.memory_status() if sys.platform == "darwin" else {}),
718
718
  },
719
719
  "gpu_vendor_class": vendor,
720
720
  "nvidia": nvidia,
@@ -730,7 +730,7 @@ def collect(
730
730
  "shared_libraries": shared_libraries() if is_linux else {},
731
731
  }
732
732
  if facts["platform"] == "darwin" and facts["arch"] == "arm64":
733
- facts["metal"] = metal_probe.metal_device()
733
+ facts["metal"] = metal_probe.metal_device_with_telemetry()
734
734
  if facts["platform"] == "win32" and gpus and (gpu_procs := win_probe.gpu_process_memory()):
735
735
  facts["gpu_processes"] = gpu_procs
736
736
  return facts
@@ -193,7 +193,12 @@ def recommendation(
193
193
  break
194
194
  if not fitting:
195
195
  return None
196
- entry_id, index = llm_rank.choose(fitting, "smartest", fallback_ids={fallback.id})
196
+ slow_ids = {
197
+ entry_id for (_, tok_s), entry_id, _ in fitting if tok_s < cat.USABLE_FLOOR_TOK_S
198
+ }
199
+ entry_id, index = llm_rank.choose(
200
+ fitting, "smartest", fallback_ids={fallback.id}, slow_ids=slow_ids
201
+ )
197
202
  if entry_id != fallback.id:
198
203
  return None
199
204
  fallback_placement = next((p for p in host if p.id == f"gpu:{index}"), None)