Diffusion training and sampling on Apple silicon with MLX.
Project description
mlx-diffuser
Diffusion & flow models on Apple silicon, powered by MLX. Train from scratch, fine-tune, or run inference — for image, video, and discrete modalities — from one small, readable codebase.
If you know PyTorch and 🤗 diffusers, you already know this library:
Model.from_pretrained(...), pipe(...), nn.Module everywhere. The difference
is underneath — unified memory, mx.compile, fused Metal kernels, and built-in
weight quantization, so large models fit and run fast on a Mac.
Install
pip install mlx-diffuser # core
pip install "mlx-diffuser[hub]" # + Hugging Face Hub loading
Requires Apple silicon (M-series) and Python 3.11+.
Generate
from mlx_diffuser import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("path/or/hub-id", dtype="bf16", quantize=4)
images = pipe([1, 2, 3], num_inference_steps=50, guidance_scale=4.0, seed=0)
…or from the terminal:
mlx-diffuser generate path/or/hub-id --labels 1,2,3 --steps 50 --out samples/
Train from scratch
from mlx_diffuser import DiT, DiTConfig, DiffusionTrainer
from mlx_diffuser.schedulers import FlowMatchEulerScheduler
from mlx_diffuser.training import batch_iterator
model = DiT(DiTConfig(in_channels=3, hidden_size=384, depth=12, num_heads=6))
trainer = DiffusionTrainer(model, FlowMatchEulerScheduler(), lr=1e-4, ema_decay=0.999)
trainer.fit(batch_iterator(data, batch_size=32), steps=10_000)
model.save_pretrained("my-model")
Fine-tune with LoRA (on your laptop)
from mlx_diffuser import DiT, inject_lora, save_lora
from mlx_diffuser.schedulers import FlowMatchEulerScheduler
from mlx_diffuser import DiffusionTrainer
model = DiT.from_pretrained("my-model")
inject_lora(model, rank=8) # base frozen; only adapters train
trainer = DiffusionTrainer(model, FlowMatchEulerScheduler(), lr=5e-3)
trainer.fit(batch_iterator(data, batch_size=8), steps=1000)
save_lora(model, "my-lora", rank=8, alpha=16)
mlx-diffuser train --data ./photos --base my-model --lora --out my-lora --steps 1000
What's inside
- Models —
DiT(image/video/text via config),UNet2D(Stable-Diffusion style, text-conditionable),AutoencoderKL(VAE for latent diffusion). - Schedulers —
DDPM,DDIM,EulerDiscrete,FlowMatchEuler; one object covers both training (add_noise/get_target) and sampling (step). - Training —
DiffusionTrainer(compiled step, EMA, grad clip, min-SNR weighting), full fine-tune, and LoRA. - Apple-silicon speed — fused attention,
mx.compile, lazy evaluation, unified-memory controls, and 4/8-bit weight quantization. - CLI —
generate,train,convert.
Design
The library rests on three orthogonal pieces — a process (the noise/flow math),
a network (a plain nn.Module), and a pipeline (inference glue). Keeping
them independent is what lets the same network train under DDPM today and
flow-matching tomorrow. See DESIGN.md and the
documentation.
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlx_diffuser-0.1.1.tar.gz.
File metadata
- Download URL: mlx_diffuser-0.1.1.tar.gz
- Upload date:
- Size: 123.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
660faf8a3ff9664ac6b26974a35eb8728dc1656461a3712256689ba2d7965c48
|
|
| MD5 |
4147c254c3ae6071e068893c36646005
|
|
| BLAKE2b-256 |
546781ad59da52723fbc5a986a212729ec5d739ac25c130843ab9571708e71de
|
Provenance
The following attestation bundles were made for mlx_diffuser-0.1.1.tar.gz:
Publisher:
release.yml on amirhossein-razlighi/mlx_diffuser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_diffuser-0.1.1.tar.gz -
Subject digest:
660faf8a3ff9664ac6b26974a35eb8728dc1656461a3712256689ba2d7965c48 - Sigstore transparency entry: 1826092875
- Sigstore integration time:
-
Permalink:
amirhossein-razlighi/mlx_diffuser@9ff735c8a1901808c84b5f8cc5e54b3d68b0f36b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/amirhossein-razlighi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ff735c8a1901808c84b5f8cc5e54b3d68b0f36b -
Trigger Event:
release
-
Statement type:
File details
Details for the file mlx_diffuser-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mlx_diffuser-0.1.1-py3-none-any.whl
- Upload date:
- Size: 46.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9f3281ddda49f9e4c616f16b06b05357030b0083171dc2ef36228729f3971a7
|
|
| MD5 |
4bd1be9352eb2730fe75539a2e27f8a0
|
|
| BLAKE2b-256 |
b4eeac143b73f83a3d047a159738257664c93bf89f11f926c30b5556255be078
|
Provenance
The following attestation bundles were made for mlx_diffuser-0.1.1-py3-none-any.whl:
Publisher:
release.yml on amirhossein-razlighi/mlx_diffuser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_diffuser-0.1.1-py3-none-any.whl -
Subject digest:
e9f3281ddda49f9e4c616f16b06b05357030b0083171dc2ef36228729f3971a7 - Sigstore transparency entry: 1826093138
- Sigstore integration time:
-
Permalink:
amirhossein-razlighi/mlx_diffuser@9ff735c8a1901808c84b5f8cc5e54b3d68b0f36b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/amirhossein-razlighi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ff735c8a1901808c84b5f8cc5e54b3d68b0f36b -
Trigger Event:
release
-
Statement type: