Diffusers documentation
Tiny AutoEncoder
Tiny AutoEncoder
Stable Diffusion 用の Tiny AutoEncoder (TAESD) は、Ollin Boer Bohan 氏によって madebyollin/taesd で紹介されました。これは Stable Diffusion の VAE の小型化・蒸留版であり、StableDiffusionPipeline または StableDiffusionXLPipeline の latents をほぼ瞬時にデコードできます。
Stable Diffusion v-2.1で使用する場合は:
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", dtype=torch.float16)
pipe = pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
imageStable Diffusion XL 1.0 と一緒に使用するには
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", dtype=torch.float16)
pipe = pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
imageAutoencoderTiny
class diffusers.AutoencoderTiny
< source >( in_channels: int = 3out_channels: int = 3encoder_block_out_channels: tuple[int, ...] = (64, 64, 64, 64)decoder_block_out_channels: tuple[int, ...] = (64, 64, 64, 64)act_fn: str = 'relu'upsample_fn: str = 'nearest'latent_channels: int = 4upsampling_scaling_factor: int = 2num_encoder_blocks: tuple[int, ...] = (1, 3, 3, 3)num_decoder_blocks: tuple[int, ...] = (3, 3, 3, 1)latent_magnitude: int = 3latent_shift: float = 0.5force_upcast: bool = Falsescaling_factor: float = 1.0shift_factor: float = 0.0 )
パラメータ
- in_channels (
int、任意、デフォルトは 3) — 入力画像のチャネル数。 - out_channels (
int, 省略可能、デフォルト値は 3) — 出力のチャネル数。 - encoder_block_out_channels (
tuple[int]、任意、デフォルトは(64, 64, 64, 64)) — 各エンコーダーブロックの出力チャネル数を表す整数のタプルです。タプルの長さは、エンコーダーブロックの数と等しくなければなりません。 - decoder_block_out_channels (
tuple[int]、任意、デフォルトは(64, 64, 64, 64)) — 各デコーダーブロックの出力チャネル数を表す整数のタプルです。タプルの長さは、デコーダーブロックの数と等しくなければなりません。 - act_fn (
str、任意、デフォルトは"relu") — モデル全体で使用される活性化関数。 - latent_channels (
int, 任意、デフォルトは 4) — 潜在表現のチャネル数。潜在空間は、入力画像の圧縮された表現として機能します。 - upsampling_scaling_factor (
int, 任意、デフォルトは 2) — デコーダーにおけるアップサンプリングの拡大係数です。アップサンプリング処理中に出力画像のサイズを決定します。 - num_encoder_blocks (
tuple[int]、任意、デフォルトは(1, 3, 3, 3)) — エンコーディング処理の各ステージにおけるエンコーダーブロックの数を表す整数のタプルです。タプルの長さは、エンコーダーのステージ数と等しくする必要があります。各ステージには異なる数のエンコーダーブロックが割り当てられます。 - num_decoder_blocks (
tuple[int]、任意、デフォルトは(3, 3, 3, 1)) — デコーディング処理の各ステージにおけるデコーダーブロックの数を表す整数のタプルです。タプルの長さは、デコーダーのステージ数と等しくする必要があります。各ステージには異なる数のデコーダーブロックが割り当てられます。 - latent_magnitude (
float、任意、デフォルト値は 3.0)— 潜在表現の大きさ。このパラメータは潜在表現の値をスケーリングし、情報保持の範囲を制御します。 - latent_shift (float, 任意、デフォルト値は 0.5) — 潜在表現に適用されるシフト。このパラメータは潜在空間の中心を制御します。
- scaling_factor (
float, 任意、デフォルト値は 1.0) — 学習済み潜在空間の要素ごとの標準偏差です。これは、学習セットの最初のバッチを使用して計算されます。拡散モデルの学習時に、潜在空間を分散 1 にスケーリングするために使用されます。潜在変数は、拡散モデルに渡される前にz = z * scaling_factorという式でスケーリングされます。デコード時には、z = 1 / scaling_factor * zという式で元のスケールに戻されます。詳細については、High-Resolution Image Synthesis with Latent Diffusion Models 論文のセクション 4.3.2 および D.1 を参照してください。ただし、この Autoencoder についてはそのようなスケーリング係数が使用されていないため、デフォルト値は 1.0 となっています。 - force_upcast (
bool、任意、デフォルトはFalse) — 有効にすると、SD-XL などの高解像度画像パイプラインにおいて、VAE を float32 で実行するよう強制します。VAE は、精度を大きく失うことなく、より低い範囲にファインチューニング / 学習させることができます。その場合、force_upcastをFalseに設定できます(この fp16 対応の AutoEncoder を参照)。
画像を潜在変数にエンコードし、潜在表現を画像にデコードするための、小型の蒸留VAEモデルです。
AutoencoderTiny は、TAESD の元の実装をラップしたものです。
このモデルは ModelMixin を継承しています。すべてのモデルに実装されている汎用的なメソッド(ダウンロードや保存など)については、スーパークラスのドキュメントを参照してください。
forward
< source >( sample: Tensorreturn_dict: bool = True ) → DecoderOutput or tuple
raw latents -> [0, 1]
[0, 1] -> 生の潜在変数
AutoencoderTinyOutput
class diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput
< source >( latents: Tensor )
AutoencoderTinyのエンコードメソッドの出力。