Skip to content

Conversation

@matthewijordan
Copy link

Summary

Add MPS (Metal Performance Shaders) inference support for Apple Silicon Macs.

Changes

  • Device utilities (mapanything/utils/device.py):

    • get_device(): Auto-detects best available device (CUDA > MPS > CPU)
    • get_device_capabilities(): Query device-specific capabilities (bf16 support)
    • get_amp_dtype(): Device-aware mixed precision dtype selection
    • get_autocast_device_type(): Device type string for torch.autocast
    • is_memory_query_supported(): Check if memory operations like empty_cache() are supported
    • empty_cache(): GPU cache clearing with device check
  • Inference updates:

    • model.py & inference.py: Use device-agnostic autocast/AMP
    • All demo scripts: Use get_device() for auto device selection
    • Gradio app: MPS-aware device handling and memory-safe cache clearing
  • Config updates:

    • moge/default.yaml: Device set to 'auto' for automatic detection

Testing

  • Confirmed working locally on Apple Silicon (MPS device)
  • Ruff linting passes on modified files
  • Backwards compatible with CUDA and CPU inference

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 19, 2026
- Add device utilities (get_device, get_amp_dtype, get_autocast_device_type, is_memory_query_supported)
- Enable MPS device detection and device-agnostic autocast/AMP
- Update all inference scripts to use auto device selection (CUDA > MPS > CPU)
- Update Gradio app and data processing scripts for MPS compatibility
- Add memory-safe cache clearing for CUDA-only operations
@matthewijordan matthewijordan force-pushed the feature/mps-inference-support branch from 2c5e824 to 2ca6e15 Compare January 19, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant