Buckets:

mishig's picture
|
download
raw
17.6 kB

DreamLite

DreamLite は、ByteDance によるテキストから画像を生成し、画像を編集するモデルです。独自の 2D U-Net (DreamLiteUNetModel) を、プロンプト / 画像指示エンコーダーとして Qwen3-VL マルチモーダルエンコーダーと組み合わせ、高速な潜在エンコード / デコードには AutoencoderTiny (TAESD スタイル) VAE を使用しています。

2つのパイプラインが公開されています:

パイプライン モード CFG ユースケース
DreamLitePipeline テキストから画像を生成するおよび画像編集(imageがNoneかどうかで自動選択されます) 3ブランチのデュアルCFG(テキストブランチにguidance_scale、画像ブランチにimage_guidance_scaleを適用、InstructPix2Pixと同様) 最高品質
DreamLiteMobilePipeline テキストから画像を生成するおよび画像編集(imageがNoneかどうかで自動選択されます) なし — 蒸留済み、ステップごとに単一の UNet 前向き オンデバイス / 低レイテンシ

公式チェックポイント:

は、image引数が提供されているかどうかから、テキストから画像への生成モードと画像編集モードを自動検出します。個別のImg2Imgクラスは存在しません。

画像の編集用にインプット画像を読み込む際は、生のPIL.Image.open(...)ではなくdiffusers.utils.load_image(...)の使用を推奨します。load_imageはRGB変換を強制し、EXIF方向を適用します。これらはパイプラインが前提としている処理です。RGBA / パレット / EXIF回転付きのソースに対して単にImage.openを使用すると、異なる潜在条件が静かに生成され、出力品質が低下します。

テキストから画像へ(Base)

import torch
from diffusers import DreamLitePipeline

pipe = DreamLitePipeline.from_pretrained("carlofkl/DreamLite-base", revision="diffusers", dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

image = pipe(
    prompt="a dog running on the grass",
    negative_prompt="",
    height=1024,
    width=1024,
    num_inference_steps=28,
    generator=torch.Generator("cpu").manual_seed(42),
).images[0]
image.save("dreamlite_t2i.png")

画像編集(Base)

image を渡すと、編集モードに入ります。ここでは guidance_scale(テキストブランチ)と image_guidance_scale(イメージブランチ)の両方が有効になります。

import torch
from diffusers import DreamLitePipeline
from diffusers.utils import load_image

pipe = DreamLitePipeline.from_pretrained("carlofkl/DreamLite-base", revision="diffusers", dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

source = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")

image = pipe(
    prompt="turn the cat into a corgi",
    image=source,
    height=1024,
    width=1024,
    num_inference_steps=28,
    generator=torch.Generator("cpu").manual_seed(42),
).images[0]
image.save("dreamlite_edit.png")

テキストから画像への変換(モバイル)

モバイルパイプラインは蒸留されており、CFGを完全にスキップします。ステップごとにUNetのフォワードが1回のみ実行されます。prompt / height / width / num_inference_steps と同じ引数を受け取りますが、guidance_scale と image_guidance_scale が渡された場合は無視されます(警告がログに記録されます)。

import torch
from diffusers import DreamLiteMobilePipeline

pipe = DreamLiteMobilePipeline.from_pretrained("carlofkl/DreamLite-mobile", revision="diffusers", dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

image = pipe(
    prompt="a dog running on the grass",
    height=1024,
    width=1024,
    num_inference_steps=4,
    generator=torch.Generator("cpu").manual_seed(42),
).images[0]
image.save("dreamlite_mobile_t2i.png")

画像編集(モバイル)

import torch
from diffusers import DreamLiteMobilePipeline
from diffusers.utils import load_image

pipe = DreamLiteMobilePipeline.from_pretrained("carlofkl/DreamLite-mobile", revision="diffusers", dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

source = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")

image = pipe(
    prompt="turn the cat into a corgi",
    image=source,
    height=1024,
    width=1024,
    num_inference_steps=4,
    generator=torch.Generator("cpu").manual_seed(42),
).images[0]
image.save("dreamlite_mobile_edit.png")

備考と制約事項

  • 両方のパイプラインは内部で batch_size = 1 を強制します。num_images_per_prompt は並列バッチ処理ではなく、同じプロンプトから何件のサンプルを生成するかを制御します。
  • プロンプトエンコーダーはマルチモーダルモデルであるQwen3-VLです。そのため、フルパイプラインの読み込みには、U-NetとQwen3-VLテキストエンコーダーの両方を収容するのに十分なGPUメモリが必要です(ベースリリースの場合、bf16でそれぞれ約4 GBと約0.7 GB)。
  • VAE は AutoencoderTiny であり、encoder_block_out_channels を公開しています。vae_scale_factor は、パイプラインの初期化時にこれから導出されます。

DreamLitePipeline[[diffusers.DreamLitePipeline]]

diffusers.DreamLitePipeline[[diffusers.DreamLitePipeline]]

diffusers.DreamLitePipeline(text_encoder: Qwen3VLForConditionalGeneration, tokenizer: AutoTokenizer, processor: Qwen3VLProcessor, vae: AutoencoderTiny, unet: DreamLiteUNetModel, scheduler: FlowMatchEulerDiscreteScheduler)

ソース

DreamLite パイプラインは、テキストから画像を生成し、指示に基づいた画像編集を行うためのものです。

同じパイプラインが両方のモードをサポートしており、動作モードは入力から自動検出されます:

  • image is None -> テキストから画像を生成(テキストに対する単一の CFG)。
  • image is not None -> 画像から画像への変換 / 指示による編集(デュアル CFG: テキスト + 画像)。

コンポーネント: text_encoder ([~transformers.Qwen3VLForConditionalGeneration]): 条件付け埋め込みを生成するために使用されるマルチモーダルなテキスト/ビジョンエンコーダー。 tokenizer ([~transformers.AutoTokenizer]): テキストのみ(generate)モード用のトークナイザー。 processor ([~transformers.Qwen3VLProcessor]): 編集モード(テキスト + 画像テンプレート)用のマルチモーダルプロセッサー。 vae ([~diffusers.AutoencoderTiny]): 潜在空間のエンコード/デコードに使用される、モバイル対応の小型 VAE。 unet ([~diffusers.DreamLiteUNetModel]): DreamLite UNet(GQA + qk_norm + depthwise-separable convs)。 scheduler ([~diffusers.FlowMatchEulerDiscreteScheduler]): 動的シフトを備えたフローマッチング・オイラー・スケジューラー。

注: batch_size は現在 1 に強制されています。num_images_per_prompt はサポートされています。

call[[diffusers.DreamLitePipeline.call]]

__call__(prompt: typing.Optional[str] = None, negative_prompt: typing.Optional[str] = None, image: typing.Optional[PIL.Image.Image] = None, height: typing.Optional[int] = None, width: typing.Optional[int] = None, guidance_scale: float = 3.5, image_guidance_scale: float = 1.5, num_inference_steps: int = 30, sigmas: typing.Optional[typing.List[float]] = None, num_images_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, max_sequence_length: int = 200, text_pad_embedding: typing.Optional[torch.Tensor] = None)

ソース

パラメータ:

prompt : テキストプロンプト。

negative_prompt : 負のテキストプロンプト(デフォルトは空文字列)。

image : Optional input image. If provided, the pipeline runs in edit / image-to-image mode with dual classifier-free guidance; otherwise it runs in text-to-image mode.

height : 出力解像度(高さ)。デフォルトは default_sample_size * vae_scale_factor(1024)です。T2I と I2I の両方で同じデフォルトが適用されます。上書きするには、明示的な値を指定してください。

width : 出力解像度(幅)。デフォルトは default_sample_size * vae_scale_factor(1024)です。T2I と I2I の両方で同じデフォルトが適用されます。上書きするには、明示的な値を指定してください。

guidance_scale : テキストブランチの CFG スケール(両方のモード)。

image_guidance_scale : 画像ブランチに追加される CFG スケール(編集モードのみ)。

num_inference_steps : デノイジングのステップ数。

sigmas : 任意の明示的な FlowMatch シグマ。デフォルトでは均等な linspace が使用されます。

num_images_per_prompt : プロンプトごとの出力画像数(注: batch_size は 1 に強制されます)。

generator : ランダムジェネレーター。

output_type : "pil"、"np"、"pt"、または "latent"。

return_dict : True の場合、DreamLitePipelineOutput を返します。それ以外の場合は、タプル (images,) を返します。

max_sequence_length : チャットテンプレートのプレフィックスを除去した後に保持される、ユーザープロンプトのトークンの最大数。generateモードでのみ適用されます(editモードでは、マルチモーダルプロセッサのネイティブなパディングが使用されます)。

text_pad_embedding : マスクされた位置用の任意の学習済みパッド埋め込み。

戻り値:

DreamLitePipelineOutput または tuple。

DreamLite パイプラインを実行します。

DreamLiteMobilePipeline[[diffusers.DreamLiteMobilePipeline]]

diffusers.DreamLiteMobilePipeline[[diffusers.DreamLiteMobilePipeline]]

diffusers.DreamLiteMobilePipeline(text_encoder: Qwen3VLForConditionalGeneration, tokenizer: AutoTokenizer, processor: Qwen3VLProcessor, vae: AutoencoderTiny, unet: DreamLiteUNetModel, scheduler: FlowMatchEulerDiscreteScheduler)

ソース

DreamLite Mobile パイプライン:DreamLitePipeline の蒸留版で、classifier-free guidance を使用しないバリアントです。高速な少ステップ推論(デフォルトは4ステップ)に最適化されています。

動作モードは入力から自動検出されます(ベースのpipelineと同じです):

  • image is None -> テキストから画像を生成。
  • image is not None -> 画像から画像への変換 / 指示による編集。

Classifier-free guidance が蒸留によって除去されるため、guidance_scaleおよびimage_guidance_scaleはDreamLitePipelineとの API 互換性のために受け入れられますが、デノイジングループでは無視されます。negative_promptは意図的に省略されています。

Components (ベースのパイプラインと同一): text_encoder ([~transformers.Qwen3VLForConditionalGeneration]): マルチモーダルなテキスト/ビジョンエンコーダー。 tokenizer ([~transformers.AutoTokenizer]): テキストのみ(generate)モード用のトークナイザー。 processor ([~transformers.Qwen3VLProcessor]): 編集モード用のマルチモーダルプロセッサー。 vae ([~diffusers.AutoencoderTiny]): モバイル対応の小型VAE。 unet ([~diffusers.DreamLiteUNetModel]): DreamLite UNet。 scheduler ([~diffusers.FlowMatchEulerDiscreteScheduler]): 動的シフトを備えたフローマッチングEulerスケジューラー。

注: batch_size は現在 1 に強制されています。num_images_per_prompt はサポートされています。

call[[diffusers.DreamLiteMobilePipeline.call]]

__call__(prompt: typing.Union[str, typing.List[str]] = None, image: typing.Optional[PIL.Image.Image] = None, height: typing.Optional[int] = None, width: typing.Optional[int] = None, num_inference_steps: int = 4, guidance_scale: typing.Optional[float] = None, image_guidance_scale: typing.Optional[float] = None, sigmas: typing.Optional[typing.List[float]] = None, num_images_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, max_sequence_length: int = 200, text_pad_embedding: typing.Optional[torch.Tensor] = None)

ソース

パラメータ:

prompt : テキストプロンプト。

image : 任意の入力画像。指定された場合はedit / image-to-imageモードで実行され、指定されない場合はtext-to-imageモードで実行されます。

height : 出力解像度(高さ)。デフォルトは default_sample_size * vae_scale_factor(1024)です。

width : 出力解像度(幅)。デフォルトは default_sample_size * vae_scale_factor(1024)です。

num_inference_steps : デノイジングのステップ数。デフォルトは4(蒸留済み)です。

guidance_scale : DreamLitePipelineとのAPI互換性を確保するために受け入れられています。無視されます。CFGは蒸留によって除去されているためです。

image_guidance_scale : DreamLitePipelineとのAPI互換性を確保するために受け入れられています。無視されます。CFGは蒸留によって除去されているためです。

sigmas : 任意の明示的な FlowMatch シグマ。デフォルトでは均等な linspace が使用されます。

num_images_per_prompt : プロンプトごとの出力画像数(注: batch_size は 1 に強制されます)。

generator : ランダムジェネレーター。

output_type : "pil"、"np"、"pt"、または "latent"。

return_dict : True の場合、DreamLitePipelineOutput を返します。それ以外の場合は (images,) を返します。

max_sequence_length : チャットテンプレートのプレフィックスを除去した後に保持される、ユーザープロンプトのトークンの最大数。generateモードでのみ適用されます(editモードでは、マルチモーダルプロセッサのネイティブなパディングが使用されます)。

text_pad_embedding : マスクされた位置用の任意の学習済みパッド埋め込み。

戻り値:

DreamLitePipelineOutput または tuple。

蒸留された DreamLite Mobile パイプラインを実行します。

DreamLitePipelineOutput[[diffusers.DreamLitePipelineOutput]]

diffusers.DreamLitePipelineOutput[[diffusers.DreamLitePipelineOutput]]

diffusers.DreamLitePipelineOutput(images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray])

ソース

パラメータ:

images (List[PIL.Image.Image] または np.ndarray) : 長さ batch_size のデノイズ済み PIL イメージのリスト、または形状 (batch_size, height, width, num_channels) の NumPy 配列。PIL イメージまたは NumPy 配列は、拡散パイプラインのデノイズ済みイメージを表します。

DreamLite パイプライン用の出力クラスです。

Xet Storage Details

Size:
17.6 kB
·
Xet hash:
4f2f3e3962c5e78901d01b26a5c05036ea070cf47c0cf93cdca1030456cb4750

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.