| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 |
SDXL 微调训练
本 README 说明如何使用 SD3 模型权重,完成数据下载、预处理与训练启动(含 eager / torch.compile 两种模式)。
目录
1. 模型权重
-
Hugging Face 模型:stabilityai/stable-diffusion-3-medium-diffusers https://huggingface.co/stabilityai/stable-diffusion-3-medium-diffusers
-
可使用如下的自定义脚本下载
python ../utils/download_hf.py --model stabilityai/stable-diffusion-3-medium-diffusers --save_path ./stable-diffusion-3-medium-diffusers
环境提示
本项目依赖已整理到 requirements.txt,可直接安装:
pip install -r ../utils/requirements.txt
2. 数据获取
训练数据集链接如下:
https://huggingface.co/datasets/AdamLucek/oldbookillustrations-small/tree/main/data
- 可使用以下命令获取
wget https://huggingface.co/datasets/AdamLucek/oldbookillustrations-small/resolve/main/data/train-00000-of-00001.parquet
3. 模型训练
训练脚本:run_sd3.sh,脚本支持在 GPU 和 NPU 训练
开始训练前,请修改脚本中的路径参数:
- 模型权重路径
- 训练数据路径
3.1 eager mode(默认)
bash run_sd3.sh
3.2 启用 torch.compile(可选)
可通过添加 --enable_compile 选项运行图模式
当在 GPU 上训练时,默认后端使用triton;当在 NPU 上训练时,可进一步指定后端为 mlir 或 dvm,默认使用 mlir。
默认后端(mlir,可不写 --npu-backend):
bash run_sd3.sh \
--enable_compile
显式指定后端为 mlir:
bash run_sd3.sh \
--enable_compile \
--npu-backend mlir
切换后端为 dvm:
bash run_sd3.sh \
--enable_compile \
--npu-backend dvm
当在 NPU 上训练时,可通过 --mfusion 参数开启 MFusion 图算融合优化功能, 配合不同的NPU图模式后端, 进一步提升模型的性能,使用示例如下
bash run_sd3.sh \
--enable_compile \
--npu-backend dvm \
--mfusion
3.3 采集profile文件(可选)
脚本已支持 --enable_profiler 这样的开关,开启方式为:
bash run_sd3.sh \
--enable_profiler \
--profiler_start_step 5 \
--profiler_end_step 6 \
可以通过 --profiler_start_step 和 --profiler_end_step 分别设置profile开始和结束步数。