Skip to main content

coreml-diffusion

Convert diffusion-model checkpoints into Core ML .mlpackage artifacts for the Apple Neural Engine (ANE) — framework-free and standalone.

coreml-diffusion takes a single-file Stable Diffusion checkpoint and produces a Core ML UNet you can run on-device (macOS/iOS) via Core ML, in a Python pipeline, or load into any host that consumes the artifact.

What this is

A standalone toolkit and knowledge base for running diffusion models on the Apple Neural Engine via Core ML. The niche is diffusion on the ANE: low-power, GPU-free, embeddable in a Swift/iOS app. ANE is the differentiator — this is about feasibility and power efficiency for SD1.5/SDXL on ANE, not a raw-throughput claim against desktop GPUs.

The power-efficiency claim is measured: in a cross-backend benchmark the ct9 converter here runs the SD1.5 UNet on the ANE at 6-7x lower energy than GPU/MPS, at the same speed — see the writeup, The ANE runs the SD1.5 UNet at 6-7x lower energy than GPU/MPS, for the methodology and the numerical-divergence tradeoff.

The scope is diffusion architectures generally, not Stable Diffusion specifically. The project aims to gather, in one place: the conversion path, a reproducible benchmarking suite for objective comparison, a per-model catalogue documenting the quirks of each architecture on the ANE, and the sources behind it all.

Supported today: SD1.5 and SDXL (verified). SDXL refiner and LCM convert but are not yet golden-verified (experimental).

Install

uv pip install coreml-diffusion          # from PyPI
uv pip install -e .                       # from a checkout

Requires Python 3.12 and (for conversion) coremltools 9 — conversion runs on macOS; the package imports and its CLI parse on any platform.

CLI

coreml-diffusion convert \
    --ckpt path/to/model.safetensors \
    --model-version SD15 \
    --out unet.mlpackage \
    --height 512 --width 512 \
    --attn-impl SPLIT_EINSUM \
    --quantize none

Options: --batch-size, --controlnet, --lora PATH[:STRENGTH] (repeatable), --config (original-config YAML). --quantize {none,8,6,4} applies k-means weight palettization. Run coreml-diffusion convert --help for the full list.

The output .mlpackage is the deliverable: load it natively in Swift/Core ML, run it through the Python inference pipeline below, or hand it to any consuming host.

Model sources

Register directories so --ckpt accepts a bare name instead of a full path:

coreml-diffusion sources add comfy /path/to/ComfyUI/models   # --kind comfy|flat
coreml-diffusion sources list                                # sources + checkpoints
coreml-diffusion convert --ckpt v1-5-pruned-emaonly --model-version SD15 --out unet.mlpackage

Sources are recorded in ~/.config/coreml-diffusion/sources.toml. comfy knows the models/{checkpoints,loras,vae,...} layout; flat is a plain checkpoint directory.

Library

import coreml_diffusion
from coreml_diffusion import ModelVersion

coreml_diffusion.convert(
    "model.safetensors", ModelVersion.SD15, "unet.mlpackage",
    height=512, width=512, attn_impl="SPLIT_EINSUM",
)

Inference (in progress)

A framework-free inference path lets a converted .mlpackage generate images with no host framework: a diffusers pipeline runs the stock VAE / text encoder on torch while the UNet is served from Core ML on the ANE. This doubles as the package's own regression anchor — the Tier 2 (m2) golden image, asserted on an Apple Silicon runner — and as the reference for the on-device write-up. See tests/m2/.

Discovery API

list_model_versions, list_attention_impls, list_quant_modes, and CONTRACT_VERSION report what this build can convert. The identifiers are an additive-only contract: removing or renaming one is a major version bump, because downstream consumers reference these strings verbatim.

ComfyUI

ComfyUI-CoreMLSuite consumes this package for its conversion path and drives its node dropdowns from the discovery API above — installing a newer coreml-diffusion surfaces new conversion types in the node with no Suite change. The Suite is one consumer; this package neither depends on nor requires ComfyUI.

License

MIT

Metadata

Release files for coreml-diffusion 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coreml-diffusion 0.1.6
File Size Uploaded Provenance
coreml_diffusion-0.1.6.tar.gz 961.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for coreml-diffusion 0.1.6
File Interpreter ABI Platform
coreml_diffusion-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 998.6 kB

Release files / coreml_diffusion-0.1.6.tar.gz

Download URL coreml_diffusion-0.1.6.tar.gz
Size 961.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cfede31370a59b8d232c9bdcfdf3f6b7dd8670e79fa97209aaf83aeb961fc216
BLAKE2b-256 checksum
How to use checksums
783399a3b1419ffd70416370250628889c2987a1272a27f2c2f6c0f854199364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / coreml_diffusion-0.1.6-py3-none-any.whl

Download URL coreml_diffusion-0.1.6-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5ee3963f934291c4da209a3cb8ad524bccf2cedcea250c5e05ebe9431a13e84
BLAKE2b-256 checksum
How to use checksums
bff4b2412d58607450c2affcd90a97bad32c1c195713103488e2f31d90d5dc58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for coreml-diffusion 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page