ジャコ Lab

プログラミング関連のメモ帳的ブログです

Consistency Decoder とやらを使ってみる

github.com

Consistency Decoderdiffusers v0.23.0 で入った機能と思われます。

何それ?

Consistency Decoder とは?

Consistency Decoder とは、 ChatGPT でお馴染みの Open AIDALE-E 3 で使われている Decoder をオープンソース化したものだそうです。

openai.com

ここにちょっとだけ書いてありました。

We are also open sourcing the Consistency Decoder, a drop in replacement for the Stable Diffusion VAE decoder. This decoder improves all images compatible with the by Stable Diffusion 1.0+ VAE, with significant improvements in text, faces and straight lines.

詳しくは、ちゃんと説明している記事を探した方が早そうです。

とりあえず、高速化&品質向上されるそうです。

とりあえず使ってみよう?

モデルのロード等 (ConsistencyDecoderVAE, stable-diffusion-v1-5)

import torch
from diffusers import ConsistencyDecoderVAE, DiffusionPipeline

# ConsistencyDecoder VAE のロード
vae = ConsistencyDecoderVAE.from_pretrained(
    "openai/consistency-decoder",
    torch_dtype=torch.float16
)

# Stable Diffusion モデルのロード
pipe = DiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    vae=vae,
    torch_dtype=torch.float16
).to("cuda")
VAEを変える感じなんですね?

プロンプト実行

import torch

# パイプライン実行
prompt = "cat"
image = pipe(
    prompt,
    generator=torch.manual_seed(0)
).images[0]
50/50 [00:07<00:00,  6.97it/s]
50ステップを7秒。早い?

出力結果

from datetime import datetime
from zoneinfo import ZoneInfo

# Asia/Tokyo タイムゾーンの現在時刻を YYYYMMDDhhmmss 形式で得る
formattedNow = datetime.now(tz=ZoneInfo("Asia/Tokyo")).strftime("%Y%m%d%H%M%S")

# 実行結果
image.save(f"animation_{formattedNow}.png")

ぬこ
ぬこ

ConsistencyDecoderVAE 無しでやってみたけど。。。

import torch
from diffusers import DiffusionPipeline

# Stable Diffusion モデルのロード
pipe = DiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16
).to("cuda")

# パイプライン実行
prompt = "cat"
image = pipe(
    prompt,
    generator=torch.manual_seed(0)
).images[0]
from datetime import datetime
from zoneinfo import ZoneInfo

# Asia/Tokyo タイムゾーンの現在時刻を YYYYMMDDhhmmss 形式で得る
formattedNow = datetime.now(tz=ZoneInfo("Asia/Tokyo")).strftime("%Y%m%d%H%M%S")

# 実行結果
image.save(f"animation_{formattedNow}.png")

50/50 [00:08<00:00,  6.72it/s]

ConsistencyDecoderVAE 無しで出力した様子
ConsistencyDecoderVAE 無し

謎。。。全然違いがわからない

出力された画像2枚を使って GIF 動画にしてみた

2枚を GIF 動画にしたもの
2枚を GIF 動画にしたもの

チカチカしているので一応違う画像が出力されてるみたい

まとめ

プロンプトが単純過ぎるのか、シードが悪いのか、違いがあまりわかりませんでした!