Diffusers documentation

Kandinsky S2V 1.0

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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 thanh. Người trong khung hình sẽ được tạo 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à bạn truyền vào.

Cả hai điều kiện đều đi qua Qwen2.5-Omni-7B: 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, thứ đ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 giọng nói mà nó bao phủ. Một 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 hơn 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 duy nhất; không có lớp DiffusionPipeline tiêu chuẩn cho nó.

Điểm kiểm tra

CheckpointTransformerCác khốiTrình lập lịchCác bướcHướng dẫn
Lite2BKandinskyS2VAutoBlocksFlowMatchEulerDiscreteScheduler503.0
Pro21BKandinskyS2VAutoBlocksFlowMatchEulerDiscreteScheduler503.0
Lite đã được chưng cất2BKandinskyS2VDistilledAutoBlocksPiflowScheduler16off
Pro đã được chưng cất21BKandinskyS2VDistilledAutoBlocksPiflowScheduler16off

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ó.

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

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:

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 VAE decode của một khối, khoảng 33 GiB ở 512x768: với mặc định 3 GB transformer vẫn ở trên GPU trong suốt quá trình decode, sau đó sẽ hết bộ nhớ. Với 40 GiB, đỉnh sẽ khoảng 50 GiB trên GPU 80 GB. 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 chúng riêng lẻ, hãy truyền cùng giá trị num_latent_frames và fps cho từng 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 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

lớp diffusers.KandinskyS2VModularPipeline

< >

( blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = Nonepretrained_model_name_or_path: str | os.PathLike | None = Nonecomponents_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = Nonecollection: str | None = Noneworkflow: str | None = Nonemodular_config_dict: dict[str, typing.Any] | None = Noneconfig_dict: dict[str, typing.Any] | None = None**kwargs )

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

KandinskyS2VAutoBlocks

lớp diffusers.KandinskyS2VAutoBlocks

< >

( )

Đường ống xử lý theo mô-đun 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)

Đầu vào: 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. 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): Đường dẫn giọng nói điều khiển quá trình tạo: dạng sóng float đơn kênh trong [-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 hình latent mỗi chunk; 32 cho ra 125 khung hình (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ố lượng chunk cần tạo. Mặc định là số lượng đủ để bao phủ đường dẫn giọng nói; video sẽ được cắt gọn theo đường dẫn đó trong mọi trường hợp. image (Image): Khung hình 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 hình 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): Torch generator cho quá trình tạo có tính xác đị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ố tỷ lệ 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: videos (list): Các video được tạo.

KandinskyS2VDistilledModularPipeline

lớp diffusers.KandinskyS2VDistilledModularPipeline

< >

( blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = Nonepretrained_model_name_or_path: str | os.PathLike | None = Nonecomponents_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = Nonecollection: str | None = Noneworkflow: str | None = Nonemodular_config_dict: dict[str, typing.Any] | None = Noneconfig_dict: dict[str, typing.Any] | None = None**kwargs )

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

Guidance được chưng cất 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

lớp diffusers.KandinskyS2VDistilledAutoBlocks

< >

( )

Pipeline dạng module cho việc tạo video từ giọng nói với các checkpoint pi-Flow distilled 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)

Đầu vào: 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. ): Lời nhắc để định hướng quá trình tạo. audio (Tensor | ndarray): Đường dẫn giọng nói đ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 hình tiềm ẩn cho mỗi khối; 32 cho ra 125 khung hình (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 khối. num_chunks (int, tùy chọn): Số khối cần tạo. Mặc định là số lượng bao phủ toàn bộ đường dẫn giọng nói; video sẽ được cắt gọn theo đường dẫn trong mọi trường hợp. image (Image): Khung hình 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 hình 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): Trình tạo 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: videos (list): Các video được tạo.

Update on GitHub