Diffusers documentation

DreamLite

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

class diffusers.DreamLitePipeline

< >

( text_encoder: Qwen3VLForConditionalGenerationtokenizer: AutoTokenizerprocessor: Qwen3VLProcessorvae: AutoencoderTinyunet: DreamLiteUNetModelscheduler: 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]): 動的シフトを備えた Flow-matching Euler スケジューラー。

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

__call__

< >

( prompt: typing.Optional[str] = Nonenegative_prompt: typing.Optional[str] = Noneimage: typing.Optional[PIL.Image.Image] = Noneheight: typing.Optional[int] = Nonewidth: typing.Optional[int] = Noneguidance_scale: float = 3.5image_guidance_scale: float = 1.5num_inference_steps: int = 30sigmas: typing.Optional[typing.List[float]] = Nonenum_images_per_prompt: typing.Optional[int] = 1generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = Noneoutput_type: typing.Optional[str] = 'pil'return_dict: bool = Truemax_sequence_length: int = 200text_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 を返します。False の場合、タプル (images,) を返します。
  • max_sequence_length — チャットテンプレートのプレフィックスを除去した後に保持される、ユーザープロンプトのトークン数の上限です。generateモードでのみ適用されます(editモードでは、マルチモーダルプロセッサのネイティブなパディングを使用します)。
  • text_pad_embedding — マスクされた位置用の、学習可能なパッド埋め込み(オプション)。

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

DreamLiteMobilePipeline

class diffusers.DreamLiteMobilePipeline

< >

( text_encoder: Qwen3VLForConditionalGenerationtokenizer: AutoTokenizerprocessor: Qwen3VLProcessorvae: AutoencoderTinyunet: DreamLiteUNetModelscheduler: 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 は意図的に省略されています。

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

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

__call__

< >

( prompt: typing.Union[str, typing.List[str]] = Noneimage: typing.Optional[PIL.Image.Image] = Noneheight: typing.Optional[int] = Nonewidth: typing.Optional[int] = Nonenum_inference_steps: int = 4guidance_scale: typing.Optional[float] = Noneimage_guidance_scale: typing.Optional[float] = Nonesigmas: typing.Optional[typing.List[float]] = Nonenum_images_per_prompt: typing.Optional[int] = 1generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = Noneoutput_type: typing.Optional[str] = 'pil'return_dict: bool = Truemax_sequence_length: int = 200text_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 — マスクされた位置用の、学習可能なパッド埋め込み(オプション)。

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

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 パイプライン用の出力クラスです。

Update on GitHub