# Kandinsky 5.0 Video

[Kandinsky 5.0](https://arxiv.org/abs/2511.14993) هي عائلة من نماذج الانتشار لتوليد الفيديو والصور.

تشكيلة Kandinsky 5.0 Lite من نماذج توليد الفيديو خفيفة الوزن (2 مليار معامل) التي تحتل المرتبة الأولى بين النماذج مفتوحة المصدر في فئتها. تتفوق على النماذج الأكبر حجمًا وتوفر أفضل فهم للمفاهيم الروسية في منظومة المصادر المفتوحة.

تشكيلة Kandinsky 5.0 Pro من نماذج توليد الفيديو الكبيرة عالية الجودة (19 مليار معامل). توفر توليدًا عالي الجودة بدقة HD بالإضافة إلى صيغ توليد أخرى مثل I2V.

يُقدّم النموذج عدة ابتكارات رئيسية:
- **خط أنابيب الانتشار الكامن** مع **Flow Matching** لتحسين استقرار التدريب
- **Diffusion Transformer (DiT)** كعمود فقري توليدي رئيسي مع انتباه متقاطع إلى تمثيلات النص
- ترميز نصي مزدوج باستخدام **Qwen2.5-VL** و **CLIP** لفهم شامل للنص
- **HunyuanVideo 3D VAE** لتشفير وفك ترميز الفيديو بكفاءة
- **آليات الانتباه المتناثر** (NABLA) لمعالجة التسلسلات الطويلة بكفاءة

يمكن العثور على قاعدة الكود الأصلية في [kandinskylab/Kandinsky-5](https://github.com/kandinskylab/Kandinsky-5).

> [!TIP]
> اطّلع على منظمة [Kandinsky Lab](https://huggingface.co/kandinskylab) على Hub للحصول على نقاط التفتيش الرسمية للنماذج لتوليد الفيديو من النص، بما في ذلك النماذج المُسبقة التدريب، ونماذج SFT، ونماذج no-CFG، والنماذج المُقطّرة.

## النماذج المتاحة

Kandinsky 5.0 T2V Pro:

| model_id | الوصف | حالات الاستخدام |
|------------|-------------|-----------|
| **kandinskylab/Kandinsky-5.0-T2V-Pro-sft-5s-Diffusers** | نموذج Text-to-Video Pro لمدة 5 ثوانٍ | توليد فيديو من نص عالي الجودة |
| **kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers** | نموذج Pro لتحويل الصور إلى فيديو في 5 ثوانٍ | توليد فيديو من صورة بجودة عالية |

Kandinsky 5.0 T2V Lite:
| model_id | الوصف | حالات الاستخدام |
|------------|-------------|-----------|
| **kandinskylab/Kandinsky-5.0-T2V-Lite-sft-5s-Diffusers** | نموذج مُدرب بإشراف خلال 5 ثوانٍ | أعلى جودة توليد |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-sft-10s-Diffusers** | نموذج مُدرب بإشراف خلال 10 ثوانٍ | أعلى جودة توليد |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-nocfg-5s-Diffusers** | 5 second Classifier-Free Guidance مُقطّر | استدلال أسرع مرتين |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-nocfg-10s-Diffusers** | 10 ثوانٍ من التوجيه الحر من التصنيف | استدلال أسرع مرتين |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-5s-Diffusers** | نموذج Diffusion بخمس ثوانٍ مُقطّر إلى 16 خطوة | استدلال أسرع 6 مرات، مع فقدان جودة ضئيل |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-10s-Diffusers** | نموذج Diffusion مُصغَّر إلى 16 خطوة في 10 ثوانٍ | استدلال أسرع 6 مرات، مع فقدان جودة ضئيل |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-pretrain-5s-Diffusers** | نموذج Base المُدرَّب مسبقًا في 5 ثوانٍ | البحث وضبط الدقة |
| **kandinskylab/Kandinsky-5.0-T2V-Lite-pretrain-10s-Diffusers** | نموذج Base المُدرَّب مسبقًا في 10 ثوانٍ | البحث وضبط الدقة |

## أمثلة على الاستخدام

### توليد النص إلى الفيديو الأساسي

#### احترافي
**⚠️ تحذير!** يجب استنتاج جميع نماذج Pro باستخدام pipeline.enable_model_cpu_offload()
```python
import torch
from diffusers import Kandinsky5T2VPipeline
from diffusers.utils import export_to_video

# Load the pipeline
model_id = "kandinskylab/Kandinsky-5.0-T2V-Pro-sft-5s-Diffusers"
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)

pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"
pipeline.transformer.set_attention_backend("flex")                            # <--- Set attention backend to Flex
pipeline.enable_model_cpu_offload()                                           # <--- Enable cpu offloading for single GPU inference
pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs

# Generate video
prompt = "A cat and a dog baking a cake together in a kitchen."
negative_prompt = "Static, 2D cartoon, cartoon, 2d animation, paintings, images, worst quality, low quality, ugly, deformed, walking backwards"

output = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=768,
    width=1024,
    num_frames=121,  # ~5 seconds at 24fps
    num_inference_steps=50,
    guidance_scale=5.0,
).frames[0]

export_to_video(output, "output.mp4", fps=24, quality=9)
```

#### خفيفة
```python
import torch
from diffusers import Kandinsky5T2VPipeline
from diffusers.utils import export_to_video

# Load the pipeline
model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-sft-5s-Diffusers"
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

# Generate video
prompt = "A cat and a dog baking a cake together in a kitchen."
negative_prompt = "Static, 2D cartoon, cartoon, 2d animation, paintings, images, worst quality, low quality, ugly, deformed, walking backwards"

output = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=512,
    width=768,
    num_frames=121,  # ~5 seconds at 24fps
    num_inference_steps=50,
    guidance_scale=5.0,
).frames[0]

export_to_video(output, "output.mp4", fps=24, quality=9)
```

### نماذج في 10 ثوانٍ
**⚠️ تحذير!** يجب استخدام جميع النماذج المدة 10 ثوانٍ مع Flex attention وتجميع max-autotune-no-cudagraphs:

```python
pipe = Kandinsky5T2VPipeline.from_pretrained(
    "kandinskylab/Kandinsky-5.0-T2V-Lite-sft-10s-Diffusers", 
    dtype=torch.bfloat16
)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

pipe.transformer.set_attention_backend(
    "flex"
)                                       # <--- Set attention backend to Flex
pipe.transformer.compile(
    mode="max-autotune-no-cudagraphs", 
    dynamic=True
)                                       # <--- Compile with max-autotune-no-cudagraphs

prompt = "A cat and a dog baking a cake together in a kitchen."
negative_prompt = "Static, 2D cartoon, cartoon, 2d animation, paintings, images, worst quality, low quality, ugly, deformed, walking backwards"

output = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=512,
    width=768,
    num_frames=241,
    num_inference_steps=50,
    guidance_scale=5.0,
).frames[0]

export_to_video(output, "output.mp4", fps=24, quality=9)
```

### نموذج التوليف المُقطّر
**⚠️ تحذير!** يجب استنتاج جميع نماذج nocfg والنماذج المُقطّرة للانتشار دون CFG (```guidance_scale=1.0```):

```python
model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-5s-Diffusers"
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

output = pipe(
    prompt="A beautiful sunset over mountains",
    num_inference_steps=16,  # <--- Model is distilled in 16 steps
    guidance_scale=1.0,      # <--- no CFG
).frames[0]

export_to_video(output, "output.mp4", fps=24, quality=9)
```

### توليد الفيديو من الصورة الأساسي
**⚠️ تحذير!** يجب استنتاج جميع نماذج Pro باستخدام pipeline.enable_model_cpu_offload()
```python
import torch
from diffusers import Kandinsky5T2VPipeline
from diffusers.utils import export_to_video

# Load the pipeline
model_id = "kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers"
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)

pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"
pipeline.transformer.set_attention_backend("flex")                            # <--- Set attention backend to Flex
pipeline.enable_model_cpu_offload()                                           # <--- Enable cpu offloading for single GPU inference
pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs

# Generate video
image = load_image(
    "https://huggingface.co/kandinsky-community/kandinsky-3/resolve/main/assets/title.jpg?download=true"
)
height = 896
width = 896
image = image.resize((width, height))

prompt = "An funny furry creture smiles happily and holds a sign that says 'Kandinsky'"
negative_prompt = ""

output = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=height,
    width=width,
    num_frames=121,  # ~5 seconds at 24fps
    num_inference_steps=50,
    guidance_scale=5.0,
).frames[0]

export_to_video(output, "output.mp4", fps=24, quality=9)
```

## Kandinsky 5.0 Pro التقييم جنبًا إلى جنب

  
      
          
      
      
         
      

  
      
          المقارنة مع Veo 3
      
      
          المقارنة مع Veo 3 fast
      
  
      
          
      
      
          
      
  
      
          مقارنة مع وضع تحويل النص إلى فيديو في Wan 2.2 A14B
      
      
          المقارنة مع وضع تحويل الصورة إلى فيديو في Wan 2.2 A14B
      

## Kandinsky 5.0 Lite تقييم جنبًا إلى جنب

تستند التقييم إلى الأوامر الموسّعة من [Movie Gen benchmark](https://github.com/facebookresearch/MovieGenBench)، وهي متاحة في عمود expanded_prompt في الملف benchmark/moviegen_bench.csv.

  
      
          
      
      
          
      
  
      
          
      
      
          
      
  
      
          
      

## Kandinsky 5.0 Lite Distill تقييم جنبًا إلى جنب

  
      
          
      
      
          
      

## Kandinsky5T2VPipeline[[diffusers.Kandinsky5T2VPipeline]]

#### diffusers.Kandinsky5T2VPipeline[[diffusers.Kandinsky5T2VPipeline]]

```python
diffusers.Kandinsky5T2VPipeline(transformer: Kandinsky5Transformer3DModel, vae: AutoencoderKLHunyuanVideo, 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.py#L131)

**المعاملات:**

transformer (`Kandinsky5Transformer3DModel`) : نموذج Transformer مشروط لإزالة الضوضاء من كامنات الفيديو المُرمّزة.

vae ([AutoencoderKLHunyuanVideo](/docs/diffusers/main/ar/api/models/autoencoder_kl_hunyuan_video#diffusers.AutoencoderKLHunyuanVideo)) : نموذج الترميز التحويلي التبايني [hunyuanvideo-community/HunyuanVideo (vae)](https://huggingface.co/hunyuanvideo-community/HunyuanVideo) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

text_encoder (`Qwen2_5_VLForConditionalGeneration`) : مُشفِّر نص ثابت [Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct).

tokenizer (`AutoProcessor`) : مُجزِّئ (Tokenizer) لـ Qwen2.5-VL.

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`) : مُقسِّم (Tokenizer) خاص بنموذج CLIP.

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ar/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : مُجدوِل يُستخدم بالاقتران مع `transformer` لإزالة الضوضاء من كامنات الفيديو المُرمَّزة.

خط أنابيب لتوليد الفيديو من النص باستخدام Kandinsky 5.0.

يرث هذا النموذج من [DiffusionPipeline](/docs/diffusers/main/ar/api/pipelines/overview#diffusers.DiffusionPipeline). راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

#### __call__[[diffusers.Kandinsky5T2VPipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 512, width: int = 768, num_frames: int = 121, num_inference_steps: int = 50, guidance_scale: float = 5.0, num_videos_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.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = 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.py#L680)

**المعاملات:**

prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الفيديو. إذا لم تُعرَّف، فمرّر `prompt_embeds` بدلاً من ذلك.

negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي يجب تجنبها أثناء توليد الفيديو. إذا لم يُعرَّف، فمرّر `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (`guidance_scale` < `1`).

height (`int`، القيمة الافتراضية `512`) : ارتفاع الفيديو المولّد بالبكسلات.

width (`int`، القيمة الافتراضية `768`) : عرض الفيديو المولّد بالبكسل.

num_frames (`int`، القيمة الافتراضية `25`) : عدد الإطارات في الفيديو المولّد.

num_inference_steps (`int`، القيمة الافتراضية `50`) : عدد خطوات إزالة الضوضاء.

guidance_scale (`float`، القيمة الافتراضية `5.0`) : مقياس التوجيه كما هو مُعرَّف في التوجيه الحر من التصنيف.

num_videos_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`) : ما إذا كان يجب إرجاع `KandinskyPipelineOutput` أم لا.

callback_on_step_end (`Callable`، `PipelineCallback`، `MultiPipelineCallbacks`، *اختياري*) : دالة تُستدعى في نهاية كل خطوة إزالة ضوضاء.

callback_on_step_end_tensor_inputs (`list`، *اختياري*) : قائمة مدخلات المصفوفات (tensors) لدالة `callback_on_step_end`.

max_sequence_length (`int`، القيمة الافتراضية `512`) : الحد الأقصى لطول التسلسل لتشفير النص.

**يعيد:** `~KandinskyPipelineOutput` أو `tuple`

إذا كان `return_dict` هو `True`، يُعاد `KandinskyPipelineOutput`، وإلا يُعاد `tuple` يكون عنصره الأول قائمة بالصور المولّدة.

دالة الاستدعاء call لخط الأنابيب pipeline الخاص بالتوليد.

أمثلة:

```python
>>> import torch
>>> from diffusers import Kandinsky5T2VPipeline
>>> from diffusers.utils import export_to_video

>>> # Available models:
>>> # kandinskylab/Kandinsky-5.0-T2V-Pro-sft-5s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-sft-5s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-nocfg-5s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-5s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-pretrain-5s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-sft-10s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-nocfg-10s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-10s-Diffusers
>>> # kandinskylab/Kandinsky-5.0-T2V-Lite-pretrain-10s-Diffusers

>>> model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-sft-5s-Diffusers"
>>> pipe = Kandinsky5T2VPipeline.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."
>>> negative_prompt = "Static, 2D cartoon, cartoon, 2d animation, paintings, images, worst quality, low quality, ugly, deformed, walking backwards"

>>> output = pipe(
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=512,
...     width=768,
...     num_frames=121,
...     num_inference_steps=50,
...     guidance_scale=5.0,
... ).frames[0]

>>> export_to_video(output, "output.mp4", fps=24, quality=9)
```

#### check_inputs[[diffusers.Kandinsky5T2VPipeline.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.py#L511)

**المعاملات:**

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.Kandinsky5T2VPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], num_videos_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.py#L418)

**المعاملات:**

prompt (`str` أو `list[str]`) : الأمر الذي سيتم ترميزه.

num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد مقاطع الفيديو التي سيتم توليدها لكل موجه.

max_sequence_length (`int`، *اختياري*، القيمة الافتراضية 512) : الحد الأقصى لطول التسلسل لتشفير النص.

device (`torch.device`، *اختياري*) : جهاز Torch.

dtype (`torch.dtype`، *اختياري*) : نوع Torch.

**يعيد:** tuple[torch.Tensor, torch.Tensor, torch.Tensor]

- تضمينات نص Qwen ذات الشكل (batch_size * num_videos_per_prompt, sequence_length, embedding_dim)
- تضمينات CLIP المجمّعة ذات الشكل (batch_size * num_videos_per_prompt, clip_embedding_dim)
- الطول التراكمي للتسلسلات (`cu_seqlens`) لتضمينات Qwen من الشكل (batch_size * num_videos_per_prompt + 1,)

يقوم بتشفير موجه واحد (إيجابي أو سلبي) إلى حالات مخفية لمشفّر النص.

تجمع هذه الطريقة بين التضمينات (embeddings) المستخرجة من كلا مشفري النصوص Qwen2.5-VL وCLIP لإنشاء تمثيلات نصية شاملة لتوليد الفيديو.

#### fast_sta_nabla[[diffusers.Kandinsky5T2VPipeline.fast_sta_nabla]]

```python
fast_sta_nabla(T: int, H: int, W: int, wT: int = 3, wH: int = 3, wW: int = 3, device = 'cuda')
```

[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky.py#L229)

**المعاملات:**

T (int) : عدد الإطارات الزمنية

H (int) : الارتفاع في الفضاء الكامن

W (int) : العرض في الفضاء الكامن

wT (int) : حجم نافذة الانتباه الزمني

wH (int) : حجم نافذة الانتباه للارتفاع

wW (int) : حجم نافذة الانتباه

device (str) : الجهاز الذي سيتم إنشاء المصفوفة عليه

**يعيد:** `torch.Tensor`

قناع انتباه متناثر (Sparse attention mask) من الشكل (T*H*W, T*H*W)

أنشئ قناع انتباه زمني متناثر (STA) لتوليد الفيديو بكفاءة.

تولّد هذه الطريقة قناعًا يحدّ الانتباه إلى الإطارات والمواقع المكانية القريبة، مما يقلّل التعقيد الحسابي لتوليد الفيديو.

#### get_sparse_params[[diffusers.Kandinsky5T2VPipeline.get_sparse_params]]

```python
get_sparse_params(sample, device)
```

[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky.py#L264)

**المعاملات:**

sample (torch.Tensor) : متجه العينة المُدخل

device (torch.device) : الجهاز الذي سيتم وضع المصفوفات عليه

**يعيد:** `Dict`

قاموس يحتوي على معاملات الانتباه المتناثر

توليد معاملات الانتباه المتناثر (sparse attention) للمحوّل (transformer) بناءً على أبعاد العينة.

تُحسب هذه الطريقة إعداد الانتباه المتناثر (sparse attention) اللازمة لمعالجة الفيديو بكفاءة في نموذج الترانسفورمر.

#### prepare_latents[[diffusers.Kandinsky5T2VPipeline.prepare_latents]]

```python
prepare_latents(batch_size: int, num_channels_latents: int = 16, height: int = 480, width: int = 832, num_frames: int = 81, 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.py#L597)

**المعاملات:**

batch_size (int) : عدد مقاطع الفيديو التي سيتم توليدها

num_channels_latents (int) : عدد القنوات في الفضاء الكامن

height (int) : ارتفاع الفيديو المولّد

width (int) : عرض الفيديو المولّد

num_frames (int) : عدد الإطارات في الفيديو

dtype (torch.dtype) : نوع البيانات للكامنات

device (torch.device) : الجهاز الذي سيتم إنشاء الكمونيات عليه

generator (torch.Generator) : مولّد الأرقام العشوائية

latents (torch.Tensor) : الكامنات الموجودة مسبقًا للاستخدام

**يعيد:** `torch.Tensor`

موتر كامن مُعدّ

جهّز متغيرات كامنة أولية لتوليد الفيديو.

تُنشئ هذه الطريقة ضوضاء عشوائية في الفضاء الكامن أو تستخدم الفضاء الكامن المُقدَّم كنقطة انطلاق لعملية إزالة الضوضاء.

## Kandinsky5I2VPipeline[[diffusers.Kandinsky5I2VPipeline]]

#### diffusers.Kandinsky5I2VPipeline[[diffusers.Kandinsky5I2VPipeline]]

```python
diffusers.Kandinsky5I2VPipeline(transformer: Kandinsky5Transformer3DModel, vae: AutoencoderKLHunyuanVideo, 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_i2v.py#L128)

**المعاملات:**

transformer (`Kandinsky5Transformer3DModel`) : نموذج Transformer مشروط لإزالة الضوضاء من كامنات الفيديو المُرمّزة.

vae ([AutoencoderKLHunyuanVideo](/docs/diffusers/main/ar/api/models/autoencoder_kl_hunyuan_video#diffusers.AutoencoderKLHunyuanVideo)) : نموذج الترميز التحويلي التبايني [hunyuanvideo-community/HunyuanVideo (vae)](https://huggingface.co/hunyuanvideo-community/HunyuanVideo) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

text_encoder (`Qwen2_5_VLForConditionalGeneration`) : مُشفِّر نص ثابت [Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct).

tokenizer (`AutoProcessor`) : مُجزِّئ (Tokenizer) لـ Qwen2.5-VL.

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`) : مُقسِّم (Tokenizer) خاص بنموذج CLIP.

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ar/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : مُجدوِل يُستخدم بالاقتران مع `transformer` لإزالة الضوضاء من كامنات الفيديو المُرمَّزة.

خط أنابيب لتوليد الفيديو من الصور باستخدام Kandinsky 5.0.

يرث هذا النموذج من [DiffusionPipeline](/docs/diffusers/main/ar/api/pipelines/overview#diffusers.DiffusionPipeline). راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

#### __call__[[diffusers.Kandinsky5I2VPipeline.__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 = 512, width: int = 768, num_frames: int = 121, num_inference_steps: int = 50, guidance_scale: float = 5.0, num_videos_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_i2v.py#L748)

**المعاملات:**

image (`PipelineImageInput`) : الصورة المدخلة التي تُشترط عليها عملية التوليد. يجب أن تكون صورة، أو قائمة من الصور، أو `torch.Tensor`.

prompt (`str` أو `list[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الفيديو. إذا لم تُعرَّف، فمرّر `prompt_embeds` بدلاً من ذلك.

negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي يجب تجنبها أثناء توليد الفيديو. إذا لم يُعرَّف، فمرّر `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (`guidance_scale` < `1`).

height (`int`، القيمة الافتراضية `512`) : ارتفاع الفيديو المولّد بالبكسلات.

width (`int`، القيمة الافتراضية `768`) : عرض الفيديو المولّد بالبكسل.

num_frames (`int`، القيمة الافتراضية `121`) : عدد الإطارات في الفيديو المولّد.

num_inference_steps (`int`، القيمة الافتراضية `50`) : عدد خطوات إزالة الضوضاء.

guidance_scale (`float`، القيمة الافتراضية `5.0`) : مقياس التوجيه كما هو مُعرَّف في التوجيه الحر من التصنيف.

num_videos_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 positive prompt.

negative_prompt_cu_seqlens (`torch.Tensor`، *اختياري*) : أطوال التسلسل التراكمي المُولَّدة مسبقًا لـ Qwen negative prompt.

output_type (`str`، *اختياري*، الافتراضي `"pil"`) : صيغة مخرجات الفيديو المولّد.

return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `KandinskyPipelineOutput` أم لا.

callback_on_step_end (`Callable`، `PipelineCallback`، `MultiPipelineCallbacks`، *اختياري*) : دالة تُستدعى في نهاية كل خطوة إزالة ضوضاء.

callback_on_step_end_tensor_inputs (`List`، *اختياري*) : قائمة مدخلات المصفوفات (tensors) لدالة `callback_on_step_end`.

max_sequence_length (`int`، القيمة الافتراضية `512`) : الحد الأقصى لطول التسلسل لتشفير النص.

**يعيد:** `~KandinskyPipelineOutput` أو `tuple`

إذا كان `return_dict` هو `True`، يُعاد `KandinskyPipelineOutput`، وإلا يُعاد `tuple` يكون عنصره الأول قائمة بالفيديوهات المولّدة.

دالة الاستدعاء call لخط الأنابيب pipeline لتوليد الفيديو من الصورة.

أمثلة:

```python
>>> import torch
>>> from diffusers import Kandinsky5I2VPipeline
>>> from diffusers.utils import export_to_video, load_image

>>> # Available models:
>>> # kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers

>>> model_id = "kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers"
>>> pipe = Kandinsky5I2VPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe = pipe.to("cuda")

>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
... )
>>> prompt = "An astronaut floating in space with Earth in the background, cinematic shot"
>>> negative_prompt = "Static, 2D cartoon, cartoon, 2d animation, paintings, images, worst quality, low quality, ugly, deformed, walking backwards"

>>> output = pipe(
...     image=image,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=512,
...     width=768,
...     num_frames=121,
...     num_inference_steps=50,
...     guidance_scale=5.0,
... ).frames[0]

>>> export_to_video(output, "output.mp4", fps=24, quality=9)
```

#### check_inputs[[diffusers.Kandinsky5I2VPipeline.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_i2v.py#L545)

**المعاملات:**

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.Kandinsky5I2VPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], num_videos_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_i2v.py#L454)

**المعاملات:**

prompt (`str` أو `list[str]`) : الأمر الذي سيتم ترميزه.

num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد مقاطع الفيديو التي سيتم توليدها لكل موجه.

max_sequence_length (`int`، *اختياري*، القيمة الافتراضية 512) : الحد الأقصى لطول التسلسل لتشفير النص.

device (`torch.device`، *اختياري*) : جهاز Torch.

dtype (`torch.dtype`، *اختياري*) : نوع Torch.

**يعيد:** tuple[torch.Tensor, torch.Tensor, torch.Tensor]

- تضمينات نص Qwen ذات الشكل (batch_size * num_videos_per_prompt, sequence_length, embedding_dim)
- تضمينات CLIP المجمّعة ذات الشكل (batch_size * num_videos_per_prompt, clip_embedding_dim)
- الطول التراكمي للتسلسلات (`cu_seqlens`) لتضمينات Qwen من الشكل (batch_size * num_videos_per_prompt + 1,)

يقوم بتشفير موجه واحد (إيجابي أو سلبي) إلى حالات مخفية لمشفّر النص.

تجمع هذه الطريقة بين التضمينات (embeddings) المستخرجة من كلا مشفري النصوص Qwen2.5-VL وCLIP لإنشاء تمثيلات نصية شاملة لتوليد الفيديو.

#### fast_sta_nabla[[diffusers.Kandinsky5I2VPipeline.fast_sta_nabla]]

```python
fast_sta_nabla(T: int, H: int, W: int, wT: int = 3, wH: int = 3, wW: int = 3, device = 'cuda')
```

[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2v.py#L226)

**المعاملات:**

T (int) : عدد الإطارات الزمنية

H (int) : الارتفاع في الفضاء الكامن

W (int) : العرض في الفضاء الكامن

wT (int) : حجم نافذة الانتباه الزمني

wH (int) : حجم نافذة الانتباه للارتفاع

wW (int) : حجم نافذة الانتباه

device (str) : الجهاز الذي سيتم إنشاء المصفوفة عليه

**يعيد:** `torch.Tensor`

قناع انتباه متناثر (Sparse attention mask) من الشكل (T*H*W, T*H*W)

أنشئ قناع انتباه زمني متناثر (STA) لتوليد الفيديو بكفاءة.

تولّد هذه الطريقة قناعًا يحدّ الانتباه إلى الإطارات والمواقع المكانية القريبة، مما يقلّل التعقيد الحسابي لتوليد الفيديو.

#### get_sparse_params[[diffusers.Kandinsky5I2VPipeline.get_sparse_params]]

```python
get_sparse_params(sample, device)
```

[المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky5/pipeline_kandinsky_i2v.py#L261)

**المعاملات:**

sample (torch.Tensor) : متجه العينة المُدخل

device (torch.device) : الجهاز الذي سيتم وضع المصفوفات عليه

**يعيد:** `Dict`

قاموس يحتوي على معاملات الانتباه المتناثر

توليد معاملات الانتباه المتناثر (sparse attention) للمحوّل (transformer) بناءً على أبعاد العينة.

تُحسب هذه الطريقة إعداد الانتباه المتناثر (sparse attention) اللازمة لمعالجة الفيديو بكفاءة في نموذج الترانسفورمر.

#### prepare_latents[[diffusers.Kandinsky5I2VPipeline.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 = 480, width: int = 832, num_frames: int = 81, 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_i2v.py#L636)

**المعاملات:**

image (PipelineImageInput) : صورة الإدخال التي تُشترط عليها عملية التوليد

batch_size (int) : عدد مقاطع الفيديو التي سيتم توليدها

num_channels_latents (int) : عدد القنوات في الفضاء الكامن

height (int) : ارتفاع الفيديو المولّد

width (int) : عرض الفيديو المولّد

num_frames (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
}
```

