demo1984s 的个人博客
本文内容结合Flux Gym项目https://github.com/cocktailpeanut/fluxgym的README.md英文文档的翻译,以及实践总结完成。
附上实践训练过程中生成的猫猫图,文末提供了模型文件下载:

Flux Gym:简单易用的 FLUX LoRA 训练UI工具,低 VRAM (显存)即可运行,支持12GB/16GB/20GB几种规格。
AI-Toolkit项目本身需要具备 24GB VRM才可运行。
Kohya Scripts项目本身只适用于在终端运行。
FluxGym 通过默认隐藏的 Advanced 选项卡,支持 Kohya sd-scripts 的所有功能。
图片出处 https://github.com/cocktailpeanut/fluxgym/blob/main/screenshot.png
在您选好了模型并开始训练时,系统会自动下载选中的相关模型。另外,您还可以通过编辑 models.yaml 文件轻松地将您感兴趣的模型添加到支持列表中。
# Add your own model here
# <name that will show up on the dropdown>:
# repo: <the huggingface repo ID to pull from>
# base: <the model used to run inference with (The Huggingface "Inference API" widget will use this to generate demo images)>
# license: <follow the other examples. Any model inherited from DEV should use the dev license, schenll is apache-2.0>
# license_name: <follow the other examples. only needed for dev inherited models>
# license_link: <follow the other examples. only needed for dev inherited models>
# file: <the file name within the huggingface repo>
flux-dev:
repo: cocktailpeanut/xulf-dev
base: black-forest-labs/FLUX.1-dev
license: other
license_name: flux-1-dev-non-commercial-license
license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
file: flux1-dev.sft
flux-schnell:
repo: black-forest-labs/FLUX.1-schnell
base: black-forest-labs/FLUX.1-schnell
license: apache-2.0
file: flux1-schnell.safetensors
bdsqlsz/flux1-dev2pro-single:
repo: bdsqlsz/flux1-dev2pro-single
base: black-forest-labs/FLUX.1-dev
license: other
license_name: flux-1-dev-non-commercial-license
license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
file: flux1-dev2pro.safetensors
~
~
~
"autodl-tmp/fluxgym/fluxgym/models.yaml" 27L, 1325B
如果您电脑上已经有现成模型的话,也可以将模型放到models目录下对应的子目录里(以 FLUX.1-dev 为例):
/fluxgym
/models
/clip
clip_l.safetensors
t5xxl_fp16.safetensors
/unet
flux1-dev.sft
/vae
ae.sft
- flux1-dev.sft 是旧的后缀名命名方式,可以将 flux1-dev.safetensors 改名为 flux1-dev.sft。Linux/Mac用户也可在
unet目录下运行ln -s /path/to/flux1-dev.safetensors flux1-dev.sft命令做个软链接。- ae.sft 同理。
clip、unet、vae模型使用的更多代码细节可打开app.py文件查看。- 模型文件百度网盘下载链接 https://pan.baidu.com/s/1nMwi4JPlaXiElsEo6lFvsg?pwd=7g96
您可以使用 Pinokio 一键式启动器在本地自动安装和启动所有内容:https://pinokio.computer/item?uri=https://github.com/cocktailpeanut/fluxgym
首先将 Fluxgym 和 kohya-ss/sd-scripts 两个项目克隆到本地:
git clone https://github.com/cocktailpeanut/fluxgym
cd fluxgym
git clone -b sd3 https://github.com/kohya-ss/sd-scripts
克隆完成后您的文件夹结构会是这样的:
/fluxgym
app.py
requirements.txt
/sd-scripts
在根目录fluxgym下创建并激活一个Python虚拟环境 venv:
Windows 用户在命令行窗口分别运行以下两行命令:
python -m venv env
env\Scripts\activate
Linux 用户在终端窗口分别运行以下两行命令:
python -m venv env
source env/bin/activate
您会发现fluxgym目录下新创建了一个子目录env:
/fluxgym
app.py
requirements.txt
/sd-scripts
/env
接下来要进入到目录sd-scripts里将项目依赖项安装到当前环境中:
cd sd-scripts
pip install -r requirements.txt
接着返回到根目录并安装应用程序依赖项:
cd ..
pip install -r requirements.txt
最后,将 pytorch 的 Nightly 版本安装上:
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
返回到根目录fluxgym,运行以下命令启动应用:
python app.py
要确保启动应用前已激活了虚拟环境:
Windows:env/Scripts/activate
Linux:source env/bin/activate
将 Fluxgym 和 kohya-ss/sd-scripts 两个项目克隆到本地:
git clone https://github.com/cocktailpeanut/fluxgym
cd fluxgym
git clone -b sd3 https://github.com/kohya-ss/sd-scripts
直接运行以下命令:
docker compose up -d --build
打开 Web 浏览器即可访问:http://localhost:7860

用法非常简单直接,按界面上的3步走基本就能满足。
图片数量 * Repeat trains per image * Max Train Epochs,上传完图片后会自动计算填充,必填。--d 来设置固定的种子参数值,还可以直观的观察 LoRA 训练过程中的演变。选填。640,Sample Image Every N Steps设置为 80,则在训练过程中分别会在第 80、160、240、320、400、480、560、640 步的时候为每条提示词生成对应的样例图像。结合 Sample Image Prompts (Separate with new lines) 使用。提示词支持使用以下参数:
- --n:指定反面提示词。
- --w:指定生成的图像的宽度。
- --h:指定生成的图像的高度。
- --d:指定生成的图像的种子。
- --l:指定生成图像的 CFG 值。
- --s:指定生成中的步数。
提示词权重
( )和[ ]也可正常使用。(点击https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#attentionemphasis了解更多关于注意力/强调的信息)
MyLoRA,那么上传的图片会保存在目录fluxgym/datasets/MyLoRA下。打开魔法。fluxgym/datasets/MyLoRA下会根据 Step 2. Dataset 里的图片生成的同名提示词文件,后缀是.txt。fluxgym/outputs/MyLoRA下会生成训练相关的文件及模型。如果在 Step 1. LoRA Info 配置了在训练过程中生成样例图片的提示词,那么指定步数生成的样例图片会保存在目录fluxgym/outputs/MyLoRA/sample里。高级参数配置暂未实际体验。
百度网盘下载链接:
https://pan.baidu.com/s/1nMwi4JPlaXiElsEo6lFvsg?pwd=7g96