Buckets:
Kandinsky 6
Kandinsky 6 là một họ mô hình tạo video từ Kandinsky Lab. Mô hình chính tạo ra video và âm thanh đồng bộ từ văn bản hoặc một hình ảnh tham chiếu bằng một diffusion transformer đa phương thức duy nhất: các latent của video và âm thanh được khử nhiễu cùng nhau thông qua các khối hợp nhất (fused blocks) thực hiện cross-attention giữa hai phương thức, mỗi phương thức được điều kiện bởi nhánh văn bản Qwen2.5-VL riêng của nó và một embedding CLIP đã được pooled. Một mô hình siêu phân giải riêng biệt sẽ tăng độ phân giải của video được tạo ra theo từng ô (tile) trong không gian latent của một K-VAE 3D nhân quả (causal).
Hãy xem tổ chức Kandinsky Lab trên Hub để có bộ checkpoint chính thức đầy đủ, bao gồm các biến thể flow-matching và distilled của cả mô hình base và super-resolution.
Các checkpoint đã được chưng cất được cung cấp kèm theo PiflowScheduler ít bước và phải được chạy với
guidance_scale=1.0.
Các model khả dụng
| Mô hình | Pipeline | Ghi chú |
|---|---|---|
kandinskylab/Kandinsky-6.0-Pro-5s-Diffusers |
Kandinsky6TI2VAPipeline | Flow matching, guidance_scale=5.0, 50 bước |
kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers |
Kandinsky6TI2VAPipeline | Đã chưng cất, guidance_scale=1.0, 10 bước |
kandinskylab/Kandinsky-6.0-Lite-5s-Diffusers |
Kandinsky6TI2VAPipeline | Flow matching, guidance_scale=5.0, 50 bước |
kandinskylab/Kandinsky-6.0-Lite-distill-5s-Diffusers |
Kandinsky6TI2VAPipeline | Đã chưng cất, guidance_scale=1.0, 10 bước |
kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-Diffusers |
Kandinsky6TI2VAPipeline | Flow matching, guidance_scale=5.0, 50 bước |
kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-Diffusers |
Kandinsky6TI2VAPipeline | Flow matching, guidance_scale=5.0, 50 bước |
kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers |
Kandinsky6SRPipeline | Siêu phân giải khớp dòng |
kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers |
Kandinsky6SRPipeline | Siêu phân giải đã chưng cất, 2 bước |
Văn bản/hình ảnh-đến-video-và-âm-thanh
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,
)
Truyền image= để điều kiện khung đầu tiên dựa trên một hình ảnh tham chiếu, sample_audio=False để chỉ tạo video, và expand_prompts=True để cho phép trình mã hóa văn bản Qwen2.5-VL viết lại các prompt ngắn thành các prompt chi tiết trước.
Nâng cao độ phân giải video
Kandinsky6SRPipeline nhận các khung hình do Kandinsky6TI2VAPipeline tạo ra và tăng độ phân giải của chúng lên 2, 4, hoặc 2.25 (gồm bước tiền tăng độ phân giải bilinear 1.125x sau đó đi theo đường dẫn 2x). Video được chia thành các ô chồng lấn lên nhau, mỗi ô được tinh chỉnh ở một trong các kích thước ô mà transformer SR được huấn luyện, và các ô được trộn lại với nhau bằng cửa sổ 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]
Tối ưu hóa bộ nhớ
Tham khảo hướng dẫn Giảm mức sử dụng bộ nhớ cho bộ kỹ thuật chung. Cả Kandinsky6TI2VAPipeline và Kandinsky6SRPipeline đều hỗ trợ model offloading (được sử dụng ở trên) và, để có kích thước nhỏ hơn với cái giá là tốc độ, sequential CPU offloading:
pipe.enable_sequential_cpu_offload()
Video VAE của Kandinsky6TI2VAPipeline cũng hỗ trợ tiled decoding cho độ phân giải cao hoặc video dài:
pipe.vae.enable_tiling()
Ghi chú
heightvàwidthphải chia hết cho tỷ lệ nén không gian của VAE video nhân với kích thước patch của transformer —16với cấu hình mặc định của Kandinsky6TI2VAPipeline (AutoencoderKLHunyuanVideovới tỷ lệ nén8,patch_size=(1, 2, 2)).480x864, được sử dụng trong ví dụ trên, thỏa mãn điều kiện này.- Đầu vào
videocủa Kandinsky6SRPipeline phải có1 + k * vae_scale_factor_temporalkhung hình với một số nguyênk(tỷ lệ nén theo thời gian là4với cấu hình K-VAE mặc định, do đó121khung hình hoạt động được nhưng120thì không) — hãy cắt hoặc đệm video chưa thỏa mãn điều kiện này trước khi tăng độ phân giải. expand_prompts=Truetái sử dụng text encoder của Qwen2.5-VL đã được nạp sẵn cho một lượt sinh thêm trước khi khử nhiễu, do đó làm tăng độ trễ nhưng không thêm trọng số mô hình.- Biên dịch các khối transformer lặp lại để suy luận lặp lại nhanh hơn:
pipe.transformer.compile_repeated_blocks(fullgraph=True)
Kandinsky6TI2VAPipeline[[diffusers.Kandinsky6TI2VAPipeline]]
diffusers.Kandinsky6TI2VAPipeline[[diffusers.Kandinsky6TI2VAPipeline]]
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)
Tham số:
transformer (Kandinsky6Transformer3DModel) : Transformer đa phương thức khử nhiễu các ẩn (latents) của video và âm thanh.
vae (AutoencoderKLHunyuanVideo) : VAE video được sử dụng để mã hóa hình ảnh tham chiếu và giải mã video được tạo ra.
text_encoder (Qwen2_5_VLForConditionalGeneration) : Mô hình Qwen2.5-VL cung cấp các embedding văn bản ở cấp độ token và, tùy chọn, mở rộng prompt.
tokenizer (Qwen2_5_VLProcessor) : Bộ xử lý của text_encoder.
text_encoder_2 (CLIPTextModel): Bộ mã hóa văn bản CLIP cung cấp nhúng văn bản đã gộp (pooled text embedding).
tokenizer_2 (CLIPTokenizer) : Tokenizer của text_encoder_2.
scheduler (FlowMatchEulerDiscreteScheduler hoặc PiflowScheduler): Scheduler được sử dụng cùng với transformer để khử nhiễu các latents. Các checkpoint đã được chưng cất đi kèm với PiflowScheduler và phải được chạy với guidance_scale=1.0.
audio_vae (MMAudioVAE, tùy chọn) : Audio VAE được sử dụng để giải mã các audio latents đã tạo thành mel spectrogram. Chỉ cần thiết khi sample_audio=True.
vocoder (MMAudioVocoder, tùy chọn) : Vocoder được dùng để chuyển đổi phổ mel mà audio_vae giải mã thành dạng sóng. Chỉ cần thiết khi sample_audio=True.
Pipeline để tạo video và âm thanh từ văn bản/ảnh với Kandinsky 6.
Latent của video và âm thanh được khử nhiễu cùng nhau bởi một transformer đa phương thức duy nhất, có điều kiện dựa trên các token văn bản của Qwen2.5-VL và một embedding pooled của CLIP. Một hình ảnh tham chiếu tùy chọn sẽ điều kiện khung hình đầu tiên.
Mô hình này kế thừa từ DiffusionPipeline. Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).
call[[diffusers.Kandinsky6TI2VAPipeline.call]]
__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'])
Tham số:
prompt (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt để hướng dẫn quá trình tạo. Bắt buộc trừ khi prompt_embeds được cung cấp.
image (PipelineImageInput, tùy chọn) : Ảnh tham chiếu điều kiện khung hình đầu tiên (image-to-video-and-audio).
negative_prompt (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt không được dùng để hướng dẫn quá trình tạo. Mặc định là negative prompt của Kandinsky 6.
height (int, mặc định là 512) : Chiều cao của video được tạo ra, tính bằng pixel.
width (int, mặc định là 768) : Độ rộng của video được tạo ra, tính bằng pixel.
num_frames (int, mặc định là 121) : Số lượng khung hình được tạo ra.
frame_rate (float, mặc định là 24.0) : Tốc độ khung hình mà video được tạo ra; xác định độ dài của âm thanh đồng bộ.
num_inference_steps (int, mặc định là 50) : Số bước khử nhiễu. Sử dụng 16 với các checkpoint đã được chưng cất.
timesteps (list[int], tùy chọn) : Các bước thời gian tùy chỉnh dành cho các trình lập lịch hỗ trợ chúng.
sigmas (list[float], tùy chọn) : Các sigma tùy chỉnh dành cho các trình lập lịch hỗ trợ chúng.
guidance_scale (float, mặc định là 5.0) : Thang độ hướng dẫn không có điều kiện (classifier-free guidance). Phải là 1.0 với PiflowScheduler.
num_videos_per_prompt (int, mặc định là 1) : Số lượng video cần tạo cho mỗi prompt.
generator (torch.Generator hoặc list[torch.Generator], tùy chọn) : Bộ tạo (Generator) được sử dụng cho nhiễu ban đầu và mã hóa ảnh tham chiếu.
latents (torch.Tensor, tùy chọn) : Các latents video đã tạo trước có hình dạng (batch_size, channels, num_latent_frames, latent_height, latent_width).
audio_latents (torch.Tensor, tùy chọn) : Các latents âm thanh đã tạo trước có hình dạng (batch_size, channels, audio_length).
prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản Qwen2.5-VL đã được tạo trước.
pooled_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản pooled của CLIP đã được tạo trước.
negative_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản âm của Qwen2.5-VL đã được tạo trước.
negative_pooled_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản pooled CLIP âm được tạo trước.
sample_audio (bool, mặc định là True) : Có tạo âm thanh đồng bộ hay không. Yêu cầu pipeline phải có audio_vae và vocoder.
expand_prompts (bool, mặc định là False) : Có nên viết lại các prompt bằng expand_prompts() trước khi mã hóa hay không.
max_sequence_length (int, mặc định là 1024) : Số lượng tối đa của các token prompt sau khi áp dụng chat template.
output_type (str, mặc định là "pil") : Định dạng đầu ra của video được tạo: "pil", "np", "pt" hoặc "latent".
return_dict (bool, mặc định là True) : Có nên trả về một Kandinsky6TI2VAPipelineOutput thay vì một tuple thông thường hay không.
callback_on_step_end (Callable, tùy chọn) : Một hàm được gọi vào cuối mỗi bước khử nhiễu với callback_on_step_end(self, step, timestep, callback_kwargs). Nó có thể trả về một dict ghi đè các tensor được liệt kê.
callback_on_step_end_tensor_inputs (list[str], mặc định là ["latents"]) : Các đầu vào Tensor được truyền vào callback_on_step_end; một tập con của _callback_tensor_inputs.
Trả về: Kandinsky6TI2VAPipelineOutput hoặc tuple
Video và âm thanh được tạo ra; một tuple (frames, audio) khi return_dict=False.
Hàm gọi call của pipeline để tạo nội dung.
Ví dụ:
>>> 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]]
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)
Mã hóa ảnh tham chiếu thành latents của khung hình đầu tiên có hình dạng (batch_size, latent_height, latent_width, latent_channels), được nhân với scaling_factor của VAE. Ảnh PIL sẽ được thay đổi kích thước và cắt giữa thành height x width; tensor và mảng phải đã có kích thước đó. Các latents được lặp lại num_videos_per_prompt lần dọc theo chiều batch.
encode_prompt[[diffusers.Kandinsky6TI2VAPipeline.encode_prompt]]
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)
Tham số:
prompt (str hoặc list[str]) : Prompt cần được mã hóa.
negative_prompt (str hoặc list[str], tùy chọn) : Prompt không dùng để hướng dẫn quá trình sinh. Bỏ qua khi do_classifier_free_guidance là False.
do_classifier_free_guidance (bool, mặc định là True) : Có mã hóa cả prompt tiêu cực hay không.
num_videos_per_prompt (int, mặc định là 1) : Số lượng video được tạo cho mỗi prompt; các embeddings sẽ được lặp lại tương ứng.
prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản Qwen2.5-VL đã được tạo trước. Bỏ qua việc mã hóa prompt.
pooled_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản pooled của CLIP đã được tạo trước. Phải được cung cấp cùng với prompt_embeds.
prompt_attention_mask (torch.Tensor, tùy chọn) : Mặt nạ đệm Boolean của prompt_embeds.
negative_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản âm của Qwen2.5-VL đã được tạo trước.
negative_pooled_prompt_embeds (torch.Tensor, tùy chọn) : Các embedding văn bản pooled CLIP âm được tạo trước.
negative_prompt_attention_mask (torch.Tensor, tùy chọn) : Mặt nạ đệm Boolean của negative_prompt_embeds.
max_sequence_length (int, mặc định là 1024) : Số lượng tối đa của các token prompt sau khi áp dụng chat template.
device (torch.device, tùy chọn) : Thiết bị để chạy các text encoder.
dtype (torch.dtype, tùy chọn) : Kiểu dữ liệu của các embedding được trả về.
Mã hóa prompt thành các trạng thái ẩn của text encoder.
expand_prompts[[diffusers.Kandinsky6TI2VAPipeline.expand_prompts]]
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)
Tham số:
prompt (str hoặc list[str]) : Prompt hoặc các prompt cần mở rộng.
tokenizer : Bộ xử lý Qwen2.5-VL, ví dụ pipe.tokenizer.
text_encoder : Mô hình Qwen2.5-VL, ví dụ pipe.text_encoder.
device (torch.device) : Thiết bị để chạy text encoder.
image (PIL.Image.Image hoặc list[PIL.Image.Image], tùy chọn) : Ảnh tham chiếu cho một cuộc gọi image-to-video.
max_sequence_length (int, mặc định là 1024) : Số lượng token tối đa được tạo ra cho mỗi prompt.
generator (torch.Generator hoặc list[torch.Generator], optional) : Khởi tạo hạt (seed) cho phần mở rộng được lấy mẫu; một danh sách phải khớp với độ dài của prompt, mỗi phần tử tương ứng với một generator. generate lấy mẫu từ RNG toàn cục, do đó RNG toàn cục được khởi tạo từ seed của generator này; các lời gọi randn_tensor sau đó sẽ tiếp tục sử dụng trực tiếp generator.
Trả về: str hoặc list[str]
Mẫu câu (prompt) đã được mở rộng.
Viết lại các prompt ngắn thành các prompt video+audio chi tiết bằng text encoder Qwen2.5-VL, dựa trên hình ảnh tham chiếu nếu có. Đây là một staticmethod nên có thể sử dụng độc lập, trước khi chạy pipeline.
prepare_audio_latents[[diffusers.Kandinsky6TI2VAPipeline.prepare_audio_latents]]
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)
Trả về các audio latents theo bố cục (batch_size, audio_length, channels) của transformer. Tensor audio_latents do người dùng cung cấp được kỳ vọng có bố cục (batch_size, channels, audio_length).
prepare_latents[[diffusers.Kandinsky6TI2VAPipeline.prepare_latents]]
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)
Trả về video latents theo bố cục (batch_size, num_frames, height, width, channels) của transformer. Tensor latents do người dùng cung cấp được kỳ vọng theo bố cục (batch_size, channels, num_frames, height, width).
Kandinsky6SRPipeline[[diffusers.Kandinsky6SRPipeline]]
diffusers.Kandinsky6SRPipeline[[diffusers.Kandinsky6SRPipeline]]
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)
Tham số:
transformer (Kandinsky6SRTransformer3DModel) : Transformer tinh chỉnh các ô tiềm ẩn.
vae (Kandinsky6SRVAE) : K-VAE video nhân quả được sử dụng để mã hóa video đầu vào và giải mã các ô đã tinh chỉnh.
scheduler (FlowMatchEulerDiscreteScheduler hoặc PiflowScheduler) : Scheduler được sử dụng cùng với transformer để khử nhiễu các tile. Các checkpoint đã được chưng cất đi kèm với PiflowScheduler.
latent_upscaler (Kandinsky6SRLatentUpscalerBank, tùy chọn) : Bộ upscaler latent cho các tỷ lệ được hỗ trợ.
Pipeline cho siêu phân giải video với Kandinsky 6.
Video được chia thành các ô không gian chồng lấn lên nhau, mỗi ô được tinh chỉnh bởi transformer SR ở một trong các kích thước ô mà mô hình đã được huấn luyện (transformer.config.tile_sizes), và các ô đã tinh chỉnh được trộn lại bằng cửa sổ Hann. Khi pipeline có latent_upscaler, các ô được cắt từ latents K-VAE của toàn bộ video và được tăng kích thước trong không gian latent; ngược lại, các ô pixel được tăng kích thước bằng nội suy hai tuyến tính và được mã hóa.
Mô hình này kế thừa từ DiffusionPipeline. Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).
call[[diffusers.Kandinsky6SRPipeline.call]]
__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)
Tham số:
video (list[PIL.Image.Image], np.ndarray hoặc torch.Tensor) : Video độ phân giải thấp, ở bất kỳ định dạng nào mà preprocess_video() chấp nhận, với 1 + k * 4 khung hình. Kích thước được làm tròn xuống đến bội số của hệ số không gian của VAE.
resolution_scale (float, mặc định là 2.25) : Tổng hệ số phóng to không gian: 2, 4, hoặc 2.25 (phóng to trước 1.125x bằng phương pháp nội suy song tuyến tính, sau đó đi theo đường dẫn 2x).
num_inference_steps (int, mặc định là 4) : Số bước khử nhiễu cho mỗi ô. Sử dụng 2 với các checkpoint đã được chưng cất.
timesteps (list[int], tùy chọn) : Các bước thời gian tùy chỉnh dành cho các trình lập lịch hỗ trợ chúng.
sigmas (list[float], tùy chọn) : Các sigma tùy chỉnh dành cho các trình lập lịch hỗ trợ chúng.
lq_noise_scale (float, mặc định là 0.7) : Lượng nhiễu Gaussian được trộn vào các latents độ phân giải thấp (bảo toàn phương sai) trước khi khử nhiễu.
min_overlap (float, mặc định là 0.2) : Mức độ chồng lấn tối thiểu giữa các ô kề nhau, tính theo phần trăm kích thước của ô.
tiles_batch_size (int, mặc định là 1) : Số lượng tile được khử nhiễu trong mỗi lần gọi transformer.
generator (torch.Generator hoặc list[torch.Generator], tùy chọn) : Bộ tạo (Generator) được sử dụng cho nhiễu được trộn vào các ô (tiles).
output_type (str, mặc định là "pil") : Định dạng đầu ra của video được tạo: "pil", "np" hoặc "pt".
return_dict (bool, mặc định là True) : Có nên trả về một Kandinsky6SRPipelineOutput thay vì một tuple thông thường hay không.
Trả về: Kandinsky6SRPipelineOutput hoặc tuple
Video siêu phân giải; một tuple một phần tử khi return_dict=False.
Hàm gọi call của pipeline cho siêu phân giải.
Ví dụ:
>>> 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]]
decode_latents(latents: Tensor)
Giải mã các latents K-VAE đã được scale thành video (batch_size, channels, num_frames, height, width) trong [-1, 1].
encode_video[[diffusers.Kandinsky6SRPipeline.encode_video]]
encode_video(video: Tensor)
Mã hóa video (batch_size, channels, num_frames, height, width) trong [-1, 1] thành các latents K-VAE được nhân với scaling_factor của VAE.
Kandinsky6SRLatentUpscalerBank[[diffusers.Kandinsky6SRLatentUpscalerBank]]
diffusers.Kandinsky6SRLatentUpscalerBank[[diffusers.Kandinsky6SRLatentUpscalerBank]]
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)
Tham số:
in_channels (int, mặc định là 64) : Số lượng kênh tiềm ẩn.
stage_channels (tuple[int, int, int], mặc định là (2048, 1024, 512)) : Độ rộng đặc trưng của ba giai đoạn trong cascade.
num_pre_blocks (int, mặc định là 5) : Các khối residual trước bước upsample đầu tiên của mô hình x4.
num_mid_blocks (int, mặc định là 3) : Các khối residual giữa hai lần upsampling.
num_post_blocks (int, mặc định là 3) : Các khối residual sau bước upsample cuối cùng.
num_x2_adapter_blocks (int, mặc định là 2) : Các khối residual của adapter trong mô hình x2.
scales (tuple[int, ...], mặc định là (2, 4)) : Các tỷ lệ không gian mà ngân hàng cung cấp bộ tăng độ phân giải.
scaling_factor (float, mặc định là 0.910344) : Thang đo mà các latents đầu vào được kỳ vọng mang theo (tham số scaling_factor của K-VAE).
Ngân hàng các bộ tăng độ phân giải tiềm ẩn (latent upscaler) được sử dụng bởi Kandinsky6SRPipeline: một Kandinsky6SRLatentUpscaler cho mỗi tỷ lệ không gian được hỗ trợ, hoạt động trên các latent của K-VAE.
forward[[diffusers.Kandinsky6SRLatentUpscalerBank.forward]]
forward(latents: Tensor, scale: int, return_dict: bool = True)
Tham số:
latents (torch.Tensor có hình dạng (batch_size, in_channels, num_frames, height, width)) : latents của K-VAE đã được nhân với scaling_factor.
scale (int) : Hệ số phóng to không gian; một trong các scales.
return_dict (bool, mặc định là True) : Có nên trả về một ~models.autoencoder_kl.DecoderOutput thay vì một tuple thông thường hay không.
Trả về:
Các latents đã được phóng to có hình dạng (batch_size, in_channels, num_frames, height * scale, width * scale).
Kandinsky6TI2VAPipelineOutput[[diffusers.Kandinsky6TI2VAPipelineOutput]]
diffusers.Kandinsky6TI2VAPipelineOutput[[diffusers.Kandinsky6TI2VAPipelineOutput]]
diffusers.Kandinsky6TI2VAPipelineOutput(frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]], audio: typing.Union[torch.Tensor, numpy.ndarray, NoneType] = None)
Tham số:
frames (torch.Tensor, np.ndarray, hoặc list[list[PIL.Image.Image]]) : Video đã được tạo. Một danh sách lồng nhau có độ dài batch_size, mỗi phần tử chứa num_frames hình ảnh PIL, hoặc một mảng NumPy hoặc tensor torch có hình dạng (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width). Với output_type="latent", các latent của video có hình dạng (batch_size, channels, num_latent_frames, latent_height, latent_width).
audio (torch.Tensor hoặc np.ndarray, tùy chọn) : Các waveform được tạo ra có hình dạng (batch_size, num_samples) trong khoảng [-1, 1] ở tốc độ lấy mẫu của audio VAE, hoặc None khi audio không được lấy mẫu. Với output_type="latent", các audio latents có hình dạng (batch_size, channels, audio_length).
Lớp đầu ra cho Kandinsky6TI2VAPipeline.
Kandinsky6SRPipelineOutput[[diffusers.Kandinsky6SRPipelineOutput]]
diffusers.Kandinsky6SRPipelineOutput[[diffusers.Kandinsky6SRPipelineOutput]]
diffusers.Kandinsky6SRPipelineOutput(frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]])
Tham số:
frames (torch.Tensor, np.ndarray, hoặc list[list[PIL.Image.Image]]) : Video đã được tăng phân giải. Một danh sách lồng nhau có độ dài batch_size, mỗi phần tử chứa num_frames hình ảnh PIL, hoặc một mảng NumPy hoặc tensor torch có hình dạng (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width).
Lớp đầu ra cho Kandinsky6SRPipeline.
Xet Storage Details
- Size:
- 39.1 kB
- Xet hash:
- 4520ffcd820accfd08d14a5d068e1e61673a41f8419e6391acc3b857617b2089
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.