# Kandinsky 6

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

> [!TIP]
> 在 Hub 上查看 [Kandinsky Lab](https://huggingface.co/kandinskylab) 组织，以获取完整的官方检查点集合，包括基础模型和超分辨率模型的 flow-matching 及蒸馏变体。
>
> 蒸馏检查点附带了少步数的 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.PiflowScheduler)，并且必须以 `guidance_scale=1.0` 运行。

## 可用模型

| 模型 | Pipeline | 备注 |
|---|---|---|
| [`kandinskylab/Kandinsky-6.0-Pro-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Pro-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 流匹配，`guidance_scale=5.0`，50 步 |
| [`kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 蒸馏模型，`guidance_scale=1.0`，10 步 |
| [`kandinskylab/Kandinsky-6.0-Lite-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Lite-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 流匹配，`guidance_scale=5.0`，50 步 |
| [`kandinskylab/Kandinsky-6.0-Lite-distill-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Lite-distill-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 蒸馏模型，`guidance_scale=1.0`，10 步 |
| [`kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 流匹配，`guidance_scale=5.0`，50 步 |
| [`kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-Diffusers) | [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) | 流匹配，`guidance_scale=5.0`，50 步 |
| [`kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers) | [Kandinsky6SRPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) | 流匹配超分辨率 |
| [`kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers`](https://huggingface.co/kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers) | [Kandinsky6SRPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) | 蒸馏超分辨率，2 步 |

## 文本/图像到视频和音频

```python
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](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) 接收 [Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) 生成的帧，并将其放大 `2`、`4` 或 `2.25` 倍（先进行 1.125 倍的双线性预放大，再走 2 倍放大路径）。视频被分割为重叠的图块，每个图块在 SR transformer 训练所用的某个图块尺寸下进行细化，随后使用 Hann 窗口将图块融合回原视频。

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

## 内存优化

请参阅 [减少内存使用](../../optimization/memory) 指南以了解通用技术集。[Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) 和 [Kandinsky6SRPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) 均支持 [模型卸载](../../optimization/memory#model-offloading)（上文已使用），以及以速度为代价换取更小内存占用的 [顺序 CPU 卸载](../../optimization/memory#cpu-offloading)：

```python
pipe.enable_sequential_cpu_offload()
```

[Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) 的视频 VAE 也支持 [tiled decoding](../../optimization/memory#vae-tiling)，适用于高分辨率或长视频：

```python
pipe.vae.enable_tiling()
```

## 备注

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

## Kandinsky6TI2VAPipeline[[diffusers.Kandinsky6TI2VAPipeline]]

#### diffusers.Kandinsky6TI2VAPipeline[[diffusers.Kandinsky6TI2VAPipeline]]

```python
diffusers.Kandinsky6TI2VAPipeline(transformer: Kandinsky6Transformer3DModel, vae: AutoencoderKLHunyuanVideo, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2_5_VLProcessor, text_encoder_2: CLIPTextModel, tokenizer_2: CLIPTokenizer, scheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowScheduler, audio_vae: diffusers.models.autoencoders.autoencoder_mmaudio.MMAudioVAE | None = None, vocoder: diffusers.models.autoencoders.mmaudio_vocoder.MMAudioVocoder | None = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L178)

**参数：**

transformer ([Kandinsky6Transformer3DModel](/docs/diffusers/v0.43.0/zh/api/models/kandinsky6_transformer#diffusers.Kandinsky6Transformer3DModel))：用于对视频和音频潜在变量进行去噪的多模态 Transformer。

vae ([AutoencoderKLHunyuanVideo](/docs/diffusers/v0.43.0/zh/api/models/autoencoder_kl_hunyuan_video#diffusers.AutoencoderKLHunyuanVideo))：用于编码参考图像并解码生成视频的 Video VAE。

text_encoder ([Qwen2_5_VLForConditionalGeneration](https://huggingface.co/docs/transformers/v5.22.2/en/model_doc/qwen2_5_vl#transformers.Qwen2_5_VLForConditionalGeneration))：Qwen2.5-VL 模型，提供 token 级别的文本嵌入，并可选地支持提示词扩展。

tokenizer ([Qwen2_5_VLProcessor](https://huggingface.co/docs/transformers/v5.22.2/en/model_doc/qwen2_5_vl#transformers.Qwen2_5_VLProcessor))：`text_encoder` 的处理器。

text_encoder_2 ([CLIPTextModel](https://huggingface.co/docs/transformers/v5.22.2/en/model_doc/clip#transformers.CLIPTextModel))：提供池化文本嵌入的 CLIP 文本编码器。

tokenizer_2 ([CLIPTokenizer](https://huggingface.co/docs/transformers/v5.22.2/en/model_doc/clip#transformers.CLIPTokenizer))：`text_encoder_2` 的分词器。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) 或 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.PiflowScheduler))：与 `transformer` 配合使用，用于对潜变量进行去噪的调度器。蒸馏检查点附带 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.PiflowScheduler)，并且必须以 `guidance_scale=1.0` 运行。

audio_vae ([MMAudioVAE](/docs/diffusers/v0.43.0/zh/api/models/kandinsky6_vae#diffusers.MMAudioVAE)，*可选*)：用于将生成的音频潜在变量解码为梅尔频谱的音频 VAE。仅在 `sample_audio=True` 时需要。

vocoder ([MMAudioVocoder](/docs/diffusers/v0.43.0/zh/api/models/kandinsky6_vae#diffusers.MMAudioVocoder)，*可选*)：用于将 `audio_vae` 解码出的梅尔频谱转换为波形的声码器。仅在 `sample_audio=True` 时需要。

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

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

该模型继承自 [DiffusionPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/overview#diffusers.DiffusionPipeline)。有关为所有流水线实现的通用方法（下载、保存、在特定设备上运行等），请参阅父类文档。

#### __调用__[[diffusers.Kandinsky6TI2VAPipeline.__call__]]

```python
__call__(prompt: str | list[str] | None = None, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, negative_prompt: str | list[str] | None = None, height: int = 512, width: int = 768, num_frames: int = 121, frame_rate: float = 24.0, num_inference_steps: int = 50, timesteps: list[int] | None = None, sigmas: list[float] | None = None, guidance_scale: float = 5.0, num_videos_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, audio_latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, sample_audio: bool = True, expand_prompts: bool = False, max_sequence_length: int = 1024, output_type: str = 'pil', return_dict: bool = True, callback_on_step_end: collections.abc.Callable[[int, int, dict], None] | None = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'])
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L644)

**参数：**

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]`，*可选*)：适用于支持自定义 sigma 的调度器。

guidance_scale (`float`，默认值为 `5.0`)：Classifier-free guidance 的缩放系数。在使用 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.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()](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline.expand_prompts) 重写提示词。

max_sequence_length (`int`，默认为 `1024`)：应用聊天模板后，提示词的最大 token 数量。

output_type (`str`，默认为 `"pil"`)：生成视频的输出格式：`"pil"`、`"np"`、`"pt"` 或 `"latent"`。

return_dict (`bool`，默认为 `True`)：是否返回 [Kandinsky6TI2VAPipelineOutput](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.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](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipelineOutput) 或 `tuple`

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

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

示例：
```python
>>> 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[[diffusers.Kandinsky6TI2VAPipeline.encode_image]]

```python
encode_image(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], height: int, width: int, device: device, dtype: dtype, num_videos_per_prompt: int = 1, generator: typing.Optional[torch.Generator] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L551)

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

#### encode_prompt[[diffusers.Kandinsky6TI2VAPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L309)

**参数：**

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`，*可选*)：返回嵌入的 Dtype。

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

#### expand_prompts[[diffusers.Kandinsky6TI2VAPipeline.expand_prompts]]

```python
expand_prompts(prompt: str | list[str], tokenizer, text_encoder, device: device, image: PIL.Image.Image | list[PIL.Image.Image] | None = None, max_sequence_length: int = 1024, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L412)

**参数：**

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[[diffusers.Kandinsky6TI2VAPipeline.prepare_audio_latents]]

```python
prepare_audio_latents(batch_size: int, num_channels_latents: int, audio_length: int, dtype: dtype, device: device, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType], audio_latents: typing.Optional[torch.Tensor] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L607)

返回采用 Transformer 的 `(batch_size, audio_length, channels)` 布局的音频潜变量。用户提供的 `audio_latents` 张量应遵循 `(batch_size, channels, audio_length)` 布局。

#### prepare_latents[[diffusers.Kandinsky6TI2VAPipeline.prepare_latents]]

```python
prepare_latents(batch_size: int, num_channels_latents: int, height: int, width: int, num_frames: int, dtype: dtype, device: device, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType], latents: typing.Optional[torch.Tensor] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py#L578)

以 Transformer 的 `(batch_size, num_frames, height, width, channels)` 布局返回视频潜变量。用户提供的 `latents` 张量需采用 `(batch_size, channels, num_frames, height, width)` 布局。

## Kandinsky6SRPipeline[[diffusers.Kandinsky6SRPipeline]]

#### diffusers.Kandinsky6SRPipeline[[diffusers.Kandinsky6SRPipeline]]

```python
diffusers.Kandinsky6SRPipeline(transformer: Kandinsky6SRTransformer3DModel, vae: Kandinsky6SRVAE, scheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowScheduler, latent_upscaler: diffusers.models.latent_upscaler.latent_upscaler_kandinsky6_sr.Kandinsky6SRLatentUpscalerBank | None = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_sr.py#L143)

**参数：**

transformer ([Kandinsky6SRTransformer3DModel](/docs/diffusers/v0.43.0/zh/api/models/kandinsky6_transformer#diffusers.Kandinsky6SRTransformer3DModel))：用于细化潜在瓦片的 Transformer。

vae ([Kandinsky6SRVAE](/docs/diffusers/v0.43.0/zh/api/models/kandinsky6_vae#diffusers.Kandinsky6SRVAE))：用于编码输入视频并解码细化图块的因果视频 K-VAE。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) 或 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.PiflowScheduler))：与 `transformer` 配合使用，用于对图块进行去噪。蒸馏检查点附带 [PiflowScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/piflow#diffusers.PiflowScheduler)。

latent_upscaler ([Kandinsky6SRLatentUpscalerBank](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRLatentUpscalerBank)，*可选*)：用于支持比例的潜在上采样器。

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

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

该模型继承自 [DiffusionPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/overview#diffusers.DiffusionPipeline)。有关为所有流水线实现的通用方法（下载、保存、在特定设备上运行等），请参阅父类文档。

#### __调用__[[diffusers.Kandinsky6SRPipeline.__call__]]

```python
__call__(video: typing.Union[list[PIL.Image.Image], list[list[PIL.Image.Image]], numpy.ndarray, torch.Tensor], resolution_scale: float = 2.25, num_inference_steps: int = 4, timesteps: list[int] | None = None, sigmas: list[float] | None = None, lq_noise_scale: float = 0.7, min_overlap: float = 0.2, tiles_batch_size: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, output_type: str = 'pil', return_dict: bool = True)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_sr.py#L228)

**参数：**

video (`list[PIL.Image.Image]`、`np.ndarray` 或 `torch.Tensor`)：低分辨率视频，格式可以是 [preprocess_video()](/docs/diffusers/v0.43.0/zh/api/video_processor#diffusers.VideoProcessor.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]`，*可选*)：适用于支持自定义 sigma 的调度器。

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](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipelineOutput) 而不是普通元组。

**返回：** [Kandinsky6SRPipelineOutput](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipelineOutput) 或 `tuple`

超分辨率视频；当 `return_dict=False` 时，为一个单元素元组。

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

示例：
```python
>>> 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[[diffusers.Kandinsky6SRPipeline.decode_latents]]

```python
decode_latents(latents: Tensor)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_sr.py#L223)

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

#### encode_video[[diffusers.Kandinsky6SRPipeline.encode_video]]

```python
encode_video(video: Tensor)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_sr.py#L213)

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

## Kandinsky6SRLatentUpscalerBank[[diffusers.Kandinsky6SRLatentUpscalerBank]]

#### diffusers.Kandinsky6SRLatentUpscalerBank[[diffusers.Kandinsky6SRLatentUpscalerBank]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/latent_upscaler/latent_upscaler_kandinsky6_sr.py#L251)

**参数：**

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](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) 使用的潜在上采样器库：每个支持的空间尺度对应一个 `Kandinsky6SRLatentUpscaler`，作用于 K-VAE 潜在表示。

#### forward[[diffusers.Kandinsky6SRLatentUpscalerBank.forward]]

```python
forward(latents: Tensor, scale: int, return_dict: bool = True)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/latent_upscaler/latent_upscaler_kandinsky6_sr.py#L305)

**参数：**

latents (`torch.Tensor`，形状为 `(batch_size, in_channels, num_frames, height, width)`)：由 `scaling_factor` 缩放后的 K-VAE 潜变量。

scale (`int`) : 空间上采样因子；`scales` 中的一个。

return_dict (`bool`，默认为 `True`) : 是否返回 `~models.autoencoder_kl.DecoderOutput` 而不是普通元组。

**返回值：**

形状为 `(batch_size, in_channels, num_frames, height * scale, width * scale)` 的上采样潜在变量。

## Kandinsky6TI2VAPipelineOutput[[diffusers.Kandinsky6TI2VAPipelineOutput]]

#### diffusers.Kandinsky6TI2VAPipelineOutput[[diffusers.Kandinsky6TI2VAPipelineOutput]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_output.py#L25)

**参数：**

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`，*可选*)：形状为 `(batch_size, num_samples)` 的生成波形，取值范围为 `[-1, 1]`，采样率为音频 VAE 的采样率；若未对音频进行采样，则为 `None`。当 `output_type="latent"` 时，为形状 `(batch_size, channels, audio_length)` 的音频潜变量。

[Kandinsky6TI2VAPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6TI2VAPipeline) 的输出类。

## Kandinsky6SRPipelineOutput[[diffusers.Kandinsky6SRPipelineOutput]]

#### diffusers.Kandinsky6SRPipelineOutput[[diffusers.Kandinsky6SRPipelineOutput]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/kandinsky6/pipeline_output.py#L46)

**参数：**

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](/docs/diffusers/v0.43.0/zh/api/pipelines/kandinsky6#diffusers.Kandinsky6SRPipeline) 的输出类。

