Buckets:
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]
image
Stable 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]
image
AutoencoderTiny[[diffusers.AutoencoderTiny]]
diffusers.AutoencoderTiny[[diffusers.AutoencoderTiny]]
diffusers.AutoencoderTiny(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', upsample_fn: str = 'nearest', 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: int = 3, latent_shift: float = 0.5, force_upcast: bool = False, scaling_factor: float = 1.0, shift_factor: float = 0.0)
パラメータ:
in_channels (int、任意、デフォルトは 3) : 入力画像のチャネル数。
out_channels (int、optional、デフォルトは 3) : 出力のチャネル数。
encoder_block_out_channels (tuple[int]、optional、デフォルトは(64, 64, 64, 64)) : 各エンコーダーブロックの出力チャネル数を表す整数のタプル。タプルの長さは、エンコーダーブロックの数と等しくなければなりません。
decoder_block_out_channels (tuple[int]、optional、デフォルトは(64, 64, 64, 64)) : 各デコーダーブロックの出力チャネル数を表す整数のタプルです。タプルの長さは、デコーダーブロックの数と等しくなければなりません。
act_fn (str、任意、デフォルトは"relu") : モデル全体で使用される活性化関数。
latent_channels (int、optional、デフォルトは 4) : 潜在表現のチャネル数。潜在空間は、入力画像の圧縮された表現として機能します。
upsampling_scaling_factor (int、任意、デフォルトは 2) : デコーダーにおけるアップサンプリングのスケール係数です。アップサンプリング処理中の出力画像のサイズを決定します。
num_encoder_blocks (tuple[int]、optional、デフォルトは(1, 3, 3, 3)) : エンコーディング処理の各ステージにおけるエンコーダーブロックの数を表す整数のタプル。タプルの長さは、エンコーダーのステージ数と等しくする必要があります。各ステージには異なる数のエンコーダーブロックがあります。
num_decoder_blocks (tuple[int]、optional、デフォルトは(3, 3, 3, 1)) : デコーディングプロセスの各ステージにおけるデコーダーブロックの数を表す整数のタプルです。タプルの長さは、デコーダーのステージ数と等しくする必要があります。各ステージには異なる数のデコーダーブロックがあります。
latent_magnitude (float、任意、デフォルト値は 3.0) : 潜在表現の大きさ。このパラメータは潜在表現の値をスケーリングし、情報保持の範囲を制御します。
latent_shift (float, optional, デフォルト値は 0.5) : 潜在表現に適用されるシフト。このパラメータは潜在空間の中心を制御します。
scaling_factor (float, optional, デフォルト値は 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[[diffusers.AutoencoderTiny.forward]]
forward(sample: Tensor, return_dict: bool = True)
パラメータ:
sample (torch.Tensor) : 入力サンプル。
return_dict (bool、任意、デフォルトはTrue) : プレーンなタプルではなくDecoderOutputを返すかどうか。
戻り値: DecoderOutput または tuple
return_dict が True の場合、DecoderOutput が返され、それ以外の場合は通常の tuple が返されます。
scale_latents[[diffusers.AutoencoderTiny.scale_latents]]
scale_latents(x: Tensor)
raw latents -> [0, 1]
unscale_latents[[diffusers.AutoencoderTiny.unscale_latents]]
unscale_latents(x: Tensor)
[0, 1] -> 生の潜在変数
AutoencoderTinyOutput[[diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput]]
diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput[[diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput]]
diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput(latents: Tensor)
パラメータ:
latents (torch.Tensor) : Encoderのエンコード済み出力。
AutoencoderTinyのエンコードメソッドの出力。
Xet Storage Details
- Size:
- 8.73 kB
- Xet hash:
- 55dc61f398ca6dee62023523242f4cef58bd5e85fda253ab10982b6c17486635
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.