MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / should_use_mlx

Function should_use_mlx

optillm/inference.py:234–269  ·  view source on GitHub ↗

Determine if a model should use MLX instead of PyTorch

(model_id: str)

Source from the content-addressed store, hash-verified

232 return platform.system() == "Darwin" and platform.machine() == "arm64"
233
234def 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
271def suggest_mlx_alternative(model_id: str) -> str:
272 """Suggest MLX alternative for a given model"""

Callers 2

is_mlx_modelMethod · 0.85
get_pipelineMethod · 0.85

Calls 2

is_apple_siliconFunction · 0.85
suggest_mlx_alternativeFunction · 0.85

Tested by

no test coverage detected