ERNIE-Image-Turbo-MLX-Q4 is a local inference distribution of ERNIE-Image-Turbo optimized for Apple Silicon. This directory contains ready-to-run MLX inference assets and minimal inference scripts, aiming to help developers perform high-quality text-to-image verification, prototyping, and engineering integration on macOS with lower VRAM consumption.
Compared to the original BF16 weights, this version quantizes the most memory-intensive modules—Transformer, Text Encoder, and Prompt Enhancement—to 4-bit, while keeping the VAE decoder at high precision to achieve a stable balance between deployment efficiency and generation quality.
Key Features
Apple Silicon Friendly: Built on MLX, specifically optimized for the Unified Memory Architecture of Apple M-series chips.
Massive Weight Compression: Core weights are compressed from ~30.56 GB to ~8.21 GB, making it ideal for local experiments and integration.
Preserved Strengths: Retains the core capabilities of ERNIE-Image-Turbo, including complex instruction following, long-form text rendering, and structured image generation.
Out-of-the-Box: Includes demo.py, a local scripts/ inference implementation, and all necessary configuration files. Developers can verify the model immediately.
Model Components
This distribution includes the following core components:
Component
Precision
Description
transformer/
Q4
Diffusion backbone (DiT), the primary compute and memory bottleneck.
text_encoder/
Q4
Text encoder responsible for prompt semantic modeling.
pe/
Q4
Prompt Enhancement module.
vae/
BF16
Image decoder, kept at high precision for high-fidelity output.
tokenizer/, pe_tokenizer/, scheduler/
Original
Necessary assets for the inference pipeline.
Use Cases
Rapidly verify ERNIE-Image-Turbo's local inference capabilities on Apple Silicon.
Provide a lightweight model base for integrating text-to-image features into applications.
Serve as a baseline for further Core ML conversion, service deployment, or on-device experiments.
Requirements
macOS
Apple Silicon Chip
Python 3.11+
Install dependencies:
pip install -r requirements.txt
The requirements.txt includes core dependencies for local execution:
mlx
mlx-lm
transformers
Pillow
numpy
safetensors
Quick Start
1. Run the Built-in Demo
Execute the following command in the current directory:
python demo.py
By default, this will:
Load the Q4 model assets from the current directory.
Use the prompt: "A cinematic poster of a futuristic city at sunrise, ultra detailed, realistic lighting".
Run 5 denoising steps.
Save the output to output.png.
2. Python Integration
To integrate this model into your own scripts, you can directly use the provided scripts.pipeline:
python
1from pathlib import Path
2from scripts.pipeline import generate, load_pipeline
34# Load the pipeline from the current directory5model_dir = Path(".")6pipeline = load_pipeline(model_dir)78# Generate an image9image = generate(10 pipeline,11 prompt="A cinematic poster of a futuristic city at sunrise, ultra detailed, realistic lighting",12 steps=5,13 seed=42,14 height=1024,15 width=1024,16)1718image.save("output.png")19print("Saved to output.png")
3. Recommended Parameters
For the best balance between quality and speed, we recommend:
Resolution: 1024x1024
Inference Steps: 8
Seed: Specify as needed for reproducibility.
For portrait or landscape orientations, you can explore:
848x1264 / 1264x848
768x1376 / 1376x768
896x1200 / 1200x896
Directory Structure
Path
Description
demo.py
Minimal runnable example.
scripts/pipeline.py
End-to-end loading and generation entry point.
scripts/dit.py
MLX implementation of the DiT backbone.
scripts/vae.py
VAE Decoder implementation.
transformer/
Quantized DiT weights and configuration.
text_encoder/
Quantized Text Encoder.
pe/
Quantized Prompt Enhancement module.
vae/
High-precision VAE decoder.
Experimental Results
We conducted local inference verification on an Apple M3 device. The core results are as follows:
Metric
Value
Model Load Time
4.62 s
Peak Memory Usage
14.70 GB
Text Encoding Time
1.05 s
Denoising Time
221.19 s
VAE Decoding Time
9.28 s
Total Generation Time
231.51 s
Notes:
Results were measured on an Apple M3 device with 24 GB Unified Memory.