本文翻译整理自:https://github.com/filipstrand/mflux
一、关于 MFLUX
MFLUX 是 Black Forest Labs 开发的强大 FLUX 模型的 MLX 移植版本,让你能在 Mac 上本地运行这些模型!
相关链接资源
- github : https://github.com/filipstrand/mflux
- 官网:https://blackforestlabs.ai
- 官方文档:https://huggingface.co/black-forest-labs/FLUX.1-dev
- Demo/在线试用:https://blackforestlabs.ai/#get-flux
- Hugging Face : https://huggingface.co/black-forest-labs
- Community : https://github.com/filipstrand/mflux/discussions
- License : MIT
关键功能特性
- 完全兼容 Huggingface Diffusers 实现
- 支持 3/4/6/8 位量化运行
- 支持 LoRA 适配器
- 支持 ControlNet 控制生成
- 支持图像到图像转换
- 支持 Dreambooth 微调
- 提供 Flux Tools 工具集(填充、深度、Redux)
- 支持第三方 HuggingFace 模型
二、安装
系统要求
- macOS 系统
- Python 3.9+
安装方式
使用 uv 工具安装(推荐)
uv tool install --upgrade mflux
传统虚拟环境安装
mkdir -p mflux && cd mflux && python3 -m venv .venv && source .venv/bin/activate
pip install -U mflux
Python 3.13 开发预览版安装
uv venv --python 3.13
python -V # 例如 Python 3.13.0rc2
source .venv/bin/activate
uv pip install https://github.com/anthonywu/sentencepiece/releases/download/0.2.1-py13dev/sentencepiece-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
uv pip install --pre --extra-index-url https://download.pytorch.org/whl/nightly -e .
开发者安装
git clone git@github.com:filipstrand/mflux.git
make install
make test
三、使用指南
1、生成图像
基础生成示例
mflux-generate --model schnell --prompt "豪华美食摄影" --steps 2 --seed 2 -q 8
mflux-generate --model dev --prompt "豪华美食摄影" --steps 25 --seed 2 -q 8
完整命令行参数
--prompt
(必填): 图像描述文本--model
(必填): 使用的模型(“schnell” 或 “dev”)--output
: 输出文件名(默认:“image.png”)--seed
: 随机种子(可多个)--height
/--width
: 图像尺寸(默认1024x1024)--steps
: 推理步数(默认4)--guidance
: 引导比例(仅dev模型)--quantize
/-q
: 量化位数(3/4/6/8)--lora-paths
: LoRA权重路径--lora-scales
: LoRA缩放比例--image-path
: 图像到图像转换的源图像--image-strength
: 源图像影响强度(0.0-1.0)--low-ram
: 低内存模式
2、量化运行
运行时量化
mflux-generate \
--model schnell \
--steps 2 \
--seed 2 \
--quantize 8 \
--height 1920 \
--width 1024 \
--prompt "竹林池塘黎明景观"
量化模型大小比较
3位 | 4位 | 6位 | 8位 | 原始(16位) |
---|---|---|---|---|
7.52GB | 9.61GB | 13.81GB | 18.01GB | 33.73GB |
保存量化模型
mflux-save \
--path "/Users/username/Desktop/schnell_8bit" \
--model schnell \
--quantize 8
加载量化模型
mflux-generate \
--path "/Users/username/Desktop/schnell_8bit" \
--model schnell \
--steps 2 \
--seed 2 \
--prompt "豪华美食摄影"
3、图像到图像转换
mflux-generate \
--prompt "埃菲尔铁塔建筑草图" \
--image-path "reference.png" \
--image-strength 0.3 \
--lora-paths Architectural_Sketching.safetensors \
--lora-scales 1.0 \
--model dev \
--steps 20 \
--seed 43 \
--guidance 4.0 \
--quantize 8 \
--height 1024 \
--width 1024
4、LoRA 适配器
单LoRA使用
mflux-generate --prompt "sandor clegane" --model dev --steps 20 --seed 43 -q 8 --lora-paths "sandor_clegane_single_layer.safetensors"
多LoRA组合
mflux-generate \
--prompt "森林中的sandor clegane, 剪纸风格" \
--model dev \
--steps 20 \
--seed 43 \
--lora-paths sandor_clegane_single_layer.safetensors Flux_1_Dev_LoRA_Paper-Cutout-Style.safetensors \
--lora-scales 1.0 1.0 \
-q 8
5、ControlNet 控制生成
mflux-generate-controlnet \
--prompt "紫色西装小丑的漫画条" \
--model dev \
--steps 20 \
--seed 1727047657 \
--height 1066 \
--width 692 \
-q 8 \
--lora-paths "Dark Comic - s0_8 g4.safetensors" \
--controlnet-image-path "reference.png" \
--controlnet-strength 0.5 \
--controlnet-save-canny
6、Dreambooth 微调
训练示例
mflux-train --train-config src/mflux/dreambooth/_example/train.json
恢复训练
mflux-train --train-checkpoint 0001000_checkpoint.zip
四、Flux 工具集
1、填充工具(Inpainting/Outpainting)
创建遮罩
python -m tools.fill_mask_tool /path/to/your/image.jpg
使用示例
mflux-generate-fill \
--prompt "戴着红色帽子和滑雪镜的狗" \
--steps 20 \
--seed 42 \
--height 1280 \
--width 851 \
--guidance 30 \
-q 8 \
--image-path "dog.png" \
--masked-image-path "dog_mask.png"
2、深度工具
生成深度图
mflux-save-depth --image-path "your_image.jpg" -q 8
使用深度图生成
mflux-generate-depth \
--prompt "白色卡拉拉大理石走廊" \
-q 8 \
--height 1680 \
--width 1200 \
--image-path "original_image.png" \
--steps 20 \
--seed 7102725
3、Redux 工具
mflux-generate-redux \
--prompt "白色平台上灰色猫雕像" \
--redux-image-paths "original.png" \
--steps 20 \
--height 1654 \
--width 1154 \
-q 8
五、性能与兼容性
图像生成速度参考
设备 | 芯片 | 用户 | 报告时间 | 备注 |
---|---|---|---|---|
Mac Studio | M2 Ultra | @awni | <15s | |
Macbook Pro | M4 Max | @ivanfioravanti | ~19s | 128GB内存 |
Macbook Pro | M3 Max | @karpathy | ~20s | |
Mac Mini | M4 Pro | @Stoobs | ~34s | 64GB内存 |
Macbook Air | M1 | @mbvillaverde | ~335s | 8GB内存,512x512 |
当前限制
- 不支持批量生成
- 不支持负面提示
- LoRA仅支持transformer部分
- 部分LoRA适配器不兼容
- ControlNet仅支持canny版本
- Dreambooth训练参数需通过配置文件设置
六、工作流建议
- 使用
HF_HUB_DISABLE_PROGRESS_BARS=1
隐藏下载进度条 - 使用配置文件保存复杂参数
- 设置shell别名简化常用命令
- 低内存设备使用
--low-ram
选项 - 多种子生成使用
--seed
多值或--auto-seeds
- 使用
--stepwise-image-output-dir
保存中间步骤图像
七、致谢
MFLUX 的实现离不开以下项目的贡献:
伊织 xAI 2025-04-28(一)