# DreamLite

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

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

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

公式チェックポイント:

* ベースモデル: [carlofkl/DreamLite-base](https://huggingface.co/carlofkl/DreamLite-base)
* 蒸留されたモバイルモデル: [carlofkl/DreamLite-mobile](https://huggingface.co/carlofkl/DreamLite-mobile)

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

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

## テキストから画像へ（Base）

```python
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`（イメージブランチ）の両方が有効になります。

```python
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` が渡された場合は**無視**されます（警告がログに記録されます）。

```python
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")
```

## 画像編集（モバイル）

```python
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]]

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

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dreamlite/pipeline_dreamlite.py#L155)

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__]]

```python
__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)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dreamlite/pipeline_dreamlite.py#L388)

**パラメータ:**

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](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipelineOutput) を返します。それ以外の場合は、タプル `(images,)` を返します。

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

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

**戻り値:**

[DreamLitePipelineOutput](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipelineOutput) または `tuple`。

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

## DreamLiteMobilePipeline[[diffusers.DreamLiteMobilePipeline]]

#### diffusers.DreamLiteMobilePipeline[[diffusers.DreamLiteMobilePipeline]]

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

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dreamlite/pipeline_dreamlite_mobile.py#L156)

DreamLite **Mobile** パイプライン:[DreamLitePipeline](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipeline) の蒸留版で、classifier-free guidance を使用しないバリアントです。高速な少ステップ推論(デフォルトは4ステップ)に最適化されています。

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

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

Classifier-free guidance が**蒸留によって除去される**ため、`guidance_scale`および`image_guidance_scale`は[DreamLitePipeline](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.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__]]

```python
__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)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dreamlite/pipeline_dreamlite_mobile.py#L384)

**パラメータ:**

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](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipeline)とのAPI互換性を確保するために受け入れられています。**無視**されます。CFGは蒸留によって除去されているためです。

image_guidance_scale : [DreamLitePipeline](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipeline)とのAPI互換性を確保するために受け入れられています。**無視**されます。CFGは蒸留によって除去されているためです。

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

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

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

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

return_dict : True の場合、[DreamLitePipelineOutput](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipelineOutput) を返します。それ以外の場合は `(images,)` を返します。

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

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

**戻り値:**

[DreamLitePipelineOutput](/docs/diffusers/v0.43.0/ja/api/pipelines/dreamlite#diffusers.DreamLitePipelineOutput) または `tuple`。

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

## DreamLitePipelineOutput[[diffusers.DreamLitePipelineOutput]]

#### diffusers.DreamLitePipelineOutput[[diffusers.DreamLitePipelineOutput]]

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

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dreamlite/pipeline_output.py#L25)

**パラメータ:**

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

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

