Determine if a model should use MLX instead of PyTorch
(model_id: str)
| 232 | return platform.system() == "Darwin" and platform.machine() == "arm64" |
| 233 | |
| 234 | def should_use_mlx(model_id: str) -> bool: |
| 235 | """Determine if a model should use MLX instead of PyTorch""" |
| 236 | if not MLX_AVAILABLE or not is_apple_silicon(): |
| 237 | return False |
| 238 | |
| 239 | # Models that should use MLX |
| 240 | mlx_patterns = [ |
| 241 | "mlx-community/", |
| 242 | "mlx-", |
| 243 | "-mlx-" |
| 244 | ] |
| 245 | |
| 246 | # Known problematic models that should prefer MLX on Apple Silicon |
| 247 | problematic_models = [ |
| 248 | "Qwen/Qwen3-", |
| 249 | "google/gemma-3-", |
| 250 | "google/gemma3-" |
| 251 | ] |
| 252 | |
| 253 | model_lower = model_id.lower() |
| 254 | |
| 255 | # Direct MLX model detection |
| 256 | for pattern in mlx_patterns: |
| 257 | if pattern.lower() in model_lower: |
| 258 | return True |
| 259 | |
| 260 | # Problematic model detection |
| 261 | for pattern in problematic_models: |
| 262 | if pattern.lower() in model_lower: |
| 263 | logger.warning(f"Model {model_id} detected as potentially problematic with MPS backend") |
| 264 | suggested_mlx = suggest_mlx_alternative(model_id) |
| 265 | logger.warning(f"Consider using MLX model: {suggested_mlx}") |
| 266 | # Don't auto-switch, but recommend |
| 267 | return False |
| 268 | |
| 269 | return False |
| 270 | |
| 271 | def suggest_mlx_alternative(model_id: str) -> str: |
| 272 | """Suggest MLX alternative for a given model""" |
no test coverage detected