🚀 sd35m-photo-1mp-Prodigy
sd35m-photo-1mp-Prodigy是一個基於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-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 = "A photo-realistic image of a cat"
negative_prompt = 'ugly, cropped, blurry, low-quality, mediocre average'
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")
✨ 主要特性
- 基於
stabilityai/stable-diffusion-3.5-medium
模型,可用於文本到圖像、圖像到圖像等轉換。
- 文本編碼器未進行訓練,推理時可複用基礎模型的文本編碼器。
- 提供了驗證設置和訓練設置的詳細信息。
- 生成了EMA權重的safetensors變體和pt文件,可分別用於推理和繼續微調。
🔧 技術細節
驗證設置
- CFG:
3.2
- CFG Rescale:
0.0
- Steps:
16
- Sampler:
FlowMatchEulerDiscreteScheduler
- Seed:
42
- Resolution:
1024x1024
- Skip-layer guidance:
skip_guidance_layers=[7, 8, 9]
需注意,驗證設置不一定與訓練設置相同。
訓練設置
- 訓練輪數: 114
- 訓練步數: 230
- 學習率: 5e-05
- 最大梯度值: 2.0
- 有效批次大小: 3
- 微批次大小: 3
- 梯度累積步數: 1
- GPU數量: 1
- 梯度檢查點: 啟用
- 預測類型: flow_matching (額外參數=['shift=3.0'])
- 優化器: optimi-lion
- 可訓練參數精度: Pure 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 px
- 裁剪: 是
- 裁剪樣式: 隨機
- 裁剪縱橫比: 方形
- 用於正則化數據: 否
指數移動平均 (EMA)
SimpleTuner生成了EMA權重的safetensors變體和pt文件。safetensors文件用於推理,pt文件用於繼續微調。EMA模型可能會提供更全面的結果,但與完整模型相比,通常會感覺訓練不足,因為它是模型權重的衰減運行平均值。
📄 許可證
許可證類型:other