# Kandinsky S2V 1.0

Kandinsky S2V 1.0 tạo video avatar từ một khung hình tham chiếu và một bản ghi âm giọng nói. Người trong khung hình sẽ được chuyển động để khớp với giọng nói — toàn bộ cơ thể, không chỉ phần đầu. Giọng nói là điều kiện đầu vào, không phải đầu ra: mô hình không tạo ra âm thanh, và bản nhạc nền của kết quả chính là bản ghi âm mà bạn truyền vào.

Cả hai điều kiện đều đi qua [Qwen2.5-Omni-7B](https://huggingface.co/Qwen/Qwen2.5-Omni-7B): các trạng thái ẩn của nó mã hóa prompt và tháp âm thanh của nó mã hóa giọng nói, sau đó đi vào transformer thông qua các adapter cross-attention được căn chỉnh theo từng khung hình, để mỗi khung hình latent chỉ chú ý đến phần giọng nói mà nó bao phủ. Một đoạn clip được tạo thành các khối 5 giây (125 khung hình ở 25 fps), mỗi khối mang bộ nhớ FramePack của các khối trước đó, để các bản nhạc dài vẫn nhất quán qua các ranh giới khối.

Kandinsky S2V 1.0 được tích hợp dưới dạng [pipeline module](../../modular_diffusers/overview) duy nhất; không có lớp `DiffusionPipeline` tiêu chuẩn cho nó.

## Điểm kiểm tra

| Checkpoint | Transformer | Các khối | Trình lập lịch | Các bước | Hướng dẫn |
|---|---|---|---|---|---|
| [Lite][lite] | 2B | [KandinskyS2VAutoBlocks](/docs/diffusers/v0.43.0/vi/api/pipelines/kandinsky_s2v#diffusers.KandinskyS2VAutoBlocks) | [FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) | 50 | 3.0 |
| [Pro][pro] | 21B | [KandinskyS2VAutoBlocks](/docs/diffusers/v0.43.0/vi/api/pipelines/kandinsky_s2v#diffusers.KandinskyS2VAutoBlocks) | [FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) | 50 | 3.0 |
| [Đã chưng cất Lite][lite-distill] | 2B | [KandinskyS2VDistilledAutoBlocks](/docs/diffusers/v0.43.0/vi/api/pipelines/kandinsky_s2v#diffusers.KandinskyS2VDistilledAutoBlocks) | [PiflowScheduler](/docs/diffusers/v0.43.0/vi/api/schedulers/piflow#diffusers.PiflowScheduler) | 16 | off |
| [Pro distilled][pro-distill] | 21B | [KandinskyS2VDistilledAutoBlocks](/docs/diffusers/v0.43.0/vi/api/pipelines/kandinsky_s2v#diffusers.KandinskyS2VDistilledAutoBlocks) | [PiflowScheduler](/docs/diffusers/v0.43.0/vi/api/schedulers/piflow#diffusers.PiflowScheduler) | 16 | off |

Các checkpoint đã được chưng cất cấu hình `PiflowScheduler` với `shift=10.0` và `n_grid=5`, thay vì các giá trị mặc định của nó.

[lite]: https://huggingface.co/kandinskylab/Kandinsky-S2V-1.0-Lite-Diffusers [pro]: https://huggingface.co/kandinskylab/Kandinsky-S2V-1.0-Pro-Diffusers [lite-distill]: https://huggingface.co/kandinskylab/Kandinsky-S2V-1.0-Lite-distill-Diffusers [pro-distill]: https://huggingface.co/kandinskylab/Kandinsky-S2V-1.0-Pro-distill-Diffusers

`ModularPipeline.from_pretrained` sẽ chọn các khối từ checkpoint. Các bước mặc định là các giá trị ở trên. Classifier-free guidance là thành phần `guider`, không phải là đối số gọi: các checkpoint cơ bản được cung cấp với giá trị 3.0. Các checkpoint đã distilled không có guider và không có `negative_prompt`, vì guidance đã là một phần của student.

## Cách sử dụng

```py
import librosa
import torch
from diffusers import ModularPipeline
from diffusers.utils import encode_video, load_image

pipe = ModularPipeline.from_pretrained("kandinskylab/Kandinsky-S2V-1.0-Lite-distill-Diffusers")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

image = load_image("reference.png")
audio, _ = librosa.load("speech.wav", sr=16000)  # a mono waveform at 16 kHz, for the model
speech, sample_rate = librosa.load("speech.wav", sr=None)  # the original track, added to the output video

video = pipe(image=image, audio=audio, output="videos")[0]
encode_video(
    video,
    fps=25,
    output_path="avatar.mp4",
    audio=torch.from_numpy(speech)[None],
    audio_sample_rate=sample_rate,
)
```

Các checkpoint Pro không vừa với GPU 80 GB cùng với bộ mã hóa giọng nói và văn bản 7B khi mọi thành phần đều nằm trên thiết bị. Hãy offload chúng thông qua `ComponentsManager`:

```py
import librosa
import torch
from diffusers import ComponentsManager, ModularPipeline
from diffusers.utils import encode_video, load_image

manager = ComponentsManager()
pipe = ModularPipeline.from_pretrained("kandinskylab/Kandinsky-S2V-1.0-Pro-Diffusers", components_manager=manager)
pipe.load_components(dtype=torch.bfloat16)
manager.enable_auto_cpu_offload(device="cuda", memory_reserve_margin="40GiB")

image = load_image("reference.png")
audio, _ = librosa.load("speech.wav", sr=16000)
speech, sample_rate = librosa.load("speech.wav", sr=None)

video = pipe(image=image, audio=audio, output="videos")[0]
encode_video(
    video,
    fps=25,
    output_path="avatar.mp4",
    audio=torch.from_numpy(speech)[None],
    audio_sample_rate=sample_rate,
)
```

Margin là bộ nhớ được giữ trống ngoài trọng số khi một mô hình được chuyển sang GPU. Nó phải chứa phần giải mã VAE của một khối, khoảng 33 GiB ở độ phân giải 512x768: với giá trị mặc định 3 GB, transformer sẽ ở lại trên GPU trong suốt quá trình giải mã, dẫn đến hết bộ nhớ. Với 40 GiB, đỉnh bộ nhớ sẽ khoảng 50 GiB trên một GPU 80 GB. Hãy bật offload sau `load_components` để nó áp dụng cho mọi thành phần.

## Ghi chú

- `image` là một ảnh PIL và `audio` là dạng sóng float đơn kênh trong khoảng [-1, 1] ở 16 kHz, dưới dạng tensor hoặc mảng có hình dạng `(samples,)`; pipeline không đọc tệp.
- Các khối cấp cao nhất (`text_encoder`, `vae_encoder`, `denoise`, `decode`) cũng có thể chạy độc lập; khi chạy riêng từng khối, hãy truyền cùng giá trị `num_latent_frames` và `fps` cho mỗi khối.
- Số lượng chunk tuân theo độ dài của bản ghi âm thanh trừ khi `num_chunks` được truyền vào. Video sẽ được cắt gọn theo bản ghi âm thanh trong mọi trường hợp, do đó các chunk vượt quá phần cuối của nó sẽ được tính toán và loại bỏ, kèm theo một cảnh báo.
- Với sự dẫn dắt, đường truyền không điều kiện thay thế bằng prompt âm tính *và* làm im tiếng nói, do đó sự dẫn dắt là liên hợp trên cả văn bản và giọng nói.

## KandinskyS2VModularPipeline[[diffusers.KandinskyS2VModularPipeline]]

#### diffusers.KandinskyS2VModularPipeline[[diffusers.KandinskyS2VModularPipeline]]

```python
diffusers.KandinskyS2VModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/kandinsky_s2v/modular_pipeline.py#L91)

ModularPipeline cho việc tạo video từ giọng nói của Kandinsky S2V 1.0.

## KandinskyS2VAutoBlocks[[diffusers.KandinskyS2VAutoBlocks]]

#### diffusers.KandinskyS2VAutoBlocks[[diffusers.KandinskyS2VAutoBlocks]]

```python
diffusers.KandinskyS2VAutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/kandinsky_s2v/modular_blocks_kandinsky_s2v.py#L108)

Đường ống xử lý dạng module cho việc tạo video từ giọng nói với Kandinsky S2V 1.0: một video avatar từ một khung hình tham chiếu và một bản ghi giọng nói, được tạo theo từng khối.

Các thành phần: text_encoder (`Qwen2_5OmniThinkerForConditionalGeneration`) tokenizer (`Qwen2_5OmniProcessor`) text_encoder_2 (`CLIPTextModel`) tokenizer_2 (`CLIPTokenizer`) vae (`AutoencoderKLHunyuanVideo`) video_processor (`VideoProcessor`) transformer (`KandinskyS2VTransformer3DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`) guider (`ClassifierFreeGuidance`)

Inputs: prompt (`str`, *tùy chọn*, mặc định là The video presents a stable medium close-up of a subject facing the camera directly. The subject exhibits natural, lifelike body dynamics: the head and shoulders move fluidly with the rhythm of speech. The lighting is even, maintaining a balanced natural exposure to clearly define facial features without washout. Throughout the sequence, the subject engages in continuous speech marked by precise, high-fidelity articulation. The lips move in a rhythmic, natural pattern: alternating between brief firm closures and relaxed openings. During these openings, the tips of the upper teeth are momentarily and realistically visible, exhibiting natural enamel texture. The upper lip lifts subtly over the teeth during enunciation, while the jaw performs minimal vertical oscillations synchronized with the speech cadence. Facial micro-expressions are active yet restrained; eyebrows rise and lower slightly with minute asymmetry. The eyes maintain a steady, engaged gaze forward, punctuated by smooth, deliberate blinks. ): Prompt để hướng dẫn quá trình tạo. negative_prompt (`str`, *tùy chọn*): Prompt cho bước không điều kiện của guidance. Mặc định là `DEFAULT_NEGATIVE_PROMPT` khi guidance cần đến. audio (`Tensor | ndarray`): Bản ghi âm thanh điều khiển quá trình tạo: dạng sóng float đơn kênh trong khoảng [-1, 1] ở 16000 Hz, có hình dạng (samples,). num_latent_frames (`int`, *tùy chọn*, mặc định là 32): Số khung latent mỗi chunk; 32 cho ra 125 khung (5 giây ở 25 fps). fps (`int`, *tùy chọn*, mặc định là 25): Tốc độ khung hình dùng để tính độ dài chunk. num_chunks (`int`, *tùy chọn*): Số chunk cần tạo. Mặc định là số lượng đủ để bao phủ bản ghi âm thanh; video sẽ được cắt gọn theo bản ghi âm thanh trong mọi trường hợp. image (`Image`): Khung tham chiếu để tạo chuyển động. height (`int`, *tùy chọn*): Chiều cao tính bằng pixel của video được tạo. Mặc định là bucket 512 gần nhất với khung tham chiếu. width (`int`, *tùy chọn*): Chiều rộng tính bằng pixel của video được tạo, được chọn cùng với `height`. generator (`Generator`, *tùy chọn*): Bộ sinh của Torch cho quá trình tạo có tính tất định. num_inference_steps (`int`, *tùy chọn*, mặc định là 50): Số bước khử nhiễu. scale_factor (`tuple`, *tùy chọn*, mặc định là (1.0, 2.0, 2.0)): Hệ số RoPE theo từng trục cho bucket độ phân giải. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.

Đầu ra: video (`list`): Các video được tạo ra.

## KandinskyS2VDistilledModularPipeline[[diffusers.KandinskyS2VDistilledModularPipeline]]

#### diffusers.KandinskyS2VDistilledModularPipeline[[diffusers.KandinskyS2VDistilledModularPipeline]]

```python
diffusers.KandinskyS2VDistilledModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/kandinsky_s2v/modular_pipeline.py#L109)

ModularPipeline cho các checkpoint đã được chưng cất của Kandinsky S2V 1.0 từ pi-Flow.

Guidance được cô đọng vào student, do đó các khối của nó không có guider và không có negative prompt, và chỉ một lần forward pass được thực hiện cho mỗi segment.

## KandinskyS2VDistilledAutoBlocks[[diffusers.KandinskyS2VDistilledAutoBlocks]]

#### diffusers.KandinskyS2VDistilledAutoBlocks[[diffusers.KandinskyS2VDistilledAutoBlocks]]

```python
diffusers.KandinskyS2VDistilledAutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/kandinsky_s2v/modular_blocks_kandinsky_s2v_distilled.py#L103)

Đường ống xử lý dạng module cho việc tạo video từ giọng nói với các checkpoint pi-Flow distilled của Kandinsky S2V 1.0: 16 đoạn mỗi chunk và không có guidance, được distilled vào student.

Các thành phần: text_encoder (`Qwen2_5OmniThinkerForConditionalGeneration`) tokenizer (`Qwen2_5OmniProcessor`) text_encoder_2 (`CLIPTextModel`) tokenizer_2 (`CLIPTokenizer`) vae (`AutoencoderKLHunyuanVideo`) video_processor (`VideoProcessor`) transformer (`KandinskyS2VTransformer3DModel`) scheduler (`PiflowScheduler`)

Inputs: prompt (`str`, *tùy chọn*, mặc định là The video presents a stable medium close-up of a subject facing the camera directly. The subject exhibits natural, lifelike body dynamics: the head and shoulders move fluidly with the rhythm of speech. The lighting is even, maintaining a balanced natural exposure to clearly define facial features without washout. Throughout the sequence, the subject engages in continuous speech marked by precise, high-fidelity articulation. The lips move in a rhythmic, natural pattern: alternating between brief firm closures and relaxed openings. During these openings, the tips of the upper teeth are momentarily and realistically visible, exhibiting natural enamel texture. The upper lip lifts subtly over the teeth during enunciation, while the jaw performs minimal vertical oscillations synchronized with the speech cadence. Facial micro-expressions are active yet restrained; eyebrows rise and lower slightly with minute asymmetry. The eyes maintain a steady, engaged gaze forward, punctuated by smooth, deliberate blinks. ): Prompt để định hướng quá trình tạo. audio (`Tensor | ndarray`): Dải âm thanh điều khiển quá trình tạo: dạng sóng float đơn kênh trong khoảng [-1, 1] ở tần số 16000 Hz, có hình dạng (samples,). num_latent_frames (`int`, *tùy chọn*, mặc định là 32): Số khung latent cho mỗi chunk; 32 cho ra 125 khung (5 giây ở 25 fps). fps (`int`, *tùy chọn*, mặc định là 25): Tốc độ khung hình dùng để tính toán độ dài chunk. num_chunks (`int`, *tùy chọn*): Số chunk cần tạo. Mặc định là số lượng đủ để bao phủ dải âm thanh; video sẽ được cắt gọn theo dải âm thanh trong mọi trường hợp. image (`Image`): Khung tham chiếu để tạo chuyển động. height (`int`, *tùy chọn*): Chiều cao tính bằng pixel của video được tạo. Mặc định là bucket 512 gần nhất với khung tham chiếu. width (`int`, *tùy chọn*): Chiều rộng tính bằng pixel của video được tạo, được chọn cùng với `height`. generator (`Generator`, *tùy chọn*): `Generator` của Torch cho quá trình tạo có tính tất định. num_inference_steps (`int`, *tùy chọn*, mặc định là 16): Số bước khử nhiễu. scale_factor (`tuple`, *tùy chọn*, mặc định là (1.0, 2.0, 2.0)): Hệ số tỷ lệ RoPE cho từng trục của bucket độ phân giải. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.

Đầu ra: video (`list`): Các video được tạo ra.

