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.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DreamLite

DreamLite 是字节跳动推出的一款文本生成图像及图像编辑模型。它采用自定义的 2D U-Net(DreamLiteUNetModel),并搭配 Qwen3-VL 多模态编码器作为提示词 / 图像指令编码器,同时使用 AutoencoderTiny(TAESD 风格)VAE 来实现快速的潜在空间编码与解码。

暴露了两个流水线:

Pipeline模式CFG用例
DreamLitePipeline文本到图像 以及 图像编辑(根据 image 是否为 None 自动选择)3 分支双 CFG(guidance_scale 用于文本分支,image_guidance_scale 用于图像分支,类似 InstructPix2Pix)最高质量
DreamLiteMobilePipeline文本到图像以及图像编辑(根据image是否为None自动选择)无 — 蒸馏,每步仅执行一次 UNet 前向传播设备端 / 低延迟

官方检查点:

两条流水线均根据是否提供了 image 参数,自动检测是文本生成图像模式还是图像编辑模式。不存在单独的 Img2Img 类。

在加载用于编辑的输入图像时,请优先使用 diffusers.utils.load_image(...),而不是直接使用 PIL.Image.open(...)。load_image 会强制执行 RGB 转换并应用 EXIF 方向,而流水线默认依赖这两项处理。 如果直接对 RGBA / 调色板 / 带有 EXIF 旋转的源图像使用 Image.open,会静默地产生不同的潜在条件,从而降低输出质量。

文本到图像(基础)

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

图像编辑(基础)

传入 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 前向传播。它接受相同的 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,这是一个多模态模型。因此,加载完整流水线需要足够的 GPU 显存来同时容纳 U-Net 和 Qwen3-VL 文本编码器(基础版本在 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 + 深度可分离卷积)。 scheduler ([~diffusers.FlowMatchEulerDiscreteScheduler]): 具有动态 shift 的 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 — 可选的输入图像。如果提供,则流水线以 编辑 / 图生图 模式运行,并采用双分类器自由引导;否则以 文生图 模式运行。
  • 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 sigmas;默认使用均匀 linspace。
  • num_images_per_prompt — 每个提示词生成的图像数量(注意:batch_size 会被强制设为 1)。
  • generator — 随机数生成器。
  • output_type — "pil"、"np"、"pt" 或 "latent"。
  • return_dict — 如果为 True,则返回 DreamLitePipelineOutput;否则返回元组 (images,)。
  • max_sequence_length — 在去除聊天模板前缀后,保留的用户提示词 token 的最大数量。仅适用于 generate 模式(edit 模式使用多模态处理器的原生填充)。
  • text_pad_embedding — 用于掩码位置的可选学习填充嵌入。

运行 DreamLite 流水线。

DreamLiteMobilePipeline

class diffusers.DreamLiteMobilePipeline

< >

( text_encoder: Qwen3VLForConditionalGenerationtokenizer: AutoTokenizerprocessor: Qwen3VLProcessorvae: AutoencoderTinyunet: DreamLiteUNetModelscheduler: FlowMatchEulerDiscreteScheduler )

DreamLite Mobile 流水线:DreamLitePipeline 的蒸馏变体,无需分类器自由引导,适用于快速少步推理(默认 4 步)。

运行模式会根据输入自动检测(与基础流水线相同):

  • 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]): 具有动态 shift 的 Flow-matching Euler 调度器。

注意: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 — 可选的输入图像。如果提供,则以 编辑 / 图生图 模式运行;否则以 文生图 模式运行。
  • 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 sigmas;默认使用均匀 linspace。
  • num_images_per_prompt — 每个提示词生成的图像数量(注意:batch_size 会被强制设为 1)。
  • generator — 随机数生成器。
  • output_type — "pil"、"np"、"pt" 或 "latent"。
  • return_dict — 如果为 True,则返回 DreamLitePipelineOutput;否则返回 (images,)。
  • max_sequence_length — 在去除聊天模板前缀后,保留的用户提示词 token 的最大数量。仅适用于 generate 模式(edit 模式使用多模态处理器的原生填充)。
  • text_pad_embedding — 用于掩码位置的可选学习填充嵌入。

运行蒸馏后的 DreamLite Mobile 流水线。

DreamLitePipelineOutput

class 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