Skip to content

Add native Metal acceleration for Apple Silicon inference SD1.5 First - #17469

Open
dmikey wants to merge 17 commits into
AUTOMATIC1111:devfrom
dmikey:dev
Open

Add native Metal acceleration for Apple Silicon inference SD1.5 First#17469
dmikey wants to merge 17 commits into
AUTOMATIC1111:devfrom
dmikey:dev

Conversation

@dmikey

@dmikey dmikey commented Aug 12, 2026

Copy link
Copy Markdown

Description

SEEKING FEEDBACK

This PR adds a focused Apple Silicon acceleration path to Automatic1111 while preserving its existing UI, API, models, samplers, LoRA syntax, extensions, and PyTorch fallbacks. Currently focused on SD1.5 and Apple M1.
~ 40% improvement for LCM based models, than out of the box settings.

Changes

  • Adds shape-selective Metal Flash Attention for measured SD 1.x workloads.
  • Coalesces native attention work onto PyTorch’s current MPS command buffer.
  • Adds unified-memory-aware attention routing and dynamically sized sub-quadratic attention chunks.
  • Streams chunked online softmax results to reduce temporary memory.
  • Removes obsolete MPS clones and precision workarounds on modern PyTorch.
  • Adds native fused FP16 GroupNorm + SiLU and exact-parity GEGLU kernels.
  • Enables the validated FP16 VAE path on M1-family Macs while retaining Automatic1111’s FP32 NaN retry.
  • Adds opt-in MPS stage profiling, UNet capture tooling, benchmarks, and focused tests.
  • Adds conservative fallback and kill-switch behavior for unsupported inputs or native runtime failures.
  • Documents measured results, rejected experiments, compatibility limits, and future work.
  • Fixes Ruff validation for the MPS UNet benchmark.

The primary optimized workload is Stable Diffusion 1.x with short DPM++ SDE/Karras schedules on Apple Silicon. Unsupported architectures, shapes, dtypes, training paths, and extension configurations continue through the existing PyTorch implementation.

Issues

No linked issues are close

Screenshots/videos

automatic1111 automatic1111-metal

Representative M1 measurements are documented in the README including:

  • A recorded 384×640 improvement from 12.8 seconds to 8.7 seconds.
  • A validated FP16 VAE reduction from 8.450 seconds to 7.795 seconds median end-to-end.
  • Exact-parity fused GEGLU savings of approximately 0.12–0.27 seconds in alternating tests.
  • Current warmed 512×512 sampling throughput around 0.72 it/s.

Validation

  • ruff check . using the CI-pinned Ruff 0.3.3: passed.
  • 15 focused MPS, fusion, profiling, and UNet-capture tests: passed.
  • Fixed-seed output validation performed for fused GEGLU and FP16 VAE paths.
  • Native functionality uses isolated startup checks and automatically falls back to PyTorch on failure.
  • Full live-server Automatic1111 test suite has not been run.

Checklist

The focused tests pass, but the complete live-server suite remains to be run.

AI Disclosure

Codex assisted benchmarking and hot path traces were used to find measurable increases in performance for offloading attention, and other MPS attributes.

dmikey added 11 commits August 11, 2026 12:31
…ing instructions

Signed-off-by: Derek Anderson <dmikey@users.noreply.github.com>
… optimization details

Signed-off-by: Derek Anderson <dmikey@users.noreply.github.com>
- Implement opt-in capture of UNet calls for native-backend experiments in mps_unet_capture.py.
- Enhance sd_hijack_unet.py to utilize the new capture functionality for validating outputs.
- Create inspect_mps_unet_capture.py for inspecting captured data and validating replay accuracy.
- Add unit tests for capture functionality in test_mps_unet_capture.py to ensure correct behavior.
- Update state-of-things-next.md with findings from initial capture and performance benchmarks.

Signed-off-by: Derek Anderson <dmikey@users.noreply.github.com>
@dmikey dmikey changed the title Add native Metal acceleration for Apple Silicon inference Add native Metal acceleration for Apple Silicon inference SD1.5 First Aug 12, 2026
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.

1 participant