本文内容结合 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
文件轻松地将您感兴趣的模型添加到支持列表中。
1# Add your own model here
2# <name that will show up on the dropdown>:
3# repo: <the huggingface repo ID to pull from>
4# base: <the model used to run inference with (The Huggingface "Inference API" widget will use this to generate demo images)>
5# license: <follow the other examples. Any model inherited from DEV should use the dev license, schenll is apache-2.0>
6# license_name: <follow the other examples. only needed for dev inherited models>
7# license_link: <follow the other examples. only needed for dev inherited models>
8# file: <the file name within the huggingface repo>
9flux-dev:
10 repo: cocktailpeanut/xulf-dev
11 base: black-forest-labs/FLUX.1-dev
12 license: other
13 license_name: flux-1-dev-non-commercial-license
14 license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
15 file: flux1-dev.sft
16flux-schnell:
17 repo: black-forest-labs/FLUX.1-schnell
18 base: black-forest-labs/FLUX.1-schnell
19 license: apache-2.0
20 file: flux1-schnell.safetensors
21bdsqlsz/flux1-dev2pro-single:
22 repo: bdsqlsz/flux1-dev2pro-single
23 base: black-forest-labs/FLUX.1-dev
24 license: other
25 license_name: flux-1-dev-non-commercial-license
26 license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
27 file: flux1-dev2pro.safetensors
28~
29~
30~
31"autodl-tmp/fluxgym/fluxgym/models.yaml" 27L, 1325B
如果您电脑上已经有现成模型的话,也可以将模型放到 models
目录下对应的子目录里(以 FLUX.1-dev 为例):
1/fluxgym
2 /models
3 /clip
4 clip_l.safetensors
5 t5xxl_fp16.safetensors
6 /unet
7 flux1-dev.sft
8 /vae
9 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 两个项目克隆到本地:
1git clone https://github.com/cocktailpeanut/fluxgym
2cd fluxgym
3git clone -b sd3 https://github.com/kohya-ss/sd-scripts
克隆完成后您的文件夹结构会是这样的:
1/fluxgym
2 app.py
3 requirements.txt
4 /sd-scripts
在根目录 fluxgym
下创建并激活一个 Python 虚拟环境 venv
:
Windows 用户在命令行窗口分别运行以下两行命令:
1python -m venv env
2env\Scripts\activate
Linux 用户在终端窗口分别运行以下两行命令:
1python -m venv env
2source env/bin/activate
您会发现 fluxgym
目录下新创建了一个子目录 env
:
1/fluxgym
2 app.py
3 requirements.txt
4 /sd-scripts
5 /env
接下来要进入到目录 sd-scripts
里将项目依赖项安装到当前环境中:
1cd sd-scripts
2pip install -r requirements.txt
接着返回到根目录并安装应用程序依赖项:
1cd ..
2pip install -r requirements.txt
最后,将 pytorch
的 Nightly 版本安装上:
1pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
返回到根目录 fluxgym
,运行以下命令启动应用:
1python app.py
要确保启动应用前已激活了虚拟环境:
Windows:env/Scripts/activate
Linux:source env/bin/activate
将 Fluxgym 和 kohya-ss/sd-scripts 两个项目克隆到本地:
1git clone https://github.com/cocktailpeanut/fluxgym
2cd fluxgym
3git clone -b sd3 https://github.com/kohya-ss/sd-scripts
直接运行以下命令:
1docker 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