Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

Detect Metal GPUs in macOS resource plans

Karel Moravec7dfdb05a8307
diff --git a/c/resource_plan.py b/c/resource_plan.py
index 7a2fe3b0..ff81097a 100644
--- a/c/resource_plan.py
+++ b/c/resource_plan.py
@@ -427,6 +427,8 @@ SSD_PROBE_PENDING = {
def discover_gpus():
+ if sys.platform == "darwin":
+ return _discover_metal_gpus()
# NVIDIA first; if there are none (or no nvidia-smi), fall back to ROCm/HIP so
# a working AMD engine isn't planned CPU-only and --gpu N stops failing (#662).
devices = _discover_nvidia_gpus()
@@ -435,6 +437,33 @@ def discover_gpus():
return _discover_amd_gpus()
+def _discover_metal_gpus():
+ """Return Apple Metal devices without pretending unified RAM is VRAM."""
+ try:
+ result = subprocess.run(
+ ["system_profiler", "SPDisplaysDataType", "-json"],
+ text=True, capture_output=True, check=True, timeout=10)
+ displays = json.loads(result.stdout).get("SPDisplaysDataType", [])
+ except (OSError, subprocess.SubprocessError, ValueError, TypeError):
+ return []
+ devices = []
+ for index, display in enumerate(displays):
+ if not isinstance(display, dict):
+ continue
+ metal = display.get("spdisplays_mtlgpufamilysupport")
+ if not metal:
+ continue
+ name = display.get("sppci_model") or display.get("_name")
+ if not isinstance(name, str) or not name:
+ continue
+ # Apple Silicon has one unified pool. Its free capacity cannot be used
+ # as an independent VRAM budget, so retain device identity only.
+ devices.append({"index": index, "name": name,
+ "total_bytes": 0, "free_bytes": None,
+ "unified_memory": True, "backend": "metal"})
+ return devices
+
+
def _discover_nvidia_gpus():
command = ["nvidia-smi", "--query-gpu=index,name,memory.total,memory.free",
"--format=csv,noheader,nounits"]
@@ -1219,12 +1248,20 @@ def format_plan(plan):
f"cap {tiers['ram']['cache_slots_per_layer']}/layer"]
vram = tiers["vram"]
if vram["devices"]:
- names = ", ".join(
- f"{gpu['index']}:{gpu['name']}"
- + ("" if plans_placement(gpu) else " (identity only)")
- for gpu in vram["devices"])
- lines.append(f"VRAM {format_bytes(vram['budget_bytes'])} hot tier · "
- f"~{vram['expert_capacity']} experts · {names}")
+ metal_identity = [gpu for gpu in vram["devices"]
+ if gpu.get("backend") == "metal"
+ and gpu.get("free_bytes") is None]
+ if len(metal_identity) == len(vram["devices"]):
+ names = ", ".join(f"{gpu['index']}:{gpu['name']}"
+ for gpu in metal_identity)
+ lines.append(f"Metal {names} · unified memory · no independent VRAM budget")
+ else:
+ names = ", ".join(
+ f"{gpu['index']}:{gpu['name']}"
+ + ("" if plans_placement(gpu) else " (identity only)")
+ for gpu in vram["devices"])
+ lines.append(f"VRAM {format_bytes(vram['budget_bytes'])} hot tier · "
+ f"~{vram['expert_capacity']} experts · {names}")
else:
# Backend-neutral, matching the accelerator wording #903 settled on:
# an AMD or Intel host that finds nothing is not "no NVIDIA device".
diff --git a/c/tests/test_resource_plan.py b/c/tests/test_resource_plan.py
index ede6e88c..2d0086ea 100644
--- a/c/tests/test_resource_plan.py
+++ b/c/tests/test_resource_plan.py
@@ -13,6 +13,7 @@ from resource_plan import (
analyze_model,
build_plan,
cpu_socket_count,
+ discover_gpus,
environment_for_plan,
format_plan,
memory_available,
@@ -112,6 +113,28 @@ class ResourcePlanTest(unittest.TestCase):
self.assertFalse(any("jointly constrained" in warning
for warning in plan["warnings"]))
+ def test_macos_discovers_metal_gpu_without_cuda_or_rocm_probes(self):
+ output = json.dumps({"SPDisplaysDataType": [{
+ "_name": "Apple M1 Pro",
+ "sppci_model": "Apple M1 Pro",
+ "spdisplays_mtlgpufamilysupport": "spdisplays_metal4",
+ }]})
+ result = subprocess.CompletedProcess(args=[], returncode=0,
+ stdout=output, stderr="")
+ with mock.patch.object(sys, "platform", "darwin"), \
+ mock.patch("resource_plan.subprocess.run", return_value=result) as run:
+ devices = discover_gpus()
+ self.assertEqual(devices, [{"index": 0, "name": "Apple M1 Pro",
+ "total_bytes": 0, "free_bytes": None,
+ "unified_memory": True, "backend": "metal"}])
+ self.assertEqual(run.call_args.args[0],
+ ["system_profiler", "SPDisplaysDataType", "-json"])
+ plan = build_plan(self.model, ram_gb=16, available_memory=32 * GB,
+ available_disk=1, gpus=devices, physical_cpus=8,
+ cpu_sockets=1)
+ self.assertIn("Metal 0:Apple M1 Pro · unified memory",
+ format_plan(plan))
+
def test_glm53_auto_tune_does_not_emit_generic_inert_knobs(self):
from resource_plan import _auto_tune