许可证: 其他
基础模型: "stabilityai/stable-diffusion-3.5-medium"
标签:
- sd3
- sd3-diffusers
- 文生图
- 图生图
- diffusers
- simpletuner
- 非全年龄段适用
- lora
- 模板:sd-lora
- lycoris
管道标签: 文生图
推理: 真
sd35m-photo-1mp-Prodigy
这是基于stabilityai/stable-diffusion-3.5-medium衍生的LyCORIS适配器。
训练期间使用的主要验证提示词为:
一张照片级真实感的猫咪图像
验证设置
- CFG值:
3.2
- CFG重缩放:
0.0
- 步数:
16
- 采样器:
FlowMatchEulerDiscreteScheduler
- 种子:
42
- 分辨率:
1024x1024
- 跳跃层引导:
skip_guidance_layers=[7, 8, 9],
注:验证设置与训练设置不一定相同。
文本编码器未参与训练。
推理时可复用基础模型的文本编码器。
训练设置
- 训练周期: 114
- 训练步数: 230
- 学习率: 5e-05
- 最大梯度值: 2.0
- 有效批大小: 3
- 微批大小: 3
- 梯度累积步数: 1
- GPU数量: 1
- 梯度检查点: 启用
- 预测类型: flow_matching (额外参数=['shift=3.0'])
- 优化器: optimi-lion
- 可训练参数精度: 纯BF16
- 基础模型精度:
int8-quanto
- 标题丢弃概率: 0.0%
LyCORIS配置:
{
"bypass_mode": true,
"algo": "lokr",
"multiplier": 1.0,
"full_matrix": true,
"linear_dim": 10000,
"linear_alpha": 1,
"factor": 4,
"apply_preset": {
"target_module": [
"Attention",
"FeedForward"
],
"module_algo_map": {
"FeedForward": {
"factor": 4
},
"Attention": {
"factor": 2
}
}
}
}
数据集
cheechandchong
- 重复次数: 0
- 图像总数: 4
- 宽高比分桶数: 1
- 分辨率: 1024像素
- 裁剪: 是
- 裁剪风格: 随机
- 裁剪比例: 方形
- 用于正则化数据: 否
推理
import torch
from diffusers import DiffusionPipeline
from lycoris import create_lycoris_from_weights
def download_adapter(repo_id: str):
import os
from huggingface_hub import hf_hub_download
adapter_filename = "pytorch_lora_weights.safetensors"
cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
os.makedirs(path_to_adapter, exist_ok=True)
hf_hub_download(
repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
)
return path_to_adapter_file
model_id = 'stabilityai/stable-diffusion-3.5-medium'
adapter_repo_id = 'bghira/sd35m-photo-1mp-Prodigy'
adapter_filename = 'pytorch_lora_weights.safetensors'
adapter_file_path = download_adapter(repo_id=adapter_repo_id)
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
lora_scale = 1.0
wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
wrapper.merge_to()
prompt = "一张照片级真实感的猫咪图像"
negative_prompt = '丑陋的, 裁剪的, 模糊的, 低质量的, 平庸的'
from optimum.quanto import quantize, freeze, qint8
quantize(pipeline.transformer, weights=qint8)
freeze(pipeline.transformer)
pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu')
model_output = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=16,
generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
width=1024,
height=1024,
guidance_scale=3.2,
skip_guidance_layers=[7, 8, 9],
).images[0]
model_output.save("output.png", format="PNG")
指数移动平均 (EMA)
SimpleTuner会生成EMA权重的safetensors变体和pt文件。
safetensors文件用于推理,pt文件用于继续微调。
EMA模型可能提供更均衡的结果,但由于是权重衰减滑动平均值,通常会显得比完整模型欠训练。