Skip to content

feat: add experimental macOS MPS inference support - #36

Open
yuhai-china wants to merge 2 commits into
boogu-project:mainfrom
yuhai-china:mps-support
Open

feat: add experimental macOS MPS inference support#36
yuhai-china wants to merge 2 commits into
boogu-project:mainfrom
yuhai-china:mps-support

Conversation

@yuhai-china

@yuhai-china yuhai-china commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Add experimental macOS MPS (Metal Performance Shaders) inference support for Boogu-Image, enabling inference on Apple Silicon Macs without CUDA.

Changes

Device Support

  • boogu/utils/validator_utils.py: Add mps as a valid device argument
  • boogu/models/transformers/transformer_boogu.py: Detect mps for attention processor selection
  • boogu/pipelines/boogu/pipeline_boogu.py: Default device from _execution_device instead of hardcoded "cuda"

MPS Workaround

  • boogu/pipelines/boogu/pipeline_boogu_turbo.py: Workaround for PyTorch MPS backend bug where @torch.no_grad() triggers an MPSGraph assertion during the first transformer forward. Temporarily enabling gradient computation bypasses this bug.

Verification

Device: Apple Silicon (MPS), macOS, PyTorch 2.11.0, Model: Boogu-Image-0.1-Turbo (4-step DMD)

Resolution Time Result
512×512 ~10s ✅ Stable
640×640 ~26s+ ❌ MPS backend crash on step 3
1024×768 ~19s ❌ MPS backend crash on step 2
1024×1024 - ❌ MPS backend crash on step 1

Sample Outputs (512×512)

cat
fuchun

Compatibility

yuhai added 2 commits July 26, 2026 08:15
- Allow 'mps' as a valid device in device validator
- Auto-detect device from _execution_device instead of hardcoding 'cuda'
- Workaround MPS Graph assertion crash under @torch.no_grad() by
  temporarily enabling grad during DMD processing loop
- Add type annotations for MPS across pipeline components

Verified: Turbo T2I 512x512, 4-step DMD completed in ~10s on MPS.
Reference: pytorch/pytorch issues #114532, #148194, #174861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants