Repository navigation
fix(local_diffusion): use MPS on Apple Silicon and a reachable default model - #897
Conversation
…t model Device selection only checked CUDA, so Macs fell back to CPU in fp32. Pick cuda, then mps (fp16), then cpu, and share that with image_gen's local backend. The default stabilityai/stable-diffusion-2-1-base repo was removed from the Hub and returns 401; default to the sd2-community mirror. Fixes OpenMontageInc#886
There was a problem hiding this comment.
🟡 Changes recommended
Seeded MPS requests can fail on supported older PyTorch versions because both image-generation paths use an unsupported MPS generator instead of a CPU fallback.
1 open issue
What changed in this PR
This PR addresses #886 by enabling Apple Silicon acceleration for local image generation and replacing the unavailable default model.
Changes:
- Share CUDA → MPS → CPU device selection across both local generation tools.
- Use the community Stable Diffusion 2.1 mirror as the default model.
- Add mocked regression tests for device selection, precision, and default-model handling.
| File | Description |
|---|---|
tools/graphics/local_diffusion.py |
Defines shared device selection and updates the default model. |
tools/graphics/image_gen.py |
Reuses the shared defaults and device selection for local generation. |
tests/tools/test_local_diffusion_device.py |
Adds regression coverage using fake Torch and Diffusers modules. |
Review effort: Balanced
| try: | ||
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
| dtype = torch.float16 if device == "cuda" else torch.float32 | ||
| device, dtype = select_device(torch) |
There was a problem hiding this comment.
Good catch. Fixed in 82d96e2: seeding goes through a CPU generator when the pipeline is on MPS, in both local_diffusion.py and image_gen.py. The fake now records the generator device and there's a seeded ImageGen case on MPS.
torch.Generator(device="mps") isn't supported on older PyTorch, which requirements still allow, so seeded requests on Apple Silicon failed. Create the generator on CPU when the pipeline runs on MPS.
|
Good catch, thanks. Older torch releases do raise on I added a small In the test, the fake |
calesthio
left a comment
There was a problem hiding this comment.
Reviewed commit 82d96e2. No blocking issues found. All six focused regression tests passed locally, and CI passed with 2,234 tests. The earlier MPS seeded-generator issue is fixed in both paths. Actual Apple Silicon image generation was not independently tested in this Windows review environment.

Summary
local_diffusion only checked for CUDA, so on Apple Silicon it always ran on CPU in fp32. The default model id (stabilityai/stable-diffusion-2-1-base) was also removed from the HF Hub and now returns 401, so a fresh install can't generate anything.
Fix
Added a small select_device() helper that picks cuda, then mps (fp16), then cpu (fp32), and used it in both local_diffusion and the local backend of image_gen, which had the same copy of the logic. Switched the default model to the sd2-community/stable-diffusion-2-1-base mirror, which has the same weights.
Testing
Fixes #886