-
-
Notifications
You must be signed in to change notification settings - Fork 620
Feat: Improve Model Tier Recommendation for Apple Silicon #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import platform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import onnxruntime as ort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import psutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,11 +36,60 @@ def detect_physical_gpu() -> list[str]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return gpu_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def detect_apple_silicon() -> str | None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if platform.system() != "Darwin": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if platform.machine() != "arm64": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sysctl = shutil.which("sysctl") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sysctl: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = subprocess.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [sysctl, "-n", "machdep.cpu.brand_string"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_output=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout=5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chip_name = result.stdout.strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if chip_name: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return chip_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except (OSError, subprocess.SubprocessError): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| proc = platform.processor() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if proc: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return proc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "Apple Silicon" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def detect_apple_silicon_tier() -> str | None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chip = detect_apple_silicon() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if chip is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chip_lower = chip.lower() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Base M1 and M2 chips (without Pro/Max/Ultra modifiers) are "small" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if any(base in chip_lower for base in ["m1", "m2"]): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not any(mod in chip_lower for mod in ["pro", "max", "ultra"]): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "small" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Default to medium for all other Apple Silicon (Pro/Max/Ultra, M3+, and future chips) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "medium" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default tier for unknown Apple Silicon contradicts requirements. Line 81 defaults unknown Apple Silicon chips to 📝 Proposed fix to match requirements- # Default to medium for all other Apple Silicon (Pro/Max/Ultra, M3+, and future chips)
- return "medium"
+ # M3+, Pro/Max/Ultra variants are medium
+ # M3, M4, and newer chips (with or without modifiers) should be medium
+ if any(chip in chip_lower for chip in ["m3", "m4", "m5", "m6", "m7", "m8", "m9"]):
+ return "medium"
+ if any(mod in chip_lower for mod in ["pro", "max", "ultra"]):
+ return "medium"
+
+ # Default to small for unknown Apple Silicon chips
+ return "small"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def detect_hardware_tier() -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Detect system hardware to recommend the best YOLO/FaceNet model tier. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: 'nano', 'small', or 'medium' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apple_tier = detect_apple_silicon_tier() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if apple_tier is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return apple_tier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check RAM in GB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ram_gb = psutil.virtual_memory().total / (1024**3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -66,6 +116,7 @@ def get_hardware_info() -> dict: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "ram_gb": round(psutil.virtual_memory().total / (1024**3), 2), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpu_detected": bool(gpu_names), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpu_names": gpu_names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "apple_silicon": detect_apple_silicon(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "available_providers": ort.get_available_providers(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "recommended_tier": detect_hardware_tier(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
from __future__ import annotationsfor Python 3.9 compatibility.The file uses PEP 604 union syntax (
str | None) in type hints but is missing the required future import for Python 3.9 compatibility. Based on learnings, this repo targets Python 3.9 minimum and requiresfrom __future__ import annotationswhen usingX | Ysyntax.🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents