Diffusers 文档
阿莱格罗
并获得增强的文档体验
开始使用
阿莱格罗
Allegro:打开商业级视频生成模型的黑匣子 来自 RhymesAI,作者:Yuan Zhou、Qiuyue Wang、Yuxuan Cai、Huan Yang。
论文摘要如下
视频生成领域取得了显著进展,开源社区为训练高质量模型贡献了大量的研究论文和工具。然而,尽管做出了这些努力,但可用的信息和资源仍然不足以实现商业级性能。在本报告中,我们打开黑匣子,介绍了 Allegro,这是一种在质量和时间一致性方面都表现出色的先进视频生成模型。我们还强调了该领域当前的局限性,并提出了一个用于训练高性能商业级视频生成模型的综合方法,解决了数据、模型架构、训练流程和评估等关键方面。我们的用户研究表明,Allegro 超过了现有的开源模型和大多数商业模型,排名仅次于 Hailuo 和 Kling。代码:https://github.com/rhymes-ai/Allegro ,模型:https://huggingface.co/rhymes-ai/Allegro ,图库:https://rhymes.ai/allegro_gallery 。
请务必查看 Schedulers 指南,了解如何探索 scheduler 速度和质量之间的权衡,并查看 跨 pipelines 重用组件 部分,了解如何有效地将相同组件加载到多个 pipelines 中。
AllegroPipeline
class diffusers.AllegroPipeline
< source >( tokenizer: T5Tokenizer text_encoder: T5EncoderModel vae: AutoencoderKLAllegro transformer: AllegroTransformer3DModel scheduler: KarrasDiffusionSchedulers )
参数
- vae (
AllegroAutoEncoderKL3D
) — 变分自编码器 (VAE) 模型,用于将视频编码和解码为潜在表示形式。 - text_encoder (
T5EncoderModel
) — 冻结的文本编码器。PixArt-Alpha 使用 T5,特别是 t5-v1_1-xxl 变体。 - tokenizer (
T5Tokenizer
) — T5Tokenizer 类的分词器。 - transformer (AllegroTransformer3DModel) — 以文本为条件的
AllegroTransformer3DModel
,用于对编码后的视频潜在表示进行去噪。 - scheduler (SchedulerMixin) — 调度器,与
transformer
结合使用,以对编码后的视频潜在表示进行去噪。
使用 Allegro 进行文本到视频生成的 Pipeline。
此模型继承自 DiffusionPipeline。查看超类文档,了解库为所有 pipeline 实现的通用方法(例如下载或保存、在特定设备上运行等)。
__call__
< source >( prompt: typing.Union[str, typing.List[str]] = None negative_prompt: str = '' num_inference_steps: int = 100 timesteps: typing.List[int] = None guidance_scale: float = 7.5 num_frames: typing.Optional[int] = None height: typing.Optional[int] = None width: typing.Optional[int] = None num_videos_per_prompt: int = 1 eta: float = 0.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] clean_caption: bool = True max_sequence_length: int = 512 ) → AllegroPipelineOutput 或 tuple
参数
- prompt (
str
或List[str]
, 可选) — 用于引导视频生成的 prompt 或 prompts。如果未定义,则必须传递prompt_embeds
。 - negative_prompt (
str
或List[str]
, 可选) — 不用于引导视频生成的 prompt 或 prompts。如果未定义,则必须传递negative_prompt_embeds
。当不使用引导时忽略(即,如果guidance_scale
小于1
则忽略)。 - num_inference_steps (
int
, 可选, 默认为 100) — 去噪步骤的数量。更多去噪步骤通常会带来更高质量的视频,但会牺牲更慢的推理速度。 - timesteps (
List[int]
, 可选) — 用于去噪过程的自定义时间步长。如果未定义,则使用等间距的num_inference_steps
时间步长。必须以降序排列。 - guidance_scale (
float
, 可选, 默认为 7.5) — 引导比例,定义于 Classifier-Free Diffusion Guidance 中。guidance_scale
定义为 Imagen Paper 的公式 2 中的w
。通过设置guidance_scale > 1
启用引导比例。较高的引导比例鼓励生成与文本prompt
紧密相关的视频,但通常以牺牲较低的视频质量为代价。 - num_videos_per_prompt (
int
, 可选, 默认为 1) — 每个 prompt 生成的视频数量。 - num_frames — (
int
, 可选, 默认为 88): 控制生成的视频帧数。 - height (
int
, 可选, 默认为 self.unet.config.sample_size) — 生成视频的高度像素。 - width (
int
, 可选, 默认为 self.unet.config.sample_size) — 生成视频的宽度像素。 - eta (
float
, 可选, 默认为 0.0) — 对应于 DDIM 论文中的参数 eta (η): https://arxiv.org/abs/2010.02502。仅适用于 schedulers.DDIMScheduler,对于其他调度器将被忽略。 - generator (
torch.Generator
或List[torch.Generator]
, 可选) — 用于使生成具有确定性的一个或多个 torch generator(s)。 - latents (
torch.Tensor
, 可选) — 预生成的噪声潜在变量,从高斯分布中采样,用作视频生成的输入。可以用于使用不同的 prompt 调整相同的生成结果。如果未提供,将通过使用提供的随机generator
进行采样来生成潜在变量张量。 - prompt_embeds (
torch.Tensor
, 可选) — 预生成的文本嵌入。可以用于轻松调整文本输入,例如 prompt 权重。如果未提供,将从prompt
输入参数生成文本嵌入。 - prompt_attention_mask (
torch.Tensor
, 可选) — 文本嵌入的预生成注意力掩码。 - negative_prompt_embeds (
torch.Tensor
, 可选) — 预生成的负面文本嵌入。对于 PixArt-Sigma,此负面 prompt 应为 ""。如果未提供,将从negative_prompt
输入参数生成 negative_prompt_embeds。 - negative_prompt_attention_mask (
torch.Tensor
, 可选) — 负面文本嵌入的预生成注意力掩码。 - output_type (
str
, 可选, 默认为"pil"
) — 生成视频的输出格式。 在 PIL:PIL.Image.Image
或np.array
之间选择。 - return_dict (
bool
, 可选, 默认为True
) — 是否返回~pipelines.stable_diffusion.IFPipelineOutput
而不是纯元组。 - callback (
Callable
, 可选) — 一个函数,它将在推理期间每callback_steps
步调用。 该函数将使用以下参数调用:callback(step: int, timestep: int, latents: torch.Tensor)
。 - callback_steps (
int
, 可选, 默认为 1) — 调用callback
函数的频率。 如果未指定,则将在每一步调用回调。 - clean_caption (
bool
, 可选, 默认为True
) — 是否在创建嵌入之前清理标题。 需要安装beautifulsoup4
和ftfy
。 如果未安装依赖项,则将从原始提示创建嵌入。 - max_sequence_length (
int
默认为512
) — 与prompt
一起使用的最大序列长度。
返回值
AllegroPipelineOutput 或 tuple
如果 return_dict
为 True
,则返回 AllegroPipelineOutput,否则返回 tuple
,其中第一个元素是包含生成的视频的列表。
调用管道进行生成时调用的函数。
示例
>>> import torch
>>> from diffusers import AutoencoderKLAllegro, AllegroPipeline
>>> from diffusers.utils import export_to_video
>>> vae = AutoencoderKLAllegro.from_pretrained("rhymes-ai/Allegro", subfolder="vae", torch_dtype=torch.float32)
>>> pipe = AllegroPipeline.from_pretrained("rhymes-ai/Allegro", vae=vae, torch_dtype=torch.bfloat16).to("cuda")
>>> pipe.enable_vae_tiling()
>>> prompt = (
... "A seaside harbor with bright sunlight and sparkling seawater, with many boats in the water. From an aerial view, "
... "the boats vary in size and color, some moving and some stationary. Fishing boats in the water suggest that this "
... "location might be a popular spot for docking fishing boats."
... )
>>> video = pipe(prompt, guidance_scale=7.5, max_sequence_length=512).frames[0]
>>> export_to_video(video, "output.mp4", fps=15)
禁用切片 VAE 解码。 如果之前启用了 enable_vae_slicing
,此方法将返回一步计算解码。
禁用平铺 VAE 解码。 如果之前启用了 enable_vae_tiling
,此方法将返回一步计算解码。
启用切片 VAE 解码。 启用此选项后,VAE 将输入张量拆分为切片,以分步计算解码。 这对于节省一些内存并允许更大的批量大小很有用。
启用平铺 VAE 解码。 启用此选项后,VAE 会将输入张量拆分为平铺,以分步计算解码和编码。 这对于节省大量内存并允许处理更大的图像很有用。
encode_prompt
< source >( prompt: typing.Union[str, typing.List[str]] do_classifier_free_guidance: bool = True negative_prompt: str = '' num_videos_per_prompt: int = 1 device: typing.Optional[torch.device] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None clean_caption: bool = False max_sequence_length: int = 512 **kwargs )
参数
- prompt (
str
或List[str]
, 可选) — 要编码的提示 - negative_prompt (
str
或List[str]
, 可选) — 不用于引导图像生成的提示。 如果未定义,则必须改为传递negative_prompt_embeds
。 当不使用引导时(即,如果guidance_scale
小于1
,则忽略)。 对于 PixArt-Alpha,这应为 ""。 - do_classifier_free_guidance (
bool
, 可选, 默认为True
) — 是否使用无分类器引导 - num_videos_per_prompt (
int
, 可选, 默认为 1) — 每个提示应生成的图像数量 - device — (
torch.device
, 可选): 用于放置结果嵌入的 torch 设备 - prompt_embeds (
torch.Tensor
, 可选) — 预生成的文本嵌入。 可用于轻松调整文本输入,例如 提示权重。 如果未提供,将从prompt
输入参数生成文本嵌入。 - negative_prompt_embeds (
torch.Tensor
, 可选) — 预生成的负面文本嵌入。 对于 PixArt-Alpha,它应该是 "" 字符串的嵌入。 - clean_caption (
bool
, 默认为False
) — 如果为True
,该函数将在编码之前预处理和清理提供的标题。 - max_sequence_length (
int
, 默认为 512) — 用于提示的最大序列长度。
将提示编码为文本编码器隐藏状态。
AllegroPipelineOutput
class diffusers.pipelines.allegro.pipeline_output.AllegroPipelineOutput
< source >( frames: typing.Union[torch.Tensor, numpy.ndarray, typing.List[typing.List[PIL.Image.Image]]] )
Allegro 管道的输出类。