🚀 sd35m-sfwbooru-lycoris
這是一個基於 stabilityai/stable-diffusion-3.5-medium 的 LyCORIS 適配器。它能夠在圖像生成任務中,基於基礎模型生成更符合特定需求的圖像,為圖像生成領域帶來更多可能性。
🚀 快速開始
推理示例
以下是使用該適配器進行推理的 Python 代碼示例:
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-sfwbooru-lycoris'
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 = "A photo-realistic image of a cat"
negative_prompt = 'blurry, cropped, ugly'
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=30,
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")
驗證設置
- CFG:
3.2
- CFG 縮放:
0.0
- 步數:
30
- 採樣器:
FlowMatchEulerDiscreteScheduler
- 種子:
42
- 分辨率:
1024x1024
- 跳過層引導:
skip_guidance_layers=[7, 8, 9]
注意:驗證設置不一定與訓練設置相同。
訓練設置
屬性 |
詳情 |
訓練輪數 |
3 |
訓練步數 |
220250 |
學習率 |
5e-06 |
學習率調度 |
餘弦 |
熱身步數 |
500000 |
最大梯度值 |
0.01 |
有效批量大小 |
6 |
微批量大小 |
6 |
梯度累積步數 |
1 |
GPU 數量 |
1 |
梯度檢查點 |
啟用 |
預測類型 |
流匹配 (額外參數=['shift=3']) |
優化器 |
optimi-lion |
可訓練參數精度 |
純 BF16 |
基礎模型精度 |
no_change |
字幕丟棄概率 |
10.0% |
LyCORIS 配置
{
"algo": "lokr",
"multiplier": 1.0,
"full_matrix": true,
"linear_alpha": 1,
"factor": 16,
"apply_preset": {
"target_module": [
"Attention"
],
"module_algo_map": {
"Attention": {
"factor": 6
}
}
}
}
數據集
sfwbooru-crop
- 重複次數: 0
- 圖像總數: 363920
- 縱橫比桶總數: 1
- 分辨率: 1.048576 兆像素
- 裁剪: 是
- 裁剪樣式: 隨機
- 裁剪縱橫比: 正方形
- 用於正則化數據: 否
指數移動平均 (EMA)
SimpleTuner 會生成 EMA 權重的 safetensors 變體和一個 pt 文件。safetensors 文件用於推理,pt 文件用於繼續微調。EMA 模型可能會提供更全面的結果,但與完整模型相比,由於它是模型權重的衰減平均值,通常會感覺訓練不足。
你可以在以下圖庫中找到一些示例圖像:
文本編碼器未經過訓練,你可以重用基礎模型的文本編碼器進行推理。