11import shutil
22import subprocess
3+ import platform
34
45import onnxruntime as ort
56import psutil
@@ -35,11 +36,60 @@ def detect_physical_gpu() -> list[str]:
3536 return gpu_names
3637
3738
39+ def detect_apple_silicon () -> str | None :
40+ if platform .system () != "Darwin" :
41+ return None
42+ if platform .machine () != "arm64" :
43+ return None
44+
45+ sysctl = shutil .which ("sysctl" )
46+ if sysctl :
47+ try :
48+ result = subprocess .run (
49+ [sysctl , "-n" , "machdep.cpu.brand_string" ],
50+ capture_output = True ,
51+ text = True ,
52+ check = True ,
53+ timeout = 5 ,
54+ )
55+ chip_name = result .stdout .strip ()
56+ if chip_name :
57+ return chip_name
58+ except (OSError , subprocess .SubprocessError ):
59+ pass
60+
61+ proc = platform .processor ()
62+ if proc :
63+ return proc
64+
65+ return "Apple Silicon"
66+
67+
68+ def detect_apple_silicon_tier () -> str | None :
69+ chip = detect_apple_silicon ()
70+ if chip is None :
71+ return None
72+
73+ chip_lower = chip .lower ()
74+
75+ # Base M1 and M2 chips (without Pro/Max/Ultra modifiers) are "small"
76+ if any (base in chip_lower for base in ["m1" , "m2" ]):
77+ if not any (mod in chip_lower for mod in ["pro" , "max" , "ultra" ]):
78+ return "small"
79+
80+ # Default to medium for all other Apple Silicon (Pro/Max/Ultra, M3+, and future chips)
81+ return "medium"
82+
83+
3884def detect_hardware_tier () -> str :
3985 """
4086 Detect system hardware to recommend the best YOLO/FaceNet model tier.
4187 Returns: 'nano', 'small', or 'medium'
4288 """
89+ apple_tier = detect_apple_silicon_tier ()
90+ if apple_tier is not None :
91+ return apple_tier
92+
4393 # Check RAM in GB
4494 ram_gb = psutil .virtual_memory ().total / (1024 ** 3 )
4595
@@ -66,6 +116,7 @@ def get_hardware_info() -> dict:
66116 "ram_gb" : round (psutil .virtual_memory ().total / (1024 ** 3 ), 2 ),
67117 "gpu_detected" : bool (gpu_names ),
68118 "gpu_names" : gpu_names ,
119+ "apple_silicon" : detect_apple_silicon (),
69120 "available_providers" : ort .get_available_providers (),
70121 "recommended_tier" : detect_hardware_tier (),
71122 }
0 commit comments