Feat: Improve Model Tier Recommendation for Apple Silicon#1299
Feat: Improve Model Tier Recommendation for Apple Silicon#1299rohan-pandeyy wants to merge 3 commits into
Conversation
WalkthroughThis PR adds Apple Silicon hardware detection to improve model tier recommendations on Apple Silicon Macs. The backend now detects Apple Silicon chips, determines appropriate hardware tiers (small/medium), and exposes chip information. The frontend displays the detected chip name in the onboarding UI hardware summary. ChangesApple Silicon Detection Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/app/utils/hardware_detect.py`:
- Around line 1-6: This module uses PEP 604 union syntax (e.g., annotations like
"str | None") but lacks the compatibility import; add "from __future__ import
annotations" as the very first line of backend/app/utils/hardware_detect.py
(before any other imports such as shutil, subprocess, platform, onnxruntime or
psutil) so functions and type hints in this file (e.g., any that use "|" unions)
work on Python 3.9.
- Around line 68-81: The function detect_apple_silicon_tier currently returns
"medium" by default for any Apple Silicon not matched as base M1/M2 small, which
contradicts issue `#1292`; update detect_apple_silicon_tier (using the chip
variable from detect_apple_silicon()) so that the final/default return is
"small" instead of "medium" while keeping existing logic that explicitly
classifies Pro/Max/Ultra as non-small.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 74b81545-d40a-4ea0-9ee8-f3535db5b6fd
📒 Files selected for processing (3)
backend/app/utils/hardware_detect.pyfrontend/src/components/OnboardingSteps/AIModelSetupStep.tsxfrontend/src/types/models.ts
| import shutil | ||
| import subprocess | ||
| import platform | ||
|
|
||
| import onnxruntime as ort | ||
| import psutil |
There was a problem hiding this comment.
Add from __future__ import annotations for 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 requires from __future__ import annotations when using X | Y syntax.
🔧 Proposed fix
+from __future__ import annotations
+
import shutil
import subprocess
import platform📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import shutil | |
| import subprocess | |
| import platform | |
| import onnxruntime as ort | |
| import psutil | |
| from __future__ import annotations | |
| import shutil | |
| import subprocess | |
| import platform | |
| import onnxruntime as ort | |
| import psutil |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/app/utils/hardware_detect.py` around lines 1 - 6, This module uses
PEP 604 union syntax (e.g., annotations like "str | None") but lacks the
compatibility import; add "from __future__ import annotations" as the very first
line of backend/app/utils/hardware_detect.py (before any other imports such as
shutil, subprocess, platform, onnxruntime or psutil) so functions and type hints
in this file (e.g., any that use "|" unions) work on Python 3.9.
| 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" |
There was a problem hiding this comment.
Default tier for unknown Apple Silicon contradicts requirements.
Line 81 defaults unknown Apple Silicon chips to "medium", but issue #1292 explicitly requires unknown Apple Silicon to default to "small". This could lead to over-recommending model sizes for future or unrecognized chips.
📝 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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" | |
| 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" | |
| # 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" |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/app/utils/hardware_detect.py` around lines 68 - 81, The function
detect_apple_silicon_tier currently returns "medium" by default for any Apple
Silicon not matched as base M1/M2 small, which contradicts issue `#1292`; update
detect_apple_silicon_tier (using the chip variable from detect_apple_silicon())
so that the final/default return is "small" instead of "medium" while keeping
existing logic that explicitly classifies Pro/Max/Ultra as non-small.
Closes #1292
This pull request adds improved detection and reporting of Apple Silicon hardware in both the backend and frontend. The main changes include new utility functions to detect Apple Silicon and its performance tier, updating the hardware info API to include this data, and adjusting the frontend to display Apple Silicon chip names when present.
Apple Silicon Detection and Tiering:
detect_apple_silicon()anddetect_apple_silicon_tier()functions to identify Apple Silicon chips and classify them as "small" (base M1/M2) or "medium" (Pro/Max/Ultra, M3+, or future chips) inhardware_detect.py.detect_hardware_tier()to return the Apple Silicon tier if detected, improving model recommendations for Mac users.Backend API Enhancements:
get_hardware_info()to include anapple_siliconfield in the returned dictionary, exposing chip information to the frontend.Frontend and Type Updates:
HardwareInfoTypeScript interface to include the newapple_siliconfield.AIModelSetupStep.tsxto show the Apple Silicon chip name (if present) instead of GPU info, improving clarity for Mac users.Screenshots/Recordings:
AI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: Claude, Gemini
Checklist
Summary by CodeRabbit
New Features