Skip to content

fix(local_diffusion): use MPS on Apple Silicon and a reachable default model - #897

Merged
calesthio merged 2 commits into
OpenMontageInc:mainfrom
thelastbackspace:fix/886-local-diffusion-mps
Nov 7, 2026
Merged

calesthio merged 2 commits into
OpenMontageInc:mainfrom
thelastbackspace:fix/886-local-diffusion-mps

Conversation

@thelastbackspace

Copy link
Copy Markdown
Contributor

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

  • New tests/tools/test_local_diffusion_device.py with fake torch/diffusers modules covering cuda/mps/cpu selection, the default model, and image_gen's local path. 3 of them fail on main, all pass with the fix.
  • make lint
  • pytest tests/ - same pre-existing failures as main, nothing new.

Fixes #886

…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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@thelastbackspace

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. Older torch releases do raise on torch.Generator(device="mps"), and requirements still allow those.

I added a small generator_device() helper in local_diffusion.py that returns "cpu" when the pipeline runs on MPS. Both LocalDiffusion and ImageGen._generate_local use it now. diffusers is fine with a CPU generator on an MPS pipeline, and seeds stay reproducible.

In the test, the fake torch.Generator now raises for "mps" the way old torch does. The MPS case expects a CPU generator, and there's a new seeded ImageGen case on MPS. Both fail on the previous commit and pass now.

@calesthio calesthio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@calesthio
calesthio merged commit 63d1087 into OpenMontageInc:main Nov 7, 2026
1 check passed
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.

local_diffusion: default model id returns 401, and Apple Silicon runs on CPU instead of MPS

3 participants