# Kandinsky 5.0 Image

[Kandinsky 5.0](https://arxiv.org/abs/2511.14993)は、動画および画像の生成のための拡散モデルのファミリーです。

Kandinsky 5.0 Image Lite は軽量な画像生成モデル(6B パラメータ)です。

このモデルには、いくつかの重要な革新が導入されています。
- **潜在拡散パイプライン**と**Flow Matching**による訓練安定性の向上
- **Diffusion Transformer (DiT)**を主要な生成バックボーンとし、テキスト埋め込みへのクロスアテンションを使用
- **Qwen2.5-VL**と**CLIP**を用いたデュアルテキストエンコーディングによる包括的なテキスト理解
- 効率的な画像エンコードとデコードのための**Flux VAE**

元のコードベースは[kandinskylab/Kandinsky-5](https://github.com/kandinskylab/Kandinsky-5)で確認できます。

> [!TIP]
> テキストから動画への変換用の公式モデルチェックポイント（事前学習済み、SFT、no-CFG、蒸留済みバリアントを含む）については、Hub上の[Kandinsky Lab](https://huggingface.co/kandinskylab)組織を確認してください。

## 利用可能なモデル

Kandinsky 5.0 Image Lite:

| model_id | 説明 | ユースケース |
|------------|-------------|-----------|
| [**kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers**](https://huggingface.co/kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers) | 6B画像のSupervised Fine-Tunedモデル | 最高品質の生成 |
| [**kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers**](https://huggingface.co/kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers) | 6B画像編集用のSupervised Fine-Tunedモデル | 最高品質の生成 |
| [**kandinskylab/Kandinsky-5.0-T2I-Lite-pretrain-Diffusers**](https://huggingface.co/kandinskylab/Kandinsky-5.0-T2I-Lite-pretrain-Diffusers) | 6B画像ベース事前学習モデル | 研究とファインチューニング |
| [**kandinskylab/Kandinsky-5.0-I2I-Lite-pretrain-Diffusers**](https://huggingface.co/kandinskylab/Kandinsky-5.0-I2I-Lite-pretrain-Diffusers) | 6B画像編集ベース事前学習モデル | 研究とファインチューニング |

## 使用例

### 基本的なテキストから画像への生成

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

### 基本的なImage-to-Image生成

```python
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[[diffusers.Kandinsky5T2IPipeline]]

#### diffusers.Kandinsky5T2IPipeline[[diffusers.Kandinsky5T2IPipeline]]

```python
diffusers.Kandinsky5T2IPipeline(transformer: Kandinsky5Transformer3DModel, vae: AutoencoderKL, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2VLProcessor, text_encoder_2: CLIPTextModel, tokenizer_2: CLIPTokenizer, scheduler: FlowMatchEulerDiscreteScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_t2i.py#L120)

**パラメータ:**

transformer (`Kandinsky5Transformer3DModel`) : エンコードされた画像の潜在変数をデノイズするための条件付き Transformer。

vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 潜在表現へのエンコードとデコードを行う、[black-forest-labs/FLUX.1-dev (vae)](https://huggingface.co/black-forest-labs/FLUX.1-dev) の Variational Auto-Encoder モデル

text_encoder (`Qwen2_5_VLForConditionalGeneration`) : 凍結されたテキストエンコーダー [Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)。

tokenizer (`AutoProcessor`) : Qwen2.5-VL用のTokenizer。

text_encoder_2 (`CLIPTextModel`) : 凍結された[CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel)、具体的には[clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)バリアントです。

tokenizer_2 (`CLIPTokenizer`) : CLIP用のTokenizer。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。

Kandinsky 5.0 を使用したテキストから画像を生成するための Pipeline。

このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。すべてのパイプラインに実装されている汎用的なメソッド（ダウンロード、保存、特定のデバイスでの実行など）については、スーパークラスのドキュメントを参照してください。

#### __call__[[diffusers.Kandinsky5T2IPipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 1024, width: int = 1024, num_inference_steps: int = 50, guidance_scale: float = 3.5, num_images_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds_qwen: typing.Optional[torch.Tensor] = None, prompt_embeds_clip: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_qwen: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_clip: typing.Optional[torch.Tensor] = None, prompt_cu_seqlens: typing.Optional[torch.Tensor] = None, negative_prompt_cu_seqlens: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = None, callback_on_step_end_tensor_inputs: list = ['latents'], max_sequence_length: int = 512)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_t2i.py#L534)

**パラメータ:**

prompt (`str` または `list[str]`、*任意*) : 画像生成をガイドするためのプロンプトまたはプロンプトのリストです。定義されていない場合は、代わりに `prompt_embeds` を渡してください。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成時に回避するプロンプトです。未定義の場合は、代わりに `negative_prompt_embeds` を渡してください。guidance を使用していない場合（`guidance_scale` < `1`）は無視されます。

height (`int`、デフォルトは`1024`) : 生成される画像のピクセル単位の縦幅。

width (`int`、デフォルトは`1024`) : 生成される画像の幅（ピクセル単位）。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数。

guidance_scale (`float`、デフォルトは`5.0`) : classifier-free guidance で定義されるガイダンススケール。

num_images_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための torch ジェネレーター。

latents (`torch.Tensor`, *任意*) : 事前生成されたノイズ付き潜在変数。

prompt_embeds_qwen (`torch.Tensor`, *任意*) : 事前生成済みの Qwen テキスト埋め込み。

prompt_embeds_clip (`torch.Tensor`, *任意*) : 事前に生成された CLIP テキスト埋め込み。

negative_prompt_embeds_qwen (`torch.Tensor`, *任意*) : 事前に生成された Qwen のネガティブテキスト埋め込み。

negative_prompt_embeds_clip (`torch.Tensor`, *任意*) : 事前に生成された CLIP のネガティブテキスト埋め込み。

prompt_cu_seqlens (`torch.Tensor`, *任意*) : Qwen の正プロンプト用の事前生成済み累積シーケンス長。

negative_prompt_cu_seqlens (`torch.Tensor`, *任意*) : Qwen のネガティブプロンプト用の事前生成済み累積シーケンス長。

output_type (`str`、*任意*、デフォルトは`"pil"`) : 生成された画像の出力形式。

return_dict (`bool`、*任意*、デフォルトは`True`) : `KandinskyImagePipelineOutput`を返すかどうかを指定します。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*省略可*) : 各デノイジングステップの終了時に呼び出される関数。

callback_on_step_end_tensor_inputs (`List`, *任意*) : `callback_on_step_end` 関数へのテンソル入力のリスト。

max_sequence_length (`int`、デフォルトは`512`) : テキストエンコードにおける最大シーケンス長です。

**戻り値:** `~KandinskyImagePipelineOutput` または `tuple`

`return_dict` が `True` の場合、`KandinskyImagePipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリストである `tuple` が返されます。

テキストから画像を生成するための pipeline の呼び出し関数。

例:

```python
>>> 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[[diffusers.Kandinsky5T2IPipeline.check_inputs]]

```python
check_inputs(prompt, negative_prompt, height, width, prompt_embeds_qwen = None, prompt_embeds_clip = None, negative_prompt_embeds_qwen = None, negative_prompt_embeds_clip = None, prompt_cu_seqlens = None, negative_prompt_cu_seqlens = None, callback_on_step_end_tensor_inputs = None, max_sequence_length = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_t2i.py#L380)

**パラメータ:**

prompt : 入力プロンプト

negative_prompt : ガイダンス用のネガティブプロンプト

height : 画像の高さ

width : 画像の幅

prompt_embeds_qwen : 事前計算済みの Qwen プロンプト埋め込み

prompt_embeds_clip : 事前計算済みのCLIPプロンプト埋め込み

negative_prompt_embeds_qwen : 事前計算済みの Qwen 負プロンプト埋め込み

negative_prompt_embeds_clip : 事前計算済みの CLIP 負プロンプト埋め込み

prompt_cu_seqlens : Qwenの正のプロンプト用の事前計算済み累積シーケンス長

negative_prompt_cu_seqlens : Qwenのネガティブプロンプト用の事前計算済み累積シーケンス長

callback_on_step_end_tensor_inputs : コールバックのテンソル入力

**例外:** ``ValueError``

- ``ValueError`` -- 入力が無効な場合

パイプラインの入力パラメータを検証します。

#### encode_prompt[[diffusers.Kandinsky5T2IPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], num_images_per_prompt: int = 1, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_t2i.py#L289)

**パラメータ:**

prompt (`str` または `list[str]`) : エンコードするプロンプト。

num_images_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

max_sequence_length (`int`、*optional*、デフォルトは 512) : テキストエンコードの最大シーケンス長。1024 未満である必要があります

device (`torch.device`、*任意*) : Torch デバイス。

dtype (`torch.dtype`、*任意*) : Torch の dtype。

**戻り値:** tuple[torch.Tensor, torch.Tensor, torch.Tensor]

- 形状が (batch_size * num_images_per_prompt, sequence_length, embedding_dim) の Qwen テキスト埋め込み
- 形状が (batch_size * num_images_per_prompt, clip_embedding_dim) の CLIP のプーリング済み埋め込み
- Qwen の埋め込みにおける累積シーケンス長（`cu_seqlens`）で、形状は (batch_size * num_images_per_prompt + 1,) です

単一のプロンプト（正または負）をテキストエンコーダーの隠れ状態にエンコードします。

このメソッドは、Qwen2.5-VLとCLIPのテキストエンコーダーの埋め込みを組み合わせることで、画像生成のための包括的なテキスト表現を作成します。

#### prepare_latents[[diffusers.Kandinsky5T2IPipeline.prepare_latents]]

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

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_t2i.py#L469)

**パラメータ:**

batch_size (int) : 生成する画像の数

num_channels_latents (int) : 潜在空間のチャネル数

height (int) : 生成画像の高さ

width (int) : 生成される画像の幅

dtype (torch.dtype) : 潜在変数のデータ型

device (torch.device) : 潜在変数を作成するデバイス

generator (torch.Generator) : 乱数生成器

latents (torch.Tensor) : 使用する既存の潜在変数

**戻り値:** `torch.Tensor`

準備済みの潜在テンソル

テキストから画像を生成するための初期潜在変数を準備します。

このメソッドは、ランダムなノイズの潜在変数を作成します

## Kandinsky5I2IPipeline[[diffusers.Kandinsky5I2IPipeline]]

#### diffusers.Kandinsky5I2IPipeline[[diffusers.Kandinsky5I2IPipeline]]

```python
diffusers.Kandinsky5I2IPipeline(transformer: Kandinsky5Transformer3DModel, vae: AutoencoderKL, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2VLProcessor, text_encoder_2: CLIPTextModel, tokenizer_2: CLIPTokenizer, scheduler: FlowMatchEulerDiscreteScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2i.py#L120)

**パラメータ:**

transformer (`Kandinsky5Transformer3DModel`) : エンコードされた画像の潜在変数をデノイズするための条件付き Transformer。

vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 潜在表現へのエンコードとデコードを行う、[black-forest-labs/FLUX.1-dev (vae)](https://huggingface.co/black-forest-labs/FLUX.1-dev) の Variational Auto-Encoder モデル

text_encoder (`Qwen2_5_VLForConditionalGeneration`) : 凍結されたテキストエンコーダー [Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)。

tokenizer (`AutoProcessor`) : Qwen2.5-VL用のTokenizer。

text_encoder_2 (`CLIPTextModel`) : 凍結された[CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel)、具体的には[clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)バリアントです。

tokenizer_2 (`CLIPTokenizer`) : CLIP用のTokenizer。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。

Kandinsky 5.0 を使用した画像から画像への生成を行う Pipeline。

このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。すべてのパイプラインに実装されている汎用的なメソッド（ダウンロード、保存、特定のデバイスでの実行など）については、スーパークラスのドキュメントを参照してください。

#### __call__[[diffusers.Kandinsky5I2IPipeline.__call__]]

```python
__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] = None, negative_prompt: str | list[str] | None = None, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, guidance_scale: float = 3.5, num_images_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds_qwen: typing.Optional[torch.Tensor] = None, prompt_embeds_clip: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_qwen: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_clip: typing.Optional[torch.Tensor] = None, prompt_cu_seqlens: typing.Optional[torch.Tensor] = None, negative_prompt_cu_seqlens: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = None, callback_on_step_end_tensor_inputs: list = ['latents'], max_sequence_length: int = 1024)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2i.py#L567)

**パラメータ:**

image (`PipelineImageInput`) : 生成を条件づけるための入力画像。画像、画像のリスト、または`torch.Tensor`である必要があります。

prompt (`str` または `list[str]`、*任意*) : 画像生成をガイドするためのプロンプトまたはプロンプトのリストです。定義されていない場合は、代わりに `prompt_embeds` を渡してください。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成時に回避するプロンプトです。未定義の場合は、代わりに `negative_prompt_embeds` を渡してください。guidance を使用していない場合（`guidance_scale` < `1`）は無視されます。

height (`int`) : 生成される画像のピクセル単位の縦幅。

width (`int`) : 生成される画像の幅（ピクセル単位）。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数。

guidance_scale (`float`、デフォルトは`5.0`) : classifier-free guidance で定義されるガイダンススケール。

num_images_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための torch ジェネレーター。

latents (`torch.Tensor`, *任意*) : 事前生成されたノイズ付き潜在変数。

prompt_embeds_qwen (`torch.Tensor`, *任意*) : 事前生成済みの Qwen テキスト埋め込み。

prompt_embeds_clip (`torch.Tensor`, *任意*) : 事前に生成された CLIP テキスト埋め込み。

negative_prompt_embeds_qwen (`torch.Tensor`, *任意*) : 事前に生成された Qwen のネガティブテキスト埋め込み。

negative_prompt_embeds_clip (`torch.Tensor`, *任意*) : 事前に生成された CLIP のネガティブテキスト埋め込み。

prompt_cu_seqlens (`torch.Tensor`, *任意*) : Qwen の正プロンプト用の事前生成済み累積シーケンス長。

negative_prompt_cu_seqlens (`torch.Tensor`, *任意*) : Qwen のネガティブプロンプト用の事前生成済み累積シーケンス長。

output_type (`str`、*任意*、デフォルトは`"pil"`) : 生成された画像の出力形式。

return_dict (`bool`、*任意*、デフォルトは`True`) : `KandinskyImagePipelineOutput`を返すかどうかを指定します。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*省略可*) : 各デノイジングステップの終了時に呼び出される関数。

callback_on_step_end_tensor_inputs (`List`, *任意*) : `callback_on_step_end` 関数へのテンソル入力のリスト。

max_sequence_length (`int`、デフォルトは`1024`) : テキストおよび画像のqwenエンコーディングにおける最大シーケンス長。1024未満である必要があります

**戻り値:** `~KandinskyImagePipelineOutput` または `tuple`

`return_dict` が `True` の場合、`KandinskyImagePipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリストである `tuple` が返されます。

画像から画像への生成を行う pipeline の呼び出し関数です。

例:

```python
>>> 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[[diffusers.Kandinsky5I2IPipeline.check_inputs]]

```python
check_inputs(prompt, negative_prompt, image, height, width, prompt_embeds_qwen = None, prompt_embeds_clip = None, negative_prompt_embeds_qwen = None, negative_prompt_embeds_clip = None, prompt_cu_seqlens = None, negative_prompt_cu_seqlens = None, callback_on_step_end_tensor_inputs = None, max_sequence_length = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2i.py#L388)

**パラメータ:**

prompt : 入力プロンプト

negative_prompt : ガイダンス用のネガティブプロンプト

image : 条件付け用の入力画像

height : 画像の高さ

width : 画像の幅

prompt_embeds_qwen : 事前計算済みの Qwen プロンプト埋め込み

prompt_embeds_clip : 事前計算済みのCLIPプロンプト埋め込み

negative_prompt_embeds_qwen : 事前計算済みの Qwen 負プロンプト埋め込み

negative_prompt_embeds_clip : 事前計算済みの CLIP 負プロンプト埋め込み

prompt_cu_seqlens : Qwenの正のプロンプト用の事前計算済み累積シーケンス長

negative_prompt_cu_seqlens : Qwenのネガティブプロンプト用の事前計算済み累積シーケンス長

callback_on_step_end_tensor_inputs : コールバックのテンソル入力

**例外:** ``ValueError``

- ``ValueError`` -- 入力が無効な場合

パイプラインの入力パラメータを検証します。

#### encode_prompt[[diffusers.Kandinsky5I2IPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], image: Tensor, num_images_per_prompt: int = 1, max_sequence_length: int = 1024, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2i.py#L295)

**パラメータ:**

prompt (`str` または `list[str]`) : エンコードするプロンプト。

num_images_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

max_sequence_length (`int`、*optional*、デフォルトは 1024) : テキストエンコードの最大シーケンス長。1024 未満である必要があります

device (`torch.device`、*任意*) : Torch デバイス。

dtype (`torch.dtype`、*任意*) : Torch の dtype。

**戻り値:** tuple[torch.Tensor, torch.Tensor, torch.Tensor]

- 形状が (batch_size * num_images_per_prompt, sequence_length, embedding_dim) の Qwen テキスト埋め込み
- 形状が (batch_size * num_images_per_prompt, clip_embedding_dim) の CLIP のプーリング済み埋め込み
- Qwen の埋め込みにおける累積シーケンス長（`cu_seqlens`）で、形状は (batch_size * num_images_per_prompt + 1,) です

単一のプロンプト（正または負）をテキストエンコーダーの隠れ状態にエンコードします。

このメソッドは、Qwen2.5-VLとCLIPのテキストエンコーダーの埋め込みを組み合わせることで、画像生成のための包括的なテキスト表現を作成します。

#### prepare_latents[[diffusers.Kandinsky5I2IPipeline.prepare_latents]]

```python
prepare_latents(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], batch_size: int, num_channels_latents: int = 16, height: int = 1024, width: int = 1024, dtype: typing.Optional[torch.dtype] = None, device: typing.Optional[torch.device] = None, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2i.py#L482)

**パラメータ:**

image (PipelineImageInput) : 生成を条件付けするための入力画像

batch_size (int) : 生成する画像の数

num_channels_latents (int) : 潜在空間のチャネル数

height (int) : 生成画像の高さ

width (int) : 生成される画像の幅

dtype (torch.dtype) : 潜在変数のデータ型

device (torch.device) : 潜在変数を作成するデバイス

generator (torch.Generator) : 乱数生成器

latents (torch.Tensor) : 使用する既存の潜在変数

**戻り値:** `torch.Tensor`

エンコードされた画像を含む準備済みの潜在テンソル

画像から画像への生成のために、初期の潜在変数を準備します。

このメソッドは、エンコードされた画像付きのランダムなノイズ潜在変数を作成します。

## 引用
```bibtex
@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
}
```

