High-performance Core ML diffusion model converter
Project description
Alloy ⚡️
[!IMPORTANT] 🚧 Work in Progress 🚧 This project is currently under active development. APIs and CLI commands are subject to change. Use with caution.
A unified toolchain for converting open-source diffusion models (Stable Diffusion, Wan 2.1/2.2) into Apple's Core ML format for hardware-accelerated inference on macOS.
Features
- Core ML Conversion: Optimize models for Apple Silicon (Neural Engine/GPU).
- Wan 2.x Support:
- Supports Wan 2.1 and Wan 2.2 (Text-to-Video).
- Supports Image-to-Video / Edit models (automatic 36-channel input detection).
- Implements Int4 Quantization to run 14B models on consumer Macs (64GB RAM recommended).
- Hunyuan Video Support:
- Supports HunyuanVideo (Transformer conversion).
- Hybrid Runner: PyTorch Text Encoder + Core ML Transformer + PyTorch VAE.
- LTX-Video Support:
- Supports Lightricks/LTX-Video.
- Efficient Core ML implementation for video generation.
- Flux ControlNet Support:
- Full support for Flux ControlNet residuals (Base Model + ControlNet Model).
- ComfyUI Nodes: Dedicated nodes for loading and applying Core ML ControlNets.
- Stable Diffusion Support: Wraps Apple's
python_coreml_stable_diffusionfor SDXL and SD3. (Requires optional[sd]extra) - Lumina-Image 2.0 Support: Implements Next-Gen DiT conversion using Gemma 2B text encoder.
- Full Pipeline: Automates Download -> Convert -> Upload to Hugging Face.
- Progress Tracking: Real-time conversion progress with phases, steps, elapsed time, and ETA estimation.
- Memory Monitoring: Pre-flight memory checks warn if system resources are low before starting conversion.
- Dependency Management: Uses
uvto resolve complex conflicts between legacy Core ML scripts and modern Hugging Face libraries.
Installation
-
Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
-
Install the Tool:
uv sync # Or install globally: # uv tool install .
-
Hugging Face Login (Required for Uploads/Gated Models):
uv run huggingface-cli login
Or configure it via
.env(recommended). -
Configuration: Copy the example environment file:
cp .env.example .env
Edit
.envto set yourHF_TOKENandOUTPUT_DIR.
Usage
You can run the tool using uv run alloy.
Convert Stable Diffusion (SDXL/SD3)
Note: SD support requires Apple's
python-coreml-stable-diffusionpackage (not on PyPI). Install manually:pip install git+https://github.com/apple/ml-stable-diffusion.git
uv run alloy convert stabilityai/stable-diffusion-xl-base-1.0 \
--type sd \
--output-dir converted_models/sdxl \
--quantization float16
Convert Lumina-Image 2.0
uv run alloy convert Alpha-VLLM/Lumina-Image-2.0 \
--type lumina \
--quantization int4
Convert Flux ControlNet (New!)
Support for converting Flux ControlNet models (X-Labs, InstantX, etc.) and preparing Base Flux models to accept them.
1. Convert Base Model (ControlNet Ready)
You must re-convert your base model with --controlnet to inject the residual inputs.
uv run alloy convert black-forest-labs/FLUX.1-schnell \
--output-dir converted_models/flux_controlnet \
--quantization int4 \
--controlnet
2. Convert ControlNet Model
uv run alloy convert x-labs/flux-controlnet-canny \
--type flux-controlnet \
--output-dir converted_models/flux_canny \
--quantization int4
Convert Wan 2.1 / 2.2
Supports both T2V (Text-to-Video) and I2V (Image-to-Video). The converter automatically detects the input channels from the model config.
# Text-to-Video
uv run alloy convert Wan-AI/Wan2.1-T2V-14B-720P-Diffusers \
--type wan \
--output-dir converted_models/wan_t2v \
--quantization int4
# Image-to-Video (36 channels)
uv run alloy convert Wan-AI/Wan2.1-I2V-14B-720P-Diffusers \
--type wan \
--output-dir converted_models/wan_i2v \
--quantization int4
Convert Flux
# Basic Conversion
uv run alloy convert black-forest-labs/FLUX.1-schnell \
--output-dir converted_models/flux \
--quantization int4
# With LoRA Baking
uv run alloy convert black-forest-labs/FLUX.1-schnell \
--output-dir converted_models/flux_style \
--quantization int4 \
--lora "path/to/style.safetensors:0.8:1.0" \
--lora "path/to/fix.safetensors:1.0"
Civitai / Single-File Models
Support for directly loading .safetensors files (e.g., from Civitai) for Flux and LTX-Video.
Auto-Detection: The CLI automatically detects the model architecture (Flux vs LTX) from the file header, so you can often skip the --type argument.
# Convert a single file checkpoint (Type auto-detected!)
uv run alloy convert /path/to/flux_schnell.safetensors \
--output-dir converted_models/flux_civiai \
--quantization int4
Full Pipeline
Downloads a model, converts it, and uploads the Core ML package to your Hugging Face account.
Run Locally
Verify your converted models by generating an image directly.
uv run alloy run converted_models/wan2.2 \
--prompt "A astronaut riding a horse on mars, photorealistic, 4k" \
--type wan \
--output result.png
Benchmark Performance
Measure real performance on your hardware:
uv run alloy run converted_models/flux \
--prompt "test image" \
--benchmark \
--benchmark-runs 5 \
--benchmark-output benchmarks.json
This will run 5 iterations and report:
- Mean/median generation time
- Memory usage
- Per-step timing breakdown
- Statistical variance
Results are saved to JSON for further analysis.
ComfyUI Integration
Alloy includes custom nodes for seamless ComfyUI integration with Core ML acceleration!
Installation
# 1. Install silicon-alloy
pip install -e .
# 2. Link to ComfyUI
ln -s /path/to/alloy/comfyui_custom_nodes /path/to/ComfyUI/custom_nodes/alloy
# 3. Restart ComfyUI
Quick Start (ComfyUI)
- Install Alloy via ComfyUI Manager
- Convert Model using the
CoreMLQuickConverternode- Select preset (e.g., "Flux Schnell")
- Run once to convert (caches automatically)
- Load Model using
CoreMLFluxWithCLIP - Generate!
Example Workflows
Check out comfyui_custom_nodes/example_workflows/ for ready-to-use examples:
- flux_txt2img.json: Basic Flux text-to-image workflow
- flux_img2img.json: Flux image-to-image transformation
- flux_allinone.json: Simplified workflow with integrated CLIP/T5/VAE
- convert_quick.json: One-click model conversion in ComfyUI
- convert_lora.json: Bake multiple LoRAs into one model
See the ComfyUI Node Reference for full documentation of all 13 nodes.
Utility Commands
Validate Models
alloy validate converted_models/flux/Flux_Transformer.mlpackage
Show Model Info
alloy info converted_models/flux/Flux_Transformer.mlpackage
List All Converted Models
alloy list-models
# or specify directory
alloy list-models --dir /path/to/models
Architecture
src/alloy/cli.py: CLI entry point.src/alloy/converters/: Model conversion logic (Flux, Wan, LTX, Hunyuan, Lumina, Stable Diffusion).- All converters use 2-phase subprocess isolation to prevent OOM during large model conversion.
- Intermediate files enable resume capability for interrupted conversions.
- Worker modules (
*_workers.py) handle subprocess conversion logic.
src/alloy/runners/: Inference runners (PyTorch/Core ML hybrids).src/alloy/utils/: Utilities for file handling, Hugging Face auth, and benchmarking.pyproject.toml: Dependency overrides to force compatibility betweencoremltoolsanddiffusers.
Requirements
- macOS 14+ (Sonoma) or newer.
- Python 3.11+.
- Apple Silicon (M1/M2/M3/M4).
Project details
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 silicon_alloy-0.4.0.tar.gz.
File metadata
- Download URL: silicon_alloy-0.4.0.tar.gz
- Upload date:
- Size: 171.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
132b4b488467bebc9ce4c7d0928b8cc8fc4c739afdde52625223fd1ef3b9cd15
|
|
| MD5 |
5e884c90fb73a188f8d231c8e97289df
|
|
| BLAKE2b-256 |
256c506e3f538a306f7dcb698a0fd5f9e06576e8e48f0ddc45060cd992f2e879
|
Provenance
The following attestation bundles were made for silicon_alloy-0.4.0.tar.gz:
Publisher:
publish.yml on hybridindie/alloy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
silicon_alloy-0.4.0.tar.gz -
Subject digest:
132b4b488467bebc9ce4c7d0928b8cc8fc4c739afdde52625223fd1ef3b9cd15 - Sigstore transparency entry: 777784475
- Sigstore integration time:
-
Permalink:
hybridindie/alloy@738f6b049f671c087ca78c3f35e28cc59d0e1bfc -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/hybridindie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@738f6b049f671c087ca78c3f35e28cc59d0e1bfc -
Trigger Event:
release
-
Statement type:
File details
Details for the file silicon_alloy-0.4.0-py3-none-any.whl.
File metadata
- Download URL: silicon_alloy-0.4.0-py3-none-any.whl
- Upload date:
- Size: 86.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb582d9f2aa209803396bec7cb76deaef5f3eff6f727c0db68378c0e586cd446
|
|
| MD5 |
8bbb50d2c1cbf0e28316a47ff4e545d1
|
|
| BLAKE2b-256 |
bbc3030bfa45e2fae3f7f4df6d66ee48ad1f6486cf93310a0a57181966e8a3ef
|
Provenance
The following attestation bundles were made for silicon_alloy-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on hybridindie/alloy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
silicon_alloy-0.4.0-py3-none-any.whl -
Subject digest:
eb582d9f2aa209803396bec7cb76deaef5f3eff6f727c0db68378c0e586cd446 - Sigstore transparency entry: 777784476
- Sigstore integration time:
-
Permalink:
hybridindie/alloy@738f6b049f671c087ca78c3f35e28cc59d0e1bfc -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/hybridindie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@738f6b049f671c087ca78c3f35e28cc59d0e1bfc -
Trigger Event:
release
-
Statement type: