Diffusers documentation

Kandinsky 6

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

Kandinsky 6

Kandinsky 6 是 Kandinsky Lab 推出的一个视频生成模型系列。主模型通过单个多模态扩散 Transformer,从文本或参考图像生成视频及同步音频:视频和音频潜变量通过融合块进行联合去噪,这些块在两种模态之间进行交叉注意力,并分别以各自的 Qwen2.5-VL 文本分支和 CLIP 池化嵌入作为条件。另一个独立的超分辨率模型在因果 3D K-VAE 的潜空间中,以分块方式对生成的视频进行上采样。

在 Hub 上查看 Kandinsky Lab 组织,以获取完整的官方检查点集合,包括基础模型和超分辨率模型的 flow-matching 及蒸馏变体。

蒸馏检查点附带了少步数的 PiflowScheduler,并且必须以 guidance_scale=1.0 运行。

可用模型

模型Pipeline备注
kandinskylab/Kandinsky-6.0-Pro-5s-DiffusersKandinsky6TI2VAPipeline流匹配,guidance_scale=5.0,50 步
kandinskylab/Kandinsky-6.0-Pro-distill-5s-DiffusersKandinsky6TI2VAPipeline蒸馏模型,guidance_scale=1.0,10 步
kandinskylab/Kandinsky-6.0-Lite-5s-DiffusersKandinsky6TI2VAPipeline流匹配,guidance_scale=5.0,50 步
kandinskylab/Kandinsky-6.0-Lite-distill-5s-DiffusersKandinsky6TI2VAPipeline蒸馏模型,guidance_scale=1.0,10 步
kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-DiffusersKandinsky6TI2VAPipeline流匹配,guidance_scale=5.0,50 步
kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-DiffusersKandinsky6TI2VAPipeline流匹配,guidance_scale=5.0,50 步
kandinskylab/Kandinsky-6.0-VSR-5s-DiffusersKandinsky6SRPipeline流匹配超分辨率
kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-DiffusersKandinsky6SRPipeline蒸馏超分辨率,2 步

文本/图像到视频和音频

import torch
from diffusers import Kandinsky6TI2VAPipeline
from diffusers.utils import encode_video

pipe = Kandinsky6TI2VAPipeline.from_pretrained(
    "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()

output = pipe(
    prompt="A cat and a dog baking a cake together in a kitchen.",
    height=480,
    width=864,
    num_frames=121,
    num_inference_steps=10,
    guidance_scale=1.0,
)
encode_video(
    output.frames[0],
    fps=24,
    output_path="output.mp4",
    audio=output.audio[0][None],
    audio_sample_rate=pipe.audio_sample_rate,
)

传入 image= 以将首帧条件化于参考图像,传入 sample_audio=False 以仅生成视频,并传入 expand_prompts=True 以让 Qwen2.5-VL 文本编码器先将简短提示词改写为详细提示词。

视频超分辨率

Kandinsky6SRPipeline 接收 Kandinsky6TI2VAPipeline 生成的帧,并将其放大 2、4 或 2.25 倍(先进行 1.125 倍的双线性预放大,再走 2 倍放大路径)。视频被分割为重叠的图块,每个图块在 SR transformer 训练所用的某个图块尺寸下进行细化,随后使用 Hann 窗口将图块融合回原视频。

# required: lets inductor pick flex-attention tiles that fit the SR block mask
torch._inductor.config.max_autotune = True  

sr_pipe = Kandinsky6SRPipeline.from_pretrained(
    "kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers", torch_dtype=torch.bfloat16
)
# The SR transformer always runs NABLA sparse attention on the `flex` backend. Compile it, otherwise flex falls
# back to an eager implementation that needs far more memory at video resolutions.
sr_pipe.enable_model_cpu_offload()
sr_pipe.transformer.set_attention_backend("flex")
sr_pipe.transformer.compile_repeated_blocks(fullgraph=True)

upscaled = sr_pipe(video=output.frames[0], resolution_scale=2.25, num_inference_steps=2).frames[0]

内存优化

请参阅 减少内存使用 指南以了解通用技术集。Kandinsky6TI2VAPipeline 和 Kandinsky6SRPipeline 均支持 模型卸载(上文已使用),以及以速度为代价换取更小内存占用的 顺序 CPU 卸载:

pipe.enable_sequential_cpu_offload()

Kandinsky6TI2VAPipeline 的视频 VAE 也支持 tiled decoding,适用于高分辨率或长视频:

pipe.vae.enable_tiling()

备注

  • height 和 width 必须能被视频 VAE 的空间压缩率与 Transformer 的 patch 尺寸之积整除——在默认的 Kandinsky6TI2VAPipeline 配置下,该值为 16(AutoencoderKLHunyuanVideo 的压缩率为 8,patch_size=(1, 2, 2))。上述示例中使用的 480x864 满足此条件。
  • Kandinsky6SRPipeline 的输入 video 必须包含 1 + k * vae_scale_factor_temporal 帧,其中 k 为某个整数(在默认的 K-VAE 配置下,时间压缩比为 4,因此 121 帧是可行的,但 120 帧不行) —— 在对不满足此条件的视频进行放大之前,请先对其进行裁剪或填充。
  • expand_prompts=True 会在去噪之前,复用已加载的 Qwen2.5-VL 文本编码器进行额外的生成步骤,因此会增加延迟,但不会引入额外的模型权重。
  • 编译重复的 Transformer 块以加速重复推理:
    pipe.transformer.compile_repeated_blocks(fullgraph=True)

Kandinsky6TI2VAPipeline

class diffusers.Kandinsky6TI2VAPipeline

< >

( transformer: Kandinsky6Transformer3DModelvae: AutoencoderKLHunyuanVideotext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2_5_VLProcessortext_encoder_2: CLIPTextModeltokenizer_2: CLIPTokenizerscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowScheduleraudio_vae: diffusers.models.autoencoders.autoencoder_mmaudio.MMAudioVAE | None = Nonevocoder: diffusers.models.autoencoders.mmaudio_vocoder.MMAudioVocoder | None = None )

参数

  • transformer (Kandinsky6Transformer3DModel) — 用于对视频和音频潜在变量进行去噪的多模态 transformer。
  • vae (AutoencoderKLHunyuanVideo) — 用于编码参考图像并解码生成视频的 Video VAE。
  • text_encoder (Qwen2_5_VLForConditionalGeneration) — Qwen2.5-VL 模型,提供 token 级别的文本嵌入,并可选地提供提示词扩展。
  • tokenizer(Qwen2_5_VLProcessor)—— text_encoder 的处理器。
  • text_encoder_2 (CLIPTextModel) — 提供池化文本嵌入的 CLIP 文本编码器。
  • tokenizer_2(CLIPTokenizer)—— text_encoder_2 的分词器。
  • scheduler(FlowMatchEulerDiscreteScheduler 或 PiflowScheduler)—— 与 transformer 配合使用,用于对潜变量进行去噪。蒸馏检查点附带 PiflowScheduler,并且必须以 guidance_scale=1.0 运行。
  • audio_vae(MMAudioVAE,可选)— 用于将生成的音频潜变量解码为梅尔频谱的音频 VAE。仅在 sample_audio=True 时需要。
  • vocoder (MMAudioVocoder,可选) — 用于将 audio_vae 解码出的梅尔频谱转换为波形的声码器。仅在 sample_audio=True 时需要。

用于使用 Kandinsky 6 进行文本/图像到视频和音频生成的 Pipeline。

视频和音频潜变量由单个多模态 Transformer 联合去噪,并以 Qwen2.5-VL 文本 token 和 CLIP 池化嵌入作为条件。可选的参考图像用于条件化第一帧。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( prompt: str | list[str] | None = Noneimage: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 512width: int = 768num_frames: int = 121frame_rate: float = 24.0num_inference_steps: int = 50timesteps: list[int] | None = Nonesigmas: list[float] | None = Noneguidance_scale: float = 5.0num_videos_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneaudio_latents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonepooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonesample_audio: bool = Trueexpand_prompts: bool = Falsemax_sequence_length: int = 1024output_type: str = 'pil'return_dict: bool = Truecallback_on_step_end: collections.abc.Callable[[int, int, dict], None] | None = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents'] ) → Kandinsky6TI2VAPipelineOutput or tuple

参数

  • prompt (str 或 list[str],可选) — 用于引导生成的提示词或提示词列表。除非提供了 prompt_embeds,否则此项为必填。
  • image (PipelineImageInput,可选) — 用于条件化首帧的参考图像(图生视频与音频)。
  • negative_prompt (str 或 list[str],可选) — 用于不引导生成的提示词或提示词列表。默认为 Kandinsky 6 的负面提示词。
  • height (int,默认为 512) — 生成视频的高度(以像素为单位)。
  • width (int,默认为 768) — 生成视频的宽度(以像素为单位)。
  • num_frames (int,默认为 121) — 生成的帧数。
  • frame_rate (float,默认为 24.0) — 视频生成的帧率;用于设置同步音频的时长。
  • num_inference_steps (int,默认为 50) — 去噪步数。使用蒸馏检查点时,请设置为 16。
  • timesteps (list[int], 可选) — 用于支持自定义时间步的调度器的自定义时间步。
  • sigmas (list[float],可选) — 用于支持自定义 sigmas 的调度器。
  • guidance_scale(float,默认为 5.0)— 无分类器引导的缩放系数。在使用 PiflowScheduler 时,该值必须为 1.0。
  • num_videos_per_prompt (int,默认为 1) — 每个提示词生成的视频数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于初始噪声和参考图像编码的生成器。
  • latents (torch.Tensor, 可选) — 预生成的视频潜变量,形状为 (batch_size, channels, num_latent_frames, latent_height, latent_width)。
  • audio_latents (torch.Tensor, 可选) — 形状为 (batch_size, channels, audio_length) 的预生成音频潜变量。
  • prompt_embeds(torch.Tensor,可选)— 预生成的 Qwen2.5-VL 文本嵌入。
  • pooled_prompt_embeds (torch.Tensor, 可选) — 预生成的 CLIP 池化文本嵌入。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向 Qwen2.5-VL 文本嵌入。
  • negative_pooled_prompt_embeds (torch.Tensor,可选) — 预生成的负向 CLIP 池化文本嵌入。
  • sample_audio (bool,默认为 True) — 是否生成同步音频。要求流水线中包含 audio_vae 和 vocoder。
  • expand_prompts (bool,默认为 False) — 是否在编码前使用 expand_prompts() 重写提示词。
  • max_sequence_length (int,默认为 1024) — 应用聊天模板后提示词的最大 token 数量。
  • output_type (str,默认为 "pil") — 生成视频的输出格式:"pil"、"np"、"pt" 或 "latent"。
  • return_dict (bool,默认为 True) — 是否返回 Kandinsky6TI2VAPipelineOutput 而不是普通元组。
  • callback_on_step_end (Callable, 可选) — 在每个去噪步骤结束时调用的函数,签名为 callback_on_step_end(self, step, timestep, callback_kwargs)。它可以返回一个字典,用于覆盖上述张量。
  • callback_on_step_end_tensor_inputs(list[str],默认为 ["latents"])— 传递给 callback_on_step_end 的张量输入;_callback_tensor_inputs 的一个子集。

返回值

Kandinsky6TI2VAPipelineOutput 或 tuple

生成的视频和音频;当 return_dict=False 时,为一个 (frames, audio) 元组。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> from diffusers import Kandinsky6TI2VAPipeline
>>> from diffusers.utils import encode_video

>>> pipe = Kandinsky6TI2VAPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.enable_model_cpu_offload()

>>> output = pipe(
...     prompt="A cat and a dog baking a cake together in a kitchen.",
...     height=480,
...     width=864,
...     num_frames=121,
...     num_inference_steps=16,
...     guidance_scale=1.0,
... )
>>> encode_video(
...     output.frames[0],
...     fps=24,
...     output_path="output.mp4",
...     audio=output.audio[0][None],
...     audio_sample_rate=pipe.audio_sample_rate,
... )

encode_image

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]height: intwidth: intdevice: devicedtype: dtypenum_videos_per_prompt: int = 1generator: typing.Optional[torch.Generator] = None )

将参考图像编码为形状为 (batch_size, latent_height, latent_width, latent_channels) 的首帧潜变量,并按 VAE 的 scaling_factor 进行缩放。PIL 图像会被调整大小并居中裁剪至 height x width;张量和数组必须已经具有该尺寸。潜变量会沿批次维度重复 num_videos_per_prompt 次。

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonepooled_prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str]) — 要编码的提示。
  • negative_prompt (str 或 list[str],可选) — 用于不引导生成的提示词。当 do_classifier_free_guidance 为 False 时将被忽略。
  • do_classifier_free_guidance(bool,默认为 True)—— 是否同时编码负向提示词。
  • num_videos_per_prompt (int,默认为 1) — 每个提示词生成的视频数量;嵌入会相应地重复。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的 Qwen2.5-VL 文本嵌入。跳过对 prompt 的编码。
  • pooled_prompt_embeds (torch.Tensor, 可选) — 预生成的 CLIP 池化文本嵌入。必须与 prompt_embeds 一起提供。
  • prompt_attention_mask (torch.Tensor,可选) — prompt_embeds 的布尔填充掩码。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向 Qwen2.5-VL 文本嵌入。
  • negative_pooled_prompt_embeds (torch.Tensor,可选) — 预生成的负向 CLIP 池化文本嵌入。
  • negative_prompt_attention_mask (torch.Tensor, 可选) — negative_prompt_embeds 的布尔填充掩码。
  • max_sequence_length (int,默认为 1024) — 应用聊天模板后提示词的最大 token 数量。
  • device (torch.device,可选) — 用于运行文本编码器的设备。
  • dtype (torch.dtype,可选) — 返回嵌入的数据类型。

将提示词编码为文本编码器的隐藏状态。

expand_prompts

< >

( prompt: str | list[str]tokenizertext_encoderdevice: deviceimage: PIL.Image.Image | list[PIL.Image.Image] | None = Nonemax_sequence_length: int = 1024generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None ) → str or list[str]

参数

  • prompt (str 或 list[str]) — 要扩展的提示词或提示词列表。
  • tokenizer — Qwen2.5-VL 处理器,例如 pipe.tokenizer。
  • text_encoder — Qwen2.5-VL 模型,例如 pipe.text_encoder。
  • device (torch.device) — 用于运行文本编码器的设备。
  • image (PIL.Image.Image 或 list[PIL.Image.Image],可选) — 图像到视频调用的参考图像。
  • max_sequence_length (int,默认为 1024) — 每个提示词生成的最大 token 数。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 为采样扩展提供随机种子;若为列表,其长度必须与 prompt 一致,每个元素对应一个生成器。generate 从全局随机数生成器中抽取随机数,因此全局随机数生成器会由该生成器的种子进行初始化;后续的 randn_tensor 调用将直接使用 generator。

返回值

str 或 list[str]

扩展后的提示词。

使用 Qwen2.5-VL 文本编码器将简短提示词重写为详细的视频+音频提示词,并在提供参考图像时基于该图像进行定位。这是一个 staticmethod,因此可以在运行流水线之前独立使用。

prepare_audio_latents

< >

( batch_size: intnum_channels_latents: intaudio_length: intdtype: dtypedevice: devicegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType]audio_latents: typing.Optional[torch.Tensor] = None )

返回采用 Transformer 的 (batch_size, audio_length, channels) 布局的音频潜在表示。用户提供的 audio_latents 张量需采用 (batch_size, channels, audio_length) 布局。

prepare_latents

< >

( batch_size: intnum_channels_latents: intheight: intwidth: intnum_frames: intdtype: dtypedevice: devicegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType]latents: typing.Optional[torch.Tensor] = None )

返回视频潜在表示,其布局为 transformer 的 (batch_size, num_frames, height, width, channels)。 用户提供的 latents 张量预期采用 (batch_size, channels, num_frames, height, width) 布局。

Kandinsky6SRPipeline

class diffusers.Kandinsky6SRPipeline

< >

( transformer: Kandinsky6SRTransformer3DModelvae: Kandinsky6SRVAEscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowSchedulerlatent_upscaler: diffusers.models.latent_upscaler.latent_upscaler_kandinsky6_sr.Kandinsky6SRLatentUpscalerBank | None = None )

参数

用于 Kandinsky 6 视频超分辨率的 Pipeline。

视频被分割为重叠的空间图块,每个图块由 SR transformer 在模型训练所用的某个图块尺寸(transformer.config.tile_sizes)下进行细化,细化后的图块再通过 Hann 窗口融合回原视频。当 pipeline 包含 latent_upscaler 时,图块从整个视频的 K-VAE 潜变量中切出,并在潜空间中进行上采样;否则,像素图块会先进行双线性上采样,再进行编码。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( video: typing.Union[list[PIL.Image.Image], list[list[PIL.Image.Image]], numpy.ndarray, torch.Tensor]resolution_scale: float = 2.25num_inference_steps: int = 4timesteps: list[int] | None = Nonesigmas: list[float] | None = Nonelq_noise_scale: float = 0.7min_overlap: float = 0.2tiles_batch_size: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneoutput_type: str = 'pil'return_dict: bool = True ) → Kandinsky6SRPipelineOutput or tuple

参数

  • video (list[PIL.Image.Image]、np.ndarray 或 torch.Tensor) — 低分辨率视频,采用 preprocess_video() 所接受的任意格式,帧数为 1 + k * 4。尺寸会向下取整为 VAE 空间因子的整数倍。
  • resolution_scale (float,默认为 2.25) — 总空间放大倍数:2、4 或 2.25(先进行 1.125 倍的双线性预放大,再走 2 倍放大路径)。
  • num_inference_steps(int,默认为 4)— 每个 tile 的去噪步数。使用蒸馏检查点时,请设置为 2。
  • timesteps (list[int], 可选) — 用于支持自定义时间步的调度器的自定义时间步。
  • sigmas (list[float],可选) — 用于支持自定义 sigmas 的调度器。
  • lq_noise_scale (float,默认为 0.7) — 在去噪之前,混合到低分辨率潜在表示中的高斯噪声量(方差保持)。
  • min_overlap (float,默认为 0.2) — 相邻图块之间的最小重叠量,以图块大小的比例表示。
  • tiles_batch_size (int,默认为 1) — 每次调用 transformer 时去噪的 tile 数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于混合到瓦片中的噪声的生成器。
  • output_type (str,默认为 "pil") — 生成视频的输出格式:"pil"、"np" 或 "pt"。
  • return_dict (bool,默认为 True) — 是否返回 Kandinsky6SRPipelineOutput 而不是普通元组。

返回值

Kandinsky6SRPipelineOutput 或 tuple

超分辨率视频;当 return_dict=False 时,为一个单元素元组。

用于超分辨率的 pipeline 的调用函数。

示例:

>>> import torch
>>> from diffusers import Kandinsky6SRPipeline, Kandinsky6TI2VAPipeline
>>> from diffusers.utils import export_to_video

>>> pipe = Kandinsky6TI2VAPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.enable_model_cpu_offload()
>>> video = pipe(
...     prompt="A cat and a dog baking a cake together in a kitchen.",
...     height=480,
...     width=864,
...     num_inference_steps=16,
...     guidance_scale=1.0,
...     sample_audio=False,
... ).frames[0]

>>> sr_pipe = Kandinsky6SRPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> # The transformer always runs attention through the `flex` backend; compiling avoids the eager
>>> # fallback's much higher memory use at video resolutions.
>>> sr_pipe.transformer.compile_repeated_blocks(fullgraph=True)
>>> sr_pipe.enable_model_cpu_offload()
>>> output = sr_pipe(video=video, resolution_scale=2.25, num_inference_steps=2)
>>> export_to_video(output.frames[0], "output_sr.mp4", fps=24)

decode_latents

< >

( latents: Tensor )

将缩放后的 K-VAE 潜在变量解码为 [-1, 1] 范围内的 (batch_size, channels, num_frames, height, width) 视频。

encode_video

< >

( video: Tensor )

将 (batch_size, channels, num_frames, height, width) 形状、取值范围为 [-1, 1] 的视频编码为经 VAE scaling_factor 缩放的 K-VAE 潜在表示。

Kandinsky6SRLatentUpscalerBank

class diffusers.Kandinsky6SRLatentUpscalerBank

< >

( in_channels: int = 64stage_channels: tuple[int, int, int] = (2048, 1024, 512)num_pre_blocks: int = 5num_mid_blocks: int = 3num_post_blocks: int = 3num_x2_adapter_blocks: int = 2scales: tuple[int, ...] = (2, 4)scaling_factor: float = 0.910344004631042 )

参数

  • in_channels (int,默认为 64) — 潜在通道的数量。
  • stage_channels (tuple[int, int, int],默认为 (2048, 1024, 512)) — 级联三个阶段的特征宽度。
  • num_pre_blocks (int,默认为 5) — x4 模型中第一次上采样之前的残差块数量。
  • num_mid_blocks (int,默认为 3) — 两个上采样层之间的残差块数量。
  • num_post_blocks (int,默认为 3) — 最后一个上采样层之后的残差块数量。
  • num_x2_adapter_blocks (int,默认为 2) — x2 模型适配器的残差块。
  • scales (tuple[int, ...],默认为 (2, 4)) — 该 bank 提供上采样器的空间尺度。
  • scaling_factor (float,默认为 0.910344) — 输入潜变量预期携带的缩放系数(即 K-VAE 的 scaling_factor)。

Kandinsky6SRPipeline 使用的潜在上采样器库:每个支持的空间尺度对应一个 Kandinsky6SRLatentUpscaler,作用于 K-VAE 潜在表示。

forward

< >

( latents: Tensorscale: intreturn_dict: bool = True )

参数

  • latents(形状为 (batch_size, in_channels, num_frames, height, width) 的 torch.Tensor)— 经 scaling_factor 缩放的 K-VAE 潜在表示。
  • scale (int) — 空间放大系数;scales 中的一个。
  • return_dict (bool,默认为 True) — 是否返回 ~models.autoencoder_kl.DecoderOutput 而不是普通元组。

Kandinsky6TI2VAPipelineOutput

class diffusers.Kandinsky6TI2VAPipelineOutput

< >

( frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]]audio: typing.Union[torch.Tensor, numpy.ndarray, NoneType] = None )

参数

  • frames (torch.Tensor、np.ndarray 或 list[list[PIL.Image.Image]]) — 生成的视频。一个长度为 batch_size 的嵌套列表,每个元素包含 num_frames 张 PIL 图像;或者形状为 (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width) 的 NumPy 数组或 torch 张量。当 output_type="latent" 时,返回形状为 (batch_size, channels, num_latent_frames, latent_height, latent_width) 的视频潜变量。
  • audio (torch.Tensor 或 np.ndarray,可选) — 在音频 VAE 采样率下,形状为 (batch_size, num_samples) 且取值范围为 [-1, 1] 的生成波形;若未对音频进行采样,则为 None。当 output_type="latent" 时,为形状 (batch_size, channels, audio_length) 的音频潜变量。

Kandinsky6TI2VAPipeline 的输出类。

Kandinsky6SRPipelineOutput

class diffusers.Kandinsky6SRPipelineOutput

< >

( frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]] )

参数

  • frames (torch.Tensor、np.ndarray 或 list[list[PIL.Image.Image]]) — 超分辨率视频。一个长度为 batch_size 的嵌套列表,每个元素包含 num_frames 张 PIL 图像;或者形状为 (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width) 的 NumPy 数组或 torch 张量。

Kandinsky6SRPipeline 的输出类。

Update on GitHub