Edit model card

はじめに

このモデルはStable Diffusionを0から作りたい人のモデルです。どこから作るかは個々人にお任せします。

SDXL

単一ファイル

sdxl_0_n.safetensorsはU-Netをランダムな値に置き換えています。作り方は以下のとおりです。

from safetensors import safe_open
from safetensors.torch import save_file
import torch

tensors = {}
with safe_open("/path/to/sd_xl_base_1.0.safetensors", framework="pt", device=0) as f:
    for k in f.keys():
        tensors[k] = f.get_tensor(k)
        if("model.diffusion_model" in k):
            tensors[k]=torch.randn_like(tensors[k])*1e-5

save_file(tensors, "/path/to/sdxl_0_n.safetensors")

このファイルをsd-scriptsでフルファインチューンをしてください。学習率は1e-4がおすすめです。(Stable Diffusion XL公式リポジトリより) また、SDXLの場合、OpenCLIPの都合上、泣き顔などができないため、テキストエンコーダーの学習を行うこともおすすめします。

また、学習しようとしても、損失関数の値が1になって下がらないようですが、念の為、 sdxl_0.safetensorsはU-Netを0に置き換えています。作り方は以下のとおりです。

from safetensors import safe_open
from safetensors.torch import save_file
import torch

tensors = {}
with safe_open("/path/to/sd_xl_base_1.0.safetensors", framework="pt", device=0) as f:
    for k in f.keys():
        tensors[k] = f.get_tensor(k)
        if("model.diffusion_model" in k):
            tensors[k]=torch.zeros_like(tensors[k])

save_file(tensors, "/path/to/sdxl_0.safetensors")

diffusers

diffusersなどを使ってダウンロードしてください。 作り方は以下のとおりです。

from diffusers import StableDiffusionXLPipeline
import torch

pipe = StableDiffusionXLPipeline.from_single_file('/path/to/sdxl_0_n.safetensors')
pipe.save_pretrained('/path/to/sd-0')
Downloads last month
11
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.