模型简介
模型特点
模型能力
使用案例
🚀 SoteDiffusion V2
SoteDiffusion V2 是对 Würstchen V3 / Stable Cascade 进行的动漫微调模型,可用于文本到图像的生成,生成具有动漫风格的图像。
✨ 主要特性
- 本版本由 fal.ai/grants 赞助发布。
- 在 8 块英伟达 H100 80GB SXM5 GPU 上对 1200 万对文本和图像(包含 WD 标签和自然语言描述)进行了单轮训练。
- 使用全 FP32 和 MAE 损失进行训练。
📦 安装指南
Diffusers
pip install git+https://github.com/huggingface/diffusers
💻 使用示例
基础用法
import torch
import diffusers
device = "cuda"
dtype = torch.float16
model_path = "Disty0/sotediffusion-v2"
pipe = diffusers.AutoPipelineForText2Image.from_pretrained(model_path, torch_dtype=dtype)
# de-dupe
pipe.decoder_pipe.text_encoder = pipe.text_encoder = None # nothing uses this
del pipe.decoder_pipe.text_encoder
del pipe.prior_prior
del pipe.prior_text_encoder
del pipe.prior_tokenizer
del pipe.prior_scheduler
del pipe.prior_feature_extractor
del pipe.prior_image_encoder
pipe = pipe.to(device, dtype=dtype)
pipe.prior_pipe = pipe.prior_pipe.to(device, dtype=dtype)
def encode_prompt(
prior_pipe,
device,
num_images_per_prompt,
prompt=""
):
if prompt == "":
text_inputs = prior_pipe.tokenizer(
prompt,
padding="max_length",
max_length=77,
truncation=False,
return_tensors="pt",
)
input_ids = text_inputs.input_ids
attention_mask=None
else:
text_inputs = prior_pipe.tokenizer(
prompt,
padding="longest",
truncation=False,
return_tensors="pt",
)
chunk = []
padding = []
max_len = 75
start_token = text_inputs.input_ids[:,0].unsqueeze(0)
end_token = text_inputs.input_ids[:,-1].unsqueeze(0)
raw_input_ids = text_inputs.input_ids[:,1:-1]
prompt_len = len(raw_input_ids[0])
last_lenght = prompt_len % max_len
for i in range(int((prompt_len - last_lenght) / max_len)):
chunk.append(torch.cat([start_token, raw_input_ids[:,i*max_len:(i+1)*max_len], end_token], dim=1))
for i in range(max_len - last_lenght):
padding.append(text_inputs.input_ids[:,-1])
last_chunk = torch.cat([raw_input_ids[:,prompt_len-last_lenght:], torch.tensor([padding])], dim=1)
chunk.append(torch.cat([start_token, last_chunk, end_token], dim=1))
input_ids = torch.cat(chunk, dim=0)
attention_mask = torch.ones(input_ids.shape, device=device, dtype=torch.int64)
attention_mask[-1,last_lenght+1:] = 0
text_encoder_output = prior_pipe.text_encoder(
input_ids.to(device), attention_mask=attention_mask, output_hidden_states=True
)
prompt_embeds = text_encoder_output.hidden_states[-1].reshape(1,-1,1280)
prompt_embeds = prompt_embeds.to(dtype=prior_pipe.text_encoder.dtype, device=device)
prompt_embeds = prompt_embeds.repeat_interleave(num_images_per_prompt, dim=0)
prompt_embeds_pooled = text_encoder_output.text_embeds[0].unsqueeze(0).unsqueeze(1)
prompt_embeds_pooled = prompt_embeds_pooled.to(dtype=prior_pipe.text_encoder.dtype, device=device)
prompt_embeds_pooled = prompt_embeds_pooled.repeat_interleave(num_images_per_prompt, dim=0)
return prompt_embeds, prompt_embeds_pooled
prompt = "1girl, solo, looking at viewer, open mouth, blue eyes, medium breasts, blonde hair, gloves, dress, bow, hair between eyes, bare shoulders, upper body, hair bow, indoors, elbow gloves, hand on own chest, bridal gauntlets, candlestand, smile, rim lighting, from side, castle interior, looking side,"
quality_prompt = "very aesthetic, best quality, newest"
negative_prompt = "very displeasing, displeasing, worst quality, bad quality, low quality, realistic, monochrome, comic, sketch, oldest, early, artist name, signature, blurry, simple background, upside down,"
num_images_per_prompt=1
# Encode prompts and quality prompts eperately, long prompt support and don't use attention masks for empty prompts:
# pipe, device, num_images_per_prompt, prompt
empty_prompt_embeds, _ = encode_prompt(pipe.prior_pipe, device, num_images_per_prompt, prompt="")
prompt_embeds, prompt_embeds_pooled = encode_prompt(pipe.prior_pipe, device, num_images_per_prompt, prompt=prompt)
quality_prompt_embeds, _ = encode_prompt(pipe.prior_pipe, device, num_images_per_prompt, prompt=quality_prompt)
prompt_embeds = torch.cat([prompt_embeds, quality_prompt_embeds], dim=1)
negative_prompt_embeds, negative_prompt_embeds_pooled = encode_prompt(pipe.prior_pipe, device, num_images_per_prompt, prompt=negative_prompt)
while prompt_embeds.shape[1] < negative_prompt_embeds.shape[1]:
prompt_embeds = torch.cat([prompt_embeds, empty_prompt_embeds], dim=1)
while negative_prompt_embeds.shape[1] < prompt_embeds.shape[1]:
negative_prompt_embeds = torch.cat([negative_prompt_embeds, empty_prompt_embeds], dim=1)
output = pipe(
width=1024,
height=1536,
decoder_guidance_scale=1.0,
prior_guidance_scale=5.0,
prior_num_inference_steps=28,
num_inference_steps=14,
output_type="pil",
prompt=prompt + " " + quality_prompt,
negative_prompt=negative_prompt,
prompt_embeds=prompt_embeds,
prompt_embeds_pooled=prompt_embeds_pooled,
negative_prompt_embeds=negative_prompt_embeds,
negative_prompt_embeds_pooled=negative_prompt_embeds_pooled,
num_images_per_prompt=num_images_per_prompt,
).images[0]
display(output)
📚 详细文档
ComfyUI 使用说明
启动 ComfyUI 时使用以下参数:--fp16-vae --fp16-unet
下载 Stage C 到 unet 文件夹:sotediffusion-v2-stage_c.safetensors
下载 Stage C 文本编码器到 clip 文件夹:sotediffusion-v2-stage_c_text_encoder.safetensors
下载 Stage B 到 unet 文件夹:sotediffusion-v2-stage_b.safetensors
下载 Stage A 到 vae 文件夹:stage_a_ft_hq.safetensors
下载工作流并加载:comfyui_workflow.json
Stage C 采样器:DPMPP 2M 或 DPMPP 2M SDE 搭配 SGM Uniform 调度器
Stage C 步数:28
Stage C 分类器自由引导(CFG):6.0
Stage B 采样器:LCM 搭配指数调度器
Stage B 步数:14
Stage B 分类器自由引导(CFG):1.0
SD.Next 使用说明
URL: https://github.com/vladmandic/automatic/
前往 Models -> Huggingface,在模型名称中输入 Disty0/sotediffusion-v2
并点击下载。
下载完成后加载 Disty0/sotediffusion-v2
。
提示词(Prompt):
your prompt goes here
very aesthetic, best quality, newest,
(在 SD.Next 中,换行的作用与 BREAK 相同)
负提示词(Negative Prompt):
very displeasing, displeasing, worst quality, bad quality, low quality, realistic, monochrome, comic, sketch, oldest, early, artist name, signature, blurry, simple background, upside down,
参数设置:
采样器(Sampler):默认
步数(Steps):28
细化步数(Refiner Steps):14
分类器自由引导(CFG):5.0 到 6.0
二次分类器自由引导(Secondary CFG):1.0 到 1.5
分辨率(Resolution):1280x1280、1024x1536、1024x2048、2048x1152
只要是 128 的倍数,任何分辨率都可以。
训练细节
Stage C
- 基础模型:Disty0/sotediffusion-wuerstchen3
- 使用的 GPU:7 块英伟达 H100 80GB SXM5
参数 | 值 |
---|---|
自动混合精度(amp) | 否 |
权重类型 | fp32 |
保存的权重类型 | fp32 |
分辨率 | 1024x1024 |
有效批量大小 | 84 |
U-Net 学习率 | 2e-6 |
文本编码器学习率 | 1e-7 |
优化器 | AdamW 8bit |
图像数量 | 600 万张,每张图像有 2 个描述 |
训练轮数 | 1 |
Stage B
- 基础模型:Disty0/sotediffusion-wuerstchen3-decoder
- 使用的 GPU:1 块英伟达 H100 80GB SXM5
参数 | 值 |
---|---|
自动混合精度(amp) | 否 |
权重类型 | fp32 |
保存的权重类型 | fp32 |
分辨率 | 1024x1024 |
有效批量大小 | 8 |
U-Net 学习率 | 8e-6 |
文本编码器学习率 | 无 |
优化器 | AdamW |
图像数量 | 12 万张 |
训练轮数 | 6 |
WD 标签说明
模型按照以下标签顺序进行训练:
美学标签, 质量标签, 日期标签, 自定义标签, 评级标签, 角色, 系列, 其余标签
日期标签
标签 | 日期范围 |
---|---|
最新(newest) | 2022 年到 2024 年 |
近期(recent) | 2019 年到 2021 年 |
中期(mid) | 2015 年到 2018 年 |
早期(early) | 2011 年到 2014 年 |
最旧(oldest) | 2005 年到 2010 年 |
美学标签
- 使用的模型:shadowlilac/aesthetic-shadow-v2
分数阈值 | 标签 | 数量 |
---|---|---|
0.90 | 极其美观(extremely aesthetic) | 125451 |
0.80 | 非常美观(very aesthetic) | 887382 |
0.70 | 美观(aesthetic) | 1049857 |
0.50 | 略有美感(slightly aesthetic) | 1643091 |
0.40 | 不令人反感(not displeasing) | 569543 |
0.30 | 不美观(not aesthetic) | 445188 |
0.20 | 略有不悦感(slightly displeasing) | 341424 |
0.10 | 令人不悦(displeasing) | 237660 |
其余 | 非常令人不悦(very displeasing) | 328712 |
质量标签
分数阈值 | 标签 | 数量 |
---|---|---|
0.980 | 最佳质量(best quality) | 1270447 |
0.900 | 高质量(high quality) | 498244 |
0.750 | 优质(great quality) | 351006 |
0.500 | 中等质量(medium quality) | 366448 |
0.250 | 普通质量(normal quality) | 368380 |
0.125 | 质量差(bad quality) | 279050 |
0.025 | 低质量(low quality) | 538958 |
其余 | 最差质量(worst quality) | 1955966 |
评级标签
标签 | 数量 |
---|---|
通用(general) | 1416451 |
敏感(sensitive) | 3447664 |
不适宜公开(nsfw) | 427459 |
明确不适宜公开(explicit nsfw) | 336925 |
自定义标签
数据集名称 | 自定义标签 |
---|---|
图像板块(image boards) | 日期, |
文本(text) | 文本内容为 "text", |
角色(characters) | 角色, 系列 |
Pixiv | 作者为 Display_Name, |
视觉小说 CG(visual novel cg) | 完整视觉小说名称 (简称), 视觉小说 CG, |
动漫壁纸(anime wallpaper) | 日期, 动漫壁纸, |
局限性和偏差
偏差
- 该模型主要用于动漫插画生成,未对其生成现实风格图像的能力进行测试。
局限性
- 可能会生成现实风格的图像,出现这种情况时,可在负提示词中添加 "realistic" 标签。
- 远景中的眼睛和手部细节可能表现不佳。
- 模型仍有很大的训练提升空间。
📄 许可证
SoteDiffusion 模型遵循 Fair AI Public License 1.0-SD 许可协议,该协议与 Stable Diffusion 模型的许可协议兼容。关键要点如下:
- 修改共享:如果您对 SoteDiffusion 模型进行了修改,必须同时共享您的修改内容和原始许可协议。
- 源代码可访问性:如果您修改后的版本可以通过网络访问,需提供一种方式(如下载链接)让他人获取源代码。这同样适用于派生模型。
- 分发条款:任何分发都必须遵循本许可协议或具有类似规则的其他协议。
- 合规性:若出现违规情况,必须在 30 天内进行修复,否则可能导致许可协议终止,强调了透明度和遵守开源价值观的重要性。
注意:Fair AI 许可协议未涵盖的内容继承自 Stability AI 非商业许可协议,该协议文件名为 LICENSE_INHERIT。

