Diffusers 文档
香肠
并获取增强的文档体验
开始使用
Würstchen (香肠)
Wuerstchen: An Efficient Architecture for Large-Scale Text-to-Image Diffusion Models 由 Pablo Pernias, Dominic Rampas, Mats L. Richter 和 Christopher Pal 以及 Marc Aubreville 撰写。
论文摘要如下
我们介绍了 Würstchen,这是一种用于文本到图像合成的新颖架构,它将竞争性能与大规模文本到图像扩散模型前所未有的成本效益相结合。我们工作的一个关键贡献是开发了一种潜在扩散技术,我们在其中学习了一种详细但极其紧凑的语义图像表示,用于指导扩散过程。与语言的潜在表示相比,这种高度压缩的图像表示提供了更详细的指导,这显着降低了实现最先进结果的计算要求。我们的方法还根据我们的用户偏好研究提高了文本条件图像生成的质量。我们的方法的训练要求包括 24,602 个 A100-GPU 小时 - 相比之下,Stable Diffusion 2.1 的训练时间为 200,000 GPU 小时。我们的方法还需要更少的训练数据才能实现这些结果。此外,我们紧凑的潜在表示使我们能够以两倍以上的速度执行推理,从而显着降低了最先进 (SOTA) 扩散模型的常用成本和碳足迹,而不会影响最终性能。在与 SOTA 模型进行的更广泛的比较中,我们的方法效率更高,并且在图像质量方面表现出色。我们认为,这项工作促使人们更加重视性能和计算可访问性的优先次序。
香肠 (Würstchen) 概览
香肠 (Würstchen) 是一个扩散模型,其文本条件模型在图像的高度压缩潜在空间中工作。为什么这很重要?压缩数据可以大幅度降低训练和推理的计算成本。在 1024x1024 图像上训练比在 32x32 图像上训练昂贵得多。通常,其他工作使用相对较小的压缩,范围在 4 倍 - 8 倍空间压缩。香肠 (Würstchen) 将此推向了极致。通过其新颖的设计,我们实现了 42 倍的空间压缩。这在以前是闻所未闻的,因为常见的方法在 16 倍空间压缩后无法忠实地重建详细的图像。香肠 (Würstchen) 采用两阶段压缩,我们称之为 Stage A 和 Stage B。Stage A 是一个 VQGAN,Stage B 是一个扩散自编码器(更多细节可以在论文中找到)。第三个模型 Stage C 在高度压缩的潜在空间中学习。这种训练所需的计算量仅为当前表现最佳模型的一小部分,同时还允许更便宜、更快速的推理。
香肠 (Würstchen) v2 加入 Diffusers
在最初的论文发布后,我们在架构、训练和采样方面改进了很多,使得香肠 (Würstchen) 在许多方面都与当前最先进的模型相媲美。我们很高兴与 Diffusers 一起发布这个新版本。以下是改进列表。
- 更高的分辨率(1024x1024 到高达 2048x2048)
- 更快的推理速度
- 多宽高比分辨率采样
- 更好的质量
我们正在发布 3 个用于文本条件图像生成模型(Stage C)的检查点。它们是
- v2-base
- v2-aesthetic
- (默认) v2-interpolated(v2-base 和 v2-aesthetic 之间 50% 的插值)
我们建议使用 v2-interpolated,因为它兼具照片真实感和美感。使用 v2-base 进行微调,因为它没有风格偏见,使用 v2-aesthetic 进行非常艺术的生成。可以在这里看到比较
文本到图像生成
为了可用性,香肠 (Würstchen) 可以使用单个 pipeline。这个 pipeline 可以如下使用
import torch
from diffusers import AutoPipelineForText2Image
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS
pipe = AutoPipelineForText2Image.from_pretrained("warp-ai/wuerstchen", torch_dtype=torch.float16).to("cuda")
caption = "Anthropomorphic cat dressed as a fire fighter"
images = pipe(
caption,
width=1024,
height=1536,
prior_timesteps=DEFAULT_STAGE_C_TIMESTEPS,
prior_guidance_scale=4.0,
num_images_per_prompt=2,
).images
为了解释目的,我们也可以单独初始化香肠 (Würstchen) 的两个主要 pipeline。香肠 (Würstchen) 由 3 个阶段组成:Stage C、Stage B、Stage A。它们都有不同的工作,并且只能协同工作。当生成文本条件图像时,Stage C 将首先在高度压缩的潜在空间中生成潜在变量。这就是 prior_pipeline
中发生的事情。之后,生成的潜在变量将传递到 Stage B,Stage B 将潜在变量解压缩为 VQGAN 的更大的潜在空间。然后,这些潜在变量可以由 Stage A(一个 VQGAN)解码为像素空间。Stage B 和 Stage A 都封装在 decoder_pipeline
中。有关更多详细信息,请查看论文。
import torch
from diffusers import WuerstchenDecoderPipeline, WuerstchenPriorPipeline
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS
device = "cuda"
dtype = torch.float16
num_images_per_prompt = 2
prior_pipeline = WuerstchenPriorPipeline.from_pretrained(
"warp-ai/wuerstchen-prior", torch_dtype=dtype
).to(device)
decoder_pipeline = WuerstchenDecoderPipeline.from_pretrained(
"warp-ai/wuerstchen", torch_dtype=dtype
).to(device)
caption = "Anthropomorphic cat dressed as a fire fighter"
negative_prompt = ""
prior_output = prior_pipeline(
prompt=caption,
height=1024,
width=1536,
timesteps=DEFAULT_STAGE_C_TIMESTEPS,
negative_prompt=negative_prompt,
guidance_scale=4.0,
num_images_per_prompt=num_images_per_prompt,
)
decoder_output = decoder_pipeline(
image_embeddings=prior_output.image_embeddings,
prompt=caption,
negative_prompt=negative_prompt,
guidance_scale=0.0,
output_type="pil",
).images[0]
decoder_output
加速推理
你可以使用 torch.compile
函数,获得约 2-3 倍的加速
prior_pipeline.prior = torch.compile(prior_pipeline.prior, mode="reduce-overhead", fullgraph=True)
decoder_pipeline.decoder = torch.compile(decoder_pipeline.decoder, mode="reduce-overhead", fullgraph=True)
局限性
- 由于香肠 (Würstchen) 采用了高压缩,生成图像可能会缺少大量细节。对于我们人类的眼睛来说,这在面部、手部等部位尤其明显。
- 图像只能以 128 像素步长生成,例如,1024x1024 之后的下一个更高分辨率是 1152x1152
- 该模型缺乏在图像中渲染正确文本的能力
- 该模型通常无法实现照片真实感
- 对于模型来说,复杂的构图提示词很难处理
原始代码库以及实验性想法可以在 dome272/Wuerstchen 找到。
WuerstchenCombinedPipeline
class diffusers.WuerstchenCombinedPipeline
< source >( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel decoder: WuerstchenDiffNeXt scheduler: DDPMWuerstchenScheduler vqgan: PaellaVQModel prior_tokenizer: CLIPTokenizer prior_text_encoder: CLIPTextModel prior_prior: WuerstchenPrior prior_scheduler: DDPMWuerstchenScheduler )
参数
- tokenizer (
CLIPTokenizer
) — 用于文本输入的解码器 tokenizer。 - text_encoder (
CLIPTextModel
) — 用于文本输入的解码器文本编码器。 - decoder (
WuerstchenDiffNeXt
) — 用于解码器图像生成 pipeline 的解码器模型。 - scheduler (
DDPMWuerstchenScheduler
) — 用于解码器图像生成 pipeline 的调度器。 - vqgan (
PaellaVQModel
) — 用于解码器图像生成 pipeline 的 VQGAN 模型。 - prior_tokenizer (
CLIPTokenizer
) — 用于文本输入的先验 tokenizer。 - prior_text_encoder (
CLIPTextModel
) — 用于文本输入的先验文本编码器。 - prior_prior (
WuerstchenPrior
) — 用于先验 pipeline 的先验模型。 - prior_scheduler (
DDPMWuerstchenScheduler
) — 用于先验 pipeline 的调度器。
用于文本到图像生成的组合 Pipeline,使用 Wuerstchen
此模型继承自 DiffusionPipeline。查看超类文档,了解库为所有 pipeline 实现的通用方法(例如下载或保存、在特定设备上运行等)。
__call__
< source >( prompt: typing.Union[str, typing.List[str], NoneType] = None height: int = 512 width: int = 512 prior_num_inference_steps: int = 60 prior_timesteps: typing.Optional[typing.List[float]] = None prior_guidance_scale: float = 4.0 num_inference_steps: int = 12 decoder_timesteps: typing.Optional[typing.List[float]] = None decoder_guidance_scale: float = 0.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None num_images_per_prompt: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True prior_callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None prior_callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )
参数
- prompt (
str
或List[str]
) — 用于引导先验和解码器图像生成的提示或提示列表。 - negative_prompt (
str
或List[str]
, 可选) — 不用于引导图像生成的提示或提示列表。当不使用引导时忽略(即,如果guidance_scale
小于1
,则忽略)。 - prompt_embeds (
torch.Tensor
, 可选) — 先验的预生成文本嵌入。可用于轻松调整文本输入,例如 提示词权重。如果未提供,将从prompt
输入参数生成文本嵌入。 - negative_prompt_embeds (
torch.Tensor
, 可选) — 先验的预生成负面文本嵌入。可用于轻松调整文本输入,例如 提示词权重。如果未提供,将从negative_prompt
输入参数生成 negative_prompt_embeds。 - num_images_per_prompt (
int
, 可选, 默认为 1) — 每个提示要生成的图像数量。 - height (
int
, 可选, 默认为 512) — 生成图像的高度,以像素为单位。 - width (
int
, 可选,默认为 512) — 生成图像的像素宽度。 - prior_guidance_scale (
float
, 可选,默认为 4.0) — Guidance scale(引导比例),定义见 Classifier-Free Diffusion Guidance。prior_guidance_scale
定义为 Imagen Paper 方程式 2 中的w
。通过设置prior_guidance_scale > 1
启用 Guidance scale。较高的 guidance scale 会鼓励生成与文本prompt
紧密相关的图像,但通常会以降低图像质量为代价。 - prior_num_inference_steps (
Union[int, Dict[float, int]]
, 可选,默认为 60) — Prior 去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会牺牲推理速度。对于更具体的时间步长间隔,您可以传递自定义的prior_timesteps
。 - num_inference_steps (
int
, 可选,默认为 12) — 解码器去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会牺牲推理速度。对于更具体的时间步长间隔,您可以传递自定义的timesteps
。 - prior_timesteps (
List[float]
, 可选) — 用于 prior 的去噪过程的自定义时间步长。如果未定义,则使用等间距的prior_num_inference_steps
时间步长。必须以降序排列。 - decoder_timesteps (
List[float]
, 可选) — 用于解码器的去噪过程的自定义时间步长。如果未定义,则使用等间距的num_inference_steps
时间步长。必须以降序排列。 - decoder_guidance_scale (
float
, 可选,默认为 0.0) — Guidance scale(引导比例),定义见 Classifier-Free Diffusion Guidance。guidance_scale
定义为 Imagen Paper 方程式 2 中的w
。通过设置guidance_scale > 1
启用 Guidance scale。较高的 guidance scale 会鼓励生成与文本prompt
紧密相关的图像,但通常会以降低图像质量为代价。 - generator (
torch.Generator
或List[torch.Generator]
, 可选) — 一个或一组 torch generator(s),用于使生成结果确定。 - latents (
torch.Tensor
, 可选) — 预生成的噪声潜变量,从高斯分布中采样,用作图像生成的输入。可用于通过不同的 prompts 调整相同的生成结果。如果未提供,将使用提供的随机generator
采样生成潜变量张量。 - output_type (
str
, 可选,默认为"pil"
) — 生成图像的输出格式。从以下选项中选择:"pil"
(PIL.Image.Image
),"np"
(np.array
) 或"pt"
(torch.Tensor
)。 - return_dict (
bool
, 可选,默认为True
) — 是否返回 ImagePipelineOutput 而不是普通的元组。 - prior_callback_on_step_end (
Callable
, 可选) — 一个在推理期间每个去噪步骤结束时调用的函数。该函数使用以下参数调用:prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)
。 - prior_callback_on_step_end_tensor_inputs (
List
, 可选) —prior_callback_on_step_end
函数的张量输入列表。列表中指定的张量将作为callback_kwargs
参数传递。您将只能包含管道类._callback_tensor_inputs
属性中列出的变量。 - callback_on_step_end (
Callable
, 可选) — 一个在推理期间每个去噪步骤结束时调用的函数。该函数使用以下参数调用:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)
。callback_kwargs
将包含callback_on_step_end_tensor_inputs
指定的所有张量的列表。 - callback_on_step_end_tensor_inputs (
List
, 可选) —callback_on_step_end
函数的张量输入列表。列表中指定的张量将作为callback_kwargs
参数传递。您将只能包含管道类._callback_tensor_inputs
属性中列出的变量。
调用管道进行生成时调用的函数。
enable_model_cpu_offload
< source >( gpu_id: typing.Optional[int] = None device: typing.Union[torch.device, str] = 'cuda' )
使用 accelerate 将所有模型卸载到 CPU,从而降低内存使用量,且对性能的影响很小。与 enable_sequential_cpu_offload
相比,此方法在调用模型的 forward
方法时,一次将一个完整模型移动到 GPU,并且该模型会保留在 GPU 中,直到下一个模型运行。内存节省低于 enable_sequential_cpu_offload
,但由于 unet
的迭代执行,性能要好得多。
enable_sequential_cpu_offload
< source >( gpu_id: typing.Optional[int] = None device: typing.Union[torch.device, str] = 'cuda' )
使用 🤗 Accelerate 将所有模型(unet
、text_encoder
、vae
和 safety checker
状态字典)卸载到 CPU,从而显著降低内存使用量。模型被移动到 torch.device('meta')
,并且仅在其特定子模块的 forward
方法被调用时才加载到 GPU 上。卸载是基于子模块进行的。内存节省高于使用 enable_model_cpu_offload
,但性能较低。
WuerstchenPriorPipeline
class diffusers.WuerstchenPriorPipeline
< source >( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel prior: WuerstchenPrior scheduler: DDPMWuerstchenScheduler latent_mean: float = 42.0 latent_std: float = 1.0 resolution_multiple: float = 42.67 )
参数
- prior (
Prior
) — 标准的 unCLIP prior,用于从文本嵌入近似图像嵌入。 - text_encoder (
CLIPTextModelWithProjection
) — 冻结的文本编码器。 - tokenizer (
CLIPTokenizer
) — CLIPTokenizer 类的分词器。 - scheduler (
DDPMWuerstchenScheduler
) — 一个调度器,与prior
结合使用以生成图像嵌入。 - latent_mean (‘float’, optional, defaults to 42.0) — 潜在扩散模型的均值,默认为 42.0。
- latent_std (‘float’, optional, defaults to 1.0) — 潜在扩散模型的标准差,默认为 1.0。
- resolution_multiple (‘float’, optional, defaults to 42.67) — 生成多张图像的默认分辨率倍数,默认为 42.67。
用于为 Wuerstchen 生成图像先验的 Pipeline。
此模型继承自 DiffusionPipeline。查看超类文档,了解库为所有 pipeline 实现的通用方法(例如下载或保存、在特定设备上运行等)。
该 pipeline 还继承了以下加载方法
- load_lora_weights() 用于加载 LoRA 权重
- save_lora_weights() 用于保存 LoRA 权重
__call__
< source >( prompt: typing.Union[str, typing.List[str], NoneType] = None height: int = 1024 width: int = 1024 num_inference_steps: int = 60 timesteps: typing.List[float] = None guidance_scale: float = 8.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None num_images_per_prompt: typing.Optional[int] = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pt' return_dict: bool = True callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )
参数
- prompt (
str
orList[str]
) — 用于引导图像生成的提示或提示列表。 - height (
int
, optional, defaults to 1024) — 生成图像的高度像素,默认为 1024。 - width (
int
, optional, defaults to 1024) — 生成图像的宽度像素,默认为 1024。 - num_inference_steps (
int
, optional, defaults to 60) — 去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会牺牲推理速度,默认为 60。 - timesteps (
List[int]
, optional) — 用于去噪过程的自定义时间步长。如果未定义,则使用等间距的num_inference_steps
时间步长。必须以降序排列。 - guidance_scale (
float
, optional, defaults to 8.0) — 指导比例,定义见 Classifier-Free Diffusion Guidance。decoder_guidance_scale
定义为 Imagen Paper 的公式 2 中的w
。通过设置decoder_guidance_scale > 1
启用指导比例。更高的指导比例鼓励生成与文本prompt
紧密相关的图像,但通常以降低图像质量为代价,默认为 8.0。 - negative_prompt (
str
orList[str]
, optional) — 不用于引导图像生成的提示或提示列表。当不使用指导时会被忽略(即,如果decoder_guidance_scale
小于1
,则忽略)。 - prompt_embeds (
torch.Tensor
, optional) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词权重。如果未提供,则将从prompt
输入参数生成文本嵌入。 - negative_prompt_embeds (
torch.Tensor
, optional) — 预生成的负面文本嵌入。可用于轻松调整文本输入,例如 提示词权重。如果未提供,则将从negative_prompt
输入参数生成 negative_prompt_embeds。 - num_images_per_prompt (
int
, optional, defaults to 1) — 每个提示要生成的图像数量,默认为 1。 - generator (
torch.Generator
orList[torch.Generator]
, optional) — 一个或多个 torch generator(s),用于使生成具有确定性。 - latents (
torch.Tensor
, optional) — 预生成的噪声潜在变量,从高斯分布中采样,用作图像生成的输入。可用于使用不同的提示调整相同的生成。如果未提供,则将使用提供的随机generator
采样生成潜在张量。 - output_type (
str
, optional, defaults to"pil"
) — 生成图像的输出格式。从以下选项中选择:"pil"
(PIL.Image.Image
)、"np"
(np.array
) 或"pt"
(torch.Tensor
),默认为"pil"
。 - return_dict (
bool
, optional, defaults toTrue
) — 是否返回 ImagePipelineOutput 而不是普通元组,默认为True
。 - callback_on_step_end (
Callable
, optional) — 一个函数,在推理期间的每个去噪步骤结束时调用。该函数使用以下参数调用:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)
。callback_kwargs
将包含由callback_on_step_end_tensor_inputs
指定的所有张量列表。 - callback_on_step_end_tensor_inputs (
List
, optional) —callback_on_step_end
函数的张量输入列表。列表中指定的张量将作为callback_kwargs
参数传递。您将只能包含 pipeline 类的._callback_tensor_inputs
属性中列出的变量。
调用管道进行生成时调用的函数。
示例
>>> import torch
>>> from diffusers import WuerstchenPriorPipeline
>>> prior_pipe = WuerstchenPriorPipeline.from_pretrained(
... "warp-ai/wuerstchen-prior", torch_dtype=torch.float16
... ).to("cuda")
>>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
>>> prior_output = pipe(prompt)
WuerstchenPriorPipelineOutput
class diffusers.pipelines.wuerstchen.pipeline_wuerstchen_prior.WuerstchenPriorPipelineOutput
< source >( image_embeddings: typing.Union[torch.Tensor, numpy.ndarray] )
WuerstchenPriorPipeline 的输出类。
WuerstchenDecoderPipeline
class diffusers.WuerstchenDecoderPipeline
< source >( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel decoder: WuerstchenDiffNeXt scheduler: DDPMWuerstchenScheduler vqgan: PaellaVQModel latent_dim_scale: float = 10.67 )
参数
- tokenizer (
CLIPTokenizer
) — CLIP tokenizer(CLIP 分词器)。 - text_encoder (
CLIPTextModel
) — CLIP 文本编码器。 - decoder (
WuerstchenDiffNeXt
) — WuerstchenDiffNeXt unet 解码器。 - vqgan (
PaellaVQModel
) — VQGAN 模型。 - scheduler (
DDPMWuerstchenScheduler
) — 调度器,与prior
结合使用以生成图像嵌入。 - latent_dim_scale (float,
optional
, defaults to 10.67) — 乘数,用于根据图像嵌入确定 VQ 潜在空间大小。如果图像嵌入的高度=24,宽度=24,则 VQ 潜在形状需要高度=int(2410.67)=256,宽度=int(2410.67)=256,以匹配训练条件。
用于从 Wuerstchen 模型生成图像的 Pipeline。
此模型继承自 DiffusionPipeline。查看超类文档,了解库为所有 pipeline 实现的通用方法(例如下载或保存、在特定设备上运行等)。
__call__
< source >( image_embeddings: typing.Union[torch.Tensor, typing.List[torch.Tensor]] prompt: typing.Union[str, typing.List[str]] = None num_inference_steps: int = 12 timesteps: typing.Optional[typing.List[float]] = None guidance_scale: float = 0.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None num_images_per_prompt: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )
参数
- image_embedding (
torch.Tensor
orList[torch.Tensor]
) — 图像嵌入,可以是从图像中提取的,也可以是由 Prior 模型生成的。 - prompt (
str
orList[str]
) — 提示或提示语,用于引导图像生成。 - num_inference_steps (
int
, optional, defaults to 12) — 去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会牺牲较慢的推理速度。 - timesteps (
List[int]
, optional) — 用于去噪过程的自定义时间步长。如果未定义,则使用等间距的num_inference_steps
时间步长。必须以降序排列。 - guidance_scale (
float
, optional, defaults to 0.0) — Guidance scale(引导缩放比例),定义见 Classifier-Free Diffusion Guidance。decoder_guidance_scale
定义为 Imagen Paper 的公式 2 中的w
。通过设置decoder_guidance_scale > 1
启用引导缩放比例。较高的引导缩放比例鼓励生成与文本prompt
紧密相关的图像,但通常以降低图像质量为代价。 - negative_prompt (
str
orList[str]
, optional) — 不用于引导图像生成的提示或提示语。当不使用引导时忽略(即,如果decoder_guidance_scale
小于1
则忽略)。 - num_images_per_prompt (
int
, optional, defaults to 1) — 每个提示要生成的图像数量。 - generator (
torch.Generator
orList[torch.Generator]
, optional) — 一个或一组 torch generator(s),用于使生成具有确定性。 - latents (
torch.Tensor
, optional) — 预生成的噪声潜在变量,从高斯分布中采样,用作图像生成的输入。可用于使用不同的提示调整相同的生成。如果未提供,将通过使用提供的随机generator
采样来生成潜在张量。 - output_type (
str
, optional, defaults to"pil"
) — 生成图像的输出格式。在以下选项中选择:"pil"
(PIL.Image.Image
)、"np"
(np.array
) 或"pt"
(torch.Tensor
)。 - return_dict (
bool
, optional, defaults toTrue
) — 是否返回 ImagePipelineOutput 而不是普通元组。 - callback_on_step_end (
Callable
, optional) — 在推理期间的每个去噪步骤结束时调用的函数。该函数使用以下参数调用:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)
。callback_kwargs
将包含callback_on_step_end_tensor_inputs
指定的所有张量的列表。 - callback_on_step_end_tensor_inputs (
List
, optional) —callback_on_step_end
函数的张量输入列表。列表中指定的张量将作为callback_kwargs
参数传递。您将只能包含管道类的._callback_tensor_inputs
属性中列出的变量。
调用管道进行生成时调用的函数。
示例
>>> import torch
>>> from diffusers import WuerstchenPriorPipeline, WuerstchenDecoderPipeline
>>> prior_pipe = WuerstchenPriorPipeline.from_pretrained(
... "warp-ai/wuerstchen-prior", torch_dtype=torch.float16
... ).to("cuda")
>>> gen_pipe = WuerstchenDecoderPipeline.from_pretrain("warp-ai/wuerstchen", torch_dtype=torch.float16).to(
... "cuda"
... )
>>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
>>> prior_output = pipe(prompt)
>>> images = gen_pipe(prior_output.image_embeddings, prompt=prompt)
Citation(引用)
@misc{pernias2023wuerstchen,
title={Wuerstchen: An Efficient Architecture for Large-Scale Text-to-Image Diffusion Models},
author={Pablo Pernias and Dominic Rampas and Mats L. Richter and Christopher J. Pal and Marc Aubreville},
year={2023},
eprint={2306.00637},
archivePrefix={arXiv},
primaryClass={cs.CV}
}