Diffusers documentation

Kandinsky 5.0 Image

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 5.0 Image

Kandinsky 5.0 là một họ mô hình khuếch tán cho việc tạo Video & Ảnh.

Kandinsky 5.0 Image Lite là một mô hình tạo ảnh nhẹ (6B tham số).

Mô hình giới thiệu một số đổi mới chính:

  • Pipeline khuếch tán tiềm ẩn với Flow Matching để cải thiện độ ổn định huấn luyện
  • Diffusion Transformer (DiT) làm khung xương sinh chính với cross-attention đến text embeddings
  • Mã hóa văn bản kép sử dụng Qwen2.5-VL và CLIP để hiểu văn bản toàn diện
  • Flux VAE để mã hóa và giải mã hình ảnh hiệu quả

Mã nguồn gốc có thể được tìm thấy tại kandinskylab/Kandinsky-5.

Xem tổ chức Kandinsky Lab trên Hub để tìm các checkpoint mô hình chính thức cho việc tạo video từ văn bản, bao gồm các biến thể được huấn luyện trước, SFT, no-CFG và distilled.

Các Mô hình Có sẵn

Kandinsky 5.0 Image Lite:

model_idMô tảCác trường hợp sử dụng
kandinskylab/Kandinsky-5.0-T2I-Lite-sft-DiffusersMô hình 6B hình ảnh được tinh chỉnh có giám sátChất lượng sinh cao nhất
kandinskylab/Kandinsky-5.0-I2I-Lite-sft-DiffusersMô hình Supervised Fine-Tuned chỉnh sửa ảnh 6BChất lượng sinh cao nhất
kandinskylab/Kandinsky-5.0-T2I-Lite-pretrain-DiffusersMô hình được huấn luyện trước cơ sở hình ảnh 6BNghiên cứu và tinh chỉnh
kandinskylab/Kandinsky-5.0-I2I-Lite-pretrain-DiffusersMô hình được huấn luyện trước cơ bản cho chỉnh sửa ảnh 6BNghiên cứu và tinh chỉnh

Ví dụ sử dụng

Tạo hình ảnh từ văn bản cơ bản

import torch
from diffusers import Kandinsky5T2IPipeline

# Load the pipeline
model_id = "kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers"
pipe = Kandinsky5T2IPipeline.from_pretrained(model_id)
_ = pipe.to(device='cuda',dtype=torch.bfloat16)  # or "mps", "xpu", "cpu"

# Generate image
prompt = "A fluffy, expressive cat wearing a bright red hat with a soft, slightly textured fabric. The hat should look cozy and well-fitted on the cat’s head. On the front of the hat, add clean, bold white text that reads “SWEET”, clearly visible and neatly centered. Ensure the overall lighting highlights the hat’s color and the cat’s fur details."

output = pipe(
    prompt=prompt,
    negative_prompt="",
    height=1024,
    width=1024,
    num_inference_steps=50,
    guidance_scale=3.5,
).image[0]

Tạo ảnh từ ảnh cơ bản

import torch
from diffusers import Kandinsky5I2IPipeline
from diffusers.utils import load_image 
# Load the pipeline
model_id = "kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers"
pipe = Kandinsky5I2IPipeline.from_pretrained(model_id)

_ = pipe.to(device='cuda',dtype=torch.bfloat16)  # or "mps", "xpu", "cpu"
pipe.enable_model_cpu_offload()                                               # <--- Enable CPU offloading for single GPU inference

# Edit the input image
image = load_image(
    "https://huggingface.co/kandinsky-community/kandinsky-3/resolve/main/assets/title.jpg?download=true"
)

prompt = "Change the background from a winter night scene to a bright summer day. Place the character on a sandy beach with clear blue sky, soft sunlight, and gentle waves in the distance. Replace the winter clothing with a light short-sleeved T-shirt (in soft pastel colors) and casual shorts. Ensure the character’s fur reflects warm daylight instead of cold winter tones. Add small beach details such as seashells, footprints in the sand, and a few scattered beach toys nearby. Keep the oranges in the scene, but place them naturally on the sand."
negative_prompt = ""

output = pipe(
    image=image,
    prompt=prompt,
    negative_prompt=negative_prompt,
    guidance_scale=3.5,
).image[0]

Kandinsky5T2IPipeline

lớp diffusers.Kandinsky5T2IPipeline

< >

( transformer: Kandinsky5Transformer3DModelvae: AutoencoderKLtext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2VLProcessortext_encoder_2: CLIPTextModeltokenizer_2: CLIPTokenizerscheduler: FlowMatchEulerDiscreteScheduler )

Tham số

  • transformer (Kandinsky5Transformer3DModel) — Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa.
  • vae (AutoencoderKL) — Mô hình Variational Auto-Encoder black-forest-labs/FLUX.1-dev (vae) để mã hóa và giải mã video sang và từ các biểu diễn ẩn (latent).
  • text_encoder (Qwen2_5_VLForConditionalGeneration) — Bộ mã hóa văn bản đóng băng Qwen2.5-VL.
  • tokenizer (AutoProcessor) — Tokenizer cho Qwen2.5-VL.
  • text_encoder_2 (CLIPTextModel) — CLIP được đóng băng, cụ thể là biến thể clip-vit-large-patch14.
  • tokenizer_2 (CLIPTokenizer) — Tokenizer cho CLIP.
  • scheduler (FlowMatchEulerDiscreteScheduler) — Một scheduler được sử dụng kết hợp với transformer để khử nhiễu các latents ảnh đã được mã hóa.

Pipeline để tạo ảnh từ văn bản sử dụng Kandinsky 5.0.

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__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 1024width: int = 1024num_inference_steps: int = 50guidance_scale: float = 3.5num_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds_qwen: typing.Optional[torch.Tensor] = Noneprompt_embeds_clip: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_qwen: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_clip: typing.Optional[torch.Tensor] = Noneprompt_cu_seqlens: typing.Optional[torch.Tensor] = Nonenegative_prompt_cu_seqlens: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~KandinskyImagePipelineOutput or tuple

Tham số

  • prompt (str hoặc list[str], tùy chọn) — Prompt hoặc các prompt để định hướng việc tạo ảnh. Nếu không được định nghĩa, hãy truyền prompt_embeds thay thế.
  • negative_prompt (str hoặc list[str], tùy chọn) — Prompt hoặc các prompt cần tránh trong quá trình tạo ảnh. Nếu không được định nghĩa, hãy truyền negative_prompt_embeds thay thế. Tham số này bị bỏ qua khi không sử dụng guidance (guidance_scale < 1).
  • height (int, mặc định là 1024) — Chiều cao của hình ảnh được tạo ra, tính bằng pixel.
  • width (int, mặc định là 1024) — Chiều rộng của hình ảnh được tạo ra, tính bằng pixel.
  • num_inference_steps (int, mặc định là 50) — Số bước khử nhiễu.
  • guidance_scale (float, mặc định là 5.0) — Thang độ dẫn hướng như được định nghĩa trong classifier-free guidance.
  • num_images_per_prompt (int, tùy chọn, mặc định là 1) — Số lượng hình ảnh cần tạo cho mỗi prompt.
  • generator (torch.Generator hoặc list[torch.Generator], tùy chọn) — Một torch generator để đảm bảo quá trình sinh ra là tất định.
  • latents (torch.Tensor, tùy chọn) — Các latents nhiễu đã được tạo trước.
  • prompt_embeds_qwen (torch.Tensor, tùy chọn) — Các embedding văn bản Qwen đã được tạo trước.
  • prompt_embeds_clip (torch.Tensor, tùy chọn) — Các embedding văn bản CLIP đã được tạo trước.
  • negative_prompt_embeds_qwen (torch.Tensor, tùy chọn) — Các embedding văn bản âm của Qwen đã được tạo trước.
  • negative_prompt_embeds_clip (torch.Tensor, tùy chọn) — Các embedding văn bản âm đã tạo trước của CLIP.
  • prompt_cu_seqlens (torch.Tensor, tùy chọn) — Độ dài chuỗi tích lũy đã tạo trước cho prompt dương của Qwen.
  • negative_prompt_cu_seqlens (torch.Tensor, tùy chọn) — Độ dài chuỗi tích lũy đã tạo trước cho Qwen negative prompt.
  • output_type (str, tùy chọn, mặc định là "pil") — Định dạng đầu ra của hình ảnh được tạo.
  • return_dict (bool, tùy chọn, mặc định là True) — Có nên trả về một KandinskyImagePipelineOutput hay không.
  • callback_on_step_end (Callable, PipelineCallback, MultiPipelineCallbacks, tùy chọn) — Một hàm được gọi vào cuối mỗi bước khử nhiễu.
  • callback_on_step_end_tensor_inputs (List, tùy chọn) — Danh sách các đầu vào tensor cho hàm callback_on_step_end.
  • max_sequence_length (int, mặc định là 512) — Chiều dài tối đa của chuỗi cho việc mã hóa văn bản.

Trả về

~KandinskyImagePipelineOutput hoặc tuple

Nếu return_dict là True, KandinskyImagePipelineOutput sẽ được trả về, ngược lại một tuple sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã được tạo.

Hàm gọi call của pipeline để tạo ảnh từ văn bản.

Ví dụ:

>>> import torch
>>> from diffusers import Kandinsky5T2IPipeline

>>> # Available models:
>>> # kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2I-Lite-pretrain-Diffusers

>>> model_id = "kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers"
>>> pipe = Kandinsky5T2IPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen."

>>> output = pipe(
...     prompt=prompt,
...     negative_prompt="",
...     height=1024,
...     width=1024,
...     num_inference_steps=50,
...     guidance_scale=3.5,
... ).frames[0]

check_inputs

< >

( promptnegative_promptheightwidthprompt_embeds_qwen = Noneprompt_embeds_clip = Nonenegative_prompt_embeds_qwen = Nonenegative_prompt_embeds_clip = Noneprompt_cu_seqlens = Nonenegative_prompt_cu_seqlens = Nonecallback_on_step_end_tensor_inputs = Nonemax_sequence_length = None )

Tham số

  • prompt — Prompt đầu vào
  • negative_prompt — Prompt tiêu cực để điều hướng
  • height — Chiều cao của ảnh
  • width — Chiều rộng của ảnh
  • prompt_embeds_qwen — Nhúng prompt Qwen đã tính trước
  • prompt_embeds_clip — Các embedding prompt CLIP đã được tính trước
  • negative_prompt_embeds_qwen — Các embedding âm của prompt Qwen đã được tính trước
  • negative_prompt_embeds_clip — Các embedding âm của prompt CLIP đã được tính trước
  • prompt_cu_seqlens — Độ dài chuỗi tích lũy đã tính trước cho prompt tích cực của Qwen
  • negative_prompt_cu_seqlens — Độ dài chuỗi tích lũy đã tính trước cho prompt âm của Qwen
  • callback_on_step_end_tensor_inputs — Đầu vào tensor của callback

Gây ra

ValueError

  • ValueError — Nếu các đầu vào không hợp lệ

Xác thực các tham số đầu vào cho pipeline.

encode_prompt

< >

( prompt: str | list[str]num_images_per_prompt: int = 1max_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None ) → tuple[torch.Tensor, torch.Tensor, torch.Tensor]

Tham số

  • prompt (str hoặc list[str]) — Prompt cần được mã hóa.
  • num_images_per_prompt (int, tùy chọn, mặc định là 1) — Số lượng hình ảnh cần tạo cho mỗi prompt.
  • max_sequence_length (int, tùy chọn, mặc định là 512) — Độ dài tối đa của chuỗi cho việc mã hóa văn bản. Phải nhỏ hơn 1024
  • device (torch.device, tùy chọn) — Thiết bị Torch.
  • dtype (torch.dtype, tùy chọn) — Dtype của Torch.

Trả về

tuple[torch.Tensor, torch.Tensor, torch.Tensor]

  • Qwen text embeddings có shape (batch_size * num_images_per_prompt, sequence_length, embedding_dim)
  • CLIP pooled embeddings có shape (batch_size * num_images_per_prompt, clip_embedding_dim)
  • Chiều dài chuỗi tích lũy (cu_seqlens) cho Qwen embeddings có shape (batch_size * num_images_per_prompt + 1,)

Mã hóa một prompt duy nhất (tích cực hoặc tiêu cực) thành các trạng thái ẩn của text encoder.

Phương pháp này kết hợp các embedding từ cả hai bộ mã hóa văn bản Qwen2.5-VL và CLIP để tạo ra các biểu diễn văn bản toàn diện cho việc tạo hình ảnh.

prepare_latents

< >

( batch_size: intnum_channels_latents: int = 16height: int = 1024width: int = 1024dtype: typing.Optional[torch.dtype] = Nonedevice: typing.Optional[torch.device] = Nonegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = None ) → torch.Tensor

Tham số

  • batch_size (int) — Số lượng ảnh cần tạo
  • num_channels_latents (int) — Số kênh trong không gian ẩn
  • height (int) — Chiều cao của hình ảnh được tạo
  • width (int) — Độ rộng của hình ảnh được tạo
  • dtype (torch.dtype) — Kiểu dữ liệu cho latents
  • device (torch.device) — Thiết bị để tạo latents
  • generator (torch.Generator) — Bộ tạo số ngẫu nhiên
  • latents (torch.Tensor) — Các latents có sẵn để sử dụng

Trả về

torch.Tensor

Tensor latent đã được chuẩn bị

Chuẩn bị các biến tiềm ẩn ban đầu cho việc tạo ảnh từ văn bản.

Phương pháp này tạo ra các latent nhiễu ngẫu nhiên

Kandinsky5I2IPipeline

lớp diffusers.Kandinsky5I2IPipeline

< >

( transformer: Kandinsky5Transformer3DModelvae: AutoencoderKLtext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2VLProcessortext_encoder_2: CLIPTextModeltokenizer_2: CLIPTokenizerscheduler: FlowMatchEulerDiscreteScheduler )

Tham số

  • transformer (Kandinsky5Transformer3DModel) — Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa.
  • vae (AutoencoderKL) — Mô hình Variational Auto-Encoder black-forest-labs/FLUX.1-dev (vae) để mã hóa và giải mã video sang và từ các biểu diễn ẩn (latent).
  • text_encoder (Qwen2_5_VLForConditionalGeneration) — Bộ mã hóa văn bản đóng băng Qwen2.5-VL.
  • tokenizer (AutoProcessor) — Tokenizer cho Qwen2.5-VL.
  • text_encoder_2 (CLIPTextModel) — CLIP được đóng băng, cụ thể là biến thể clip-vit-large-patch14.
  • tokenizer_2 (CLIPTokenizer) — Tokenizer cho CLIP.
  • scheduler (FlowMatchEulerDiscreteScheduler) — Một scheduler được sử dụng kết hợp với transformer để khử nhiễu các latents ảnh đã được mã hóa.

Pipeline để tạo ảnh từ ảnh sử dụng Kandinsky 5.0.

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__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50guidance_scale: float = 3.5num_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds_qwen: typing.Optional[torch.Tensor] = Noneprompt_embeds_clip: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_qwen: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_clip: typing.Optional[torch.Tensor] = Noneprompt_cu_seqlens: typing.Optional[torch.Tensor] = Nonenegative_prompt_cu_seqlens: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 1024 ) → ~KandinskyImagePipelineOutput or tuple

Tham số

  • image (PipelineImageInput) — Hình ảnh đầu vào để điều kiện cho quá trình tạo. Phải là một hình ảnh, một danh sách các hình ảnh hoặc một torch.Tensor.
  • prompt (str hoặc list[str], tùy chọn) — Prompt hoặc các prompt để định hướng việc tạo ảnh. Nếu không được định nghĩa, hãy truyền prompt_embeds thay thế.
  • negative_prompt (str hoặc list[str], tùy chọn) — Prompt hoặc các prompt cần tránh trong quá trình tạo ảnh. Nếu không được định nghĩa, hãy truyền negative_prompt_embeds thay thế. Tham số này bị bỏ qua khi không sử dụng guidance (guidance_scale < 1).
  • height (int) — Chiều cao của hình ảnh được tạo ra, tính bằng pixel.
  • width (int) — Chiều rộng của hình ảnh được tạo ra, tính bằng pixel.
  • num_inference_steps (int, mặc định là 50) — Số bước khử nhiễu.
  • guidance_scale (float, mặc định là 5.0) — Thang độ dẫn hướng như được định nghĩa trong classifier-free guidance.
  • num_images_per_prompt (int, tùy chọn, mặc định là 1) — Số lượng hình ảnh cần tạo cho mỗi prompt.
  • generator (torch.Generator hoặc list[torch.Generator], tùy chọn) — Một torch generator để đảm bảo quá trình sinh ra là tất định.
  • latents (torch.Tensor, tùy chọn) — Các latents nhiễu đã được tạo trước.
  • prompt_embeds_qwen (torch.Tensor, tùy chọn) — Các embedding văn bản Qwen đã được tạo trước.
  • prompt_embeds_clip (torch.Tensor, tùy chọn) — Các embedding văn bản CLIP đã được tạo trước.
  • negative_prompt_embeds_qwen (torch.Tensor, tùy chọn) — Các embedding văn bản âm của Qwen đã được tạo trước.
  • negative_prompt_embeds_clip (torch.Tensor, tùy chọn) — Các embedding văn bản âm đã tạo trước của CLIP.
  • prompt_cu_seqlens (torch.Tensor, tùy chọn) — Độ dài chuỗi tích lũy đã tạo trước cho prompt dương của Qwen.
  • negative_prompt_cu_seqlens (torch.Tensor, tùy chọn) — Độ dài chuỗi tích lũy đã tạo trước cho Qwen negative prompt.
  • output_type (str, tùy chọn, mặc định là "pil") — Định dạng đầu ra của hình ảnh được tạo.
  • return_dict (bool, tùy chọn, mặc định là True) — Có nên trả về một KandinskyImagePipelineOutput hay không.
  • callback_on_step_end (Callable, PipelineCallback, MultiPipelineCallbacks, tùy chọn) — Một hàm được gọi vào cuối mỗi bước khử nhiễu.
  • callback_on_step_end_tensor_inputs (List, tùy chọn) — Danh sách các đầu vào tensor cho hàm callback_on_step_end.
  • max_sequence_length (int, mặc định là 1024) — Độ dài tối đa của chuỗi cho việc mã hóa văn bản và hình ảnh qwen. Phải nhỏ hơn 1024

Trả về

~KandinskyImagePipelineOutput hoặc tuple

Nếu return_dict là True, KandinskyImagePipelineOutput sẽ được trả về, ngược lại một tuple sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã được tạo.

Hàm gọi call của pipeline để tạo ảnh từ ảnh.

Ví dụ:

>>> import torch
>>> from diffusers import Kandinsky5I2IPipeline

>>> # Available models:
>>> # kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers
>>> # kandinskylab/Kandinsky-5.0-I2I-Lite-pretrain-Diffusers

>>> model_id = "kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers"
>>> pipe = Kandinsky5I2IPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen."

>>> output = pipe(
...     prompt=prompt,
...     negative_prompt="",
...     height=1024,
...     width=1024,
...     num_inference_steps=50,
...     guidance_scale=3.5,
... ).frames[0]

check_inputs

< >

( promptnegative_promptimageheightwidthprompt_embeds_qwen = Noneprompt_embeds_clip = Nonenegative_prompt_embeds_qwen = Nonenegative_prompt_embeds_clip = Noneprompt_cu_seqlens = Nonenegative_prompt_cu_seqlens = Nonecallback_on_step_end_tensor_inputs = Nonemax_sequence_length = None )

Tham số

  • prompt — Prompt đầu vào
  • negative_prompt — Prompt tiêu cực để điều hướng
  • image — Ảnh đầu vào để điều kiện
  • height — Chiều cao của ảnh
  • width — Chiều rộng của ảnh
  • prompt_embeds_qwen — Nhúng prompt Qwen đã tính trước
  • prompt_embeds_clip — Các embedding prompt CLIP đã được tính trước
  • negative_prompt_embeds_qwen — Các embedding âm của prompt Qwen đã được tính trước
  • negative_prompt_embeds_clip — Các embedding âm của prompt CLIP đã được tính trước
  • prompt_cu_seqlens — Độ dài chuỗi tích lũy đã tính trước cho prompt tích cực của Qwen
  • negative_prompt_cu_seqlens — Độ dài chuỗi tích lũy đã tính trước cho prompt âm của Qwen
  • callback_on_step_end_tensor_inputs — Đầu vào tensor của callback

Gây ra

ValueError

  • ValueError — Nếu các đầu vào không hợp lệ

Xác thực các tham số đầu vào cho pipeline.

encode_prompt

< >

( prompt: str | list[str]image: Tensornum_images_per_prompt: int = 1max_sequence_length: int = 1024device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None ) → tuple[torch.Tensor, torch.Tensor, torch.Tensor]

Tham số

  • prompt (str hoặc list[str]) — Prompt cần được mã hóa.
  • num_images_per_prompt (int, tùy chọn, mặc định là 1) — Số lượng hình ảnh cần tạo cho mỗi prompt.
  • max_sequence_length (int, tùy chọn, mặc định là 1024) — Độ dài tối đa của chuỗi cho việc mã hóa văn bản. Phải nhỏ hơn 1024
  • device (torch.device, tùy chọn) — Thiết bị Torch.
  • dtype (torch.dtype, tùy chọn) — Dtype của Torch.

Trả về

tuple[torch.Tensor, torch.Tensor, torch.Tensor]

  • Qwen text embeddings có shape (batch_size * num_images_per_prompt, sequence_length, embedding_dim)
  • CLIP pooled embeddings có shape (batch_size * num_images_per_prompt, clip_embedding_dim)
  • Chiều dài chuỗi tích lũy (cu_seqlens) cho Qwen embeddings có shape (batch_size * num_images_per_prompt + 1,)

Mã hóa một prompt duy nhất (tích cực hoặc tiêu cực) thành các trạng thái ẩn của text encoder.

Phương pháp này kết hợp các embedding từ cả hai bộ mã hóa văn bản Qwen2.5-VL và CLIP để tạo ra các biểu diễn văn bản toàn diện cho việc tạo hình ảnh.

prepare_latents

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]batch_size: intnum_channels_latents: int = 16height: int = 1024width: int = 1024dtype: typing.Optional[torch.dtype] = Nonedevice: typing.Optional[torch.device] = Nonegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = None ) → torch.Tensor

Tham số

  • image (PipelineImageInput) — Ảnh đầu vào để điều kiện hóa quá trình tạo
  • batch_size (int) — Số lượng ảnh cần tạo
  • num_channels_latents (int) — Số kênh trong không gian ẩn
  • height (int) — Chiều cao của hình ảnh được tạo
  • width (int) — Độ rộng của hình ảnh được tạo
  • dtype (torch.dtype) — Kiểu dữ liệu cho latents
  • device (torch.device) — Thiết bị để tạo latents
  • generator (torch.Generator) — Bộ tạo số ngẫu nhiên
  • latents (torch.Tensor) — Các latents có sẵn để sử dụng

Trả về

torch.Tensor

Tensor latent đã chuẩn bị với ảnh được mã hóa

Chuẩn bị các biến tiềm ẩn ban đầu cho việc tạo ảnh từ ảnh.

Phương pháp này tạo ra các latent nhiễu ngẫu nhiên với ảnh đã được mã hóa,

Trích dẫn

@misc{kandinsky2025,
    author = {Alexander Belykh and Alexander Varlamov and Alexey Letunovskiy and Anastasia Aliaskina and Anastasia Maltseva and Anastasiia Kargapoltseva and Andrey Shutkin and Anna Averchenkova and Anna Dmitrienko and Bulat Akhmatov and Denis Dimitrov and Denis Koposov and Denis Parkhomenko and Dmitrii and Ilya Vasiliev and Ivan Kirillov and Julia Agafonova and Kirill Chernyshev and Kormilitsyn Semen and Lev Novitskiy and Maria Kovaleva and Mikhail Mamaev and Mikhailov and Nikita Kiselev and Nikita Osterov and Nikolai Gerasimenko and Nikolai Vaulin and Olga Kim and Olga Vdovchenko and Polina Gavrilova and Polina Mikhailova and Tatiana Nikulina and Viacheslav Vasilev and Vladimir Arkhipkin and Vladimir Korviakov and Vladimir Polovnikov and Yury Kolabushin},
    title = {Kandinsky 5.0: A family of diffusion models for Video & Image generation},
    howpublished = {\url{https://github.com/kandinskylab/Kandinsky-5}},
    year = 2025
}
Update on GitHub