# PAN 2

PAN2, zamanla ilişkili bir eylem ve kamera hareketi planı altında bir sahnenin nasıl evrildiğini simüle eden bir temel dünya modelidir. 29B'lik üretken simülatörü, burada entegre edilen çift akımlı çok modlu difüzyon transformeri'dir; promptlarını yazan [akıl yürütme omurgası](https://huggingface.co/IFM/PAN2#reasoning-backbone) ise değildir.

PAN 2 yalnızca [Modular Diffusers](../../modular_diffusers/overview) blokları olarak entegre edilmiştir. [PAN2Blocks](/docs/diffusers/v0.43.0/tr/api/pipelines/pan2#diffusers.PAN2Blocks) iki iş akışını destekler:

| İş Akışı | Girdiler |
|---|---|
| `t2v` | `prompt` |
| `i2v` | `prompt`, `image` |

```py
import torch
from diffusers import ModularPipeline
from diffusers.utils import export_to_video, load_image

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

prompt = "A red fox trots through fresh snow in a pine forest at dawn."

video = pipe(prompt=prompt, generator=torch.Generator().manual_seed(0), output="videos")[0]
export_to_video(video, "pan2_t2v.mp4", fps=24)

image = load_image("path/to/first_frame.png")
video = pipe(prompt=prompt, image=image, generator=torch.Generator().manual_seed(0), output="videos")[0]
export_to_video(video, "pan2_i2v.mp4", fps=24)
```

Classifier-free guidance, guider üzerinde yapılandırılır (varsayılan olarak `guidance_scale=2.5`):

```py
pipe.update_components(guider=pipe.guider.new(guidance_scale=5.0))
```

Her çağrı, dolgusuz olarak kodlanan tek bir istem alır. Bu nedenle transformer asla bir dikkat maskesine ihtiyaç duymaz ve tüm [dikkat arka uçları](../../optimization/attention_backends) kullanılabilir:

```py
pipe.transformer.set_attention_backend("flash_hub")  # FlashAttention-2
```

## Güvenlik denetleyicisi

PAN 2, üretimden önce istemci üzerinde ve üretilen her video üzerinde guardrail çalıştırır; engellenen bir istemci veya video `ValueError` oluşturur. Kontroller varsayılan olarak açıktır ve `load_components()` guardrail’leri yükler; bunun için [PAN 2 guardrail](https://github.com/ifm-ai/pan2-guardrail) paketi gereklidir:

```bash
pip install git+https://github.com/ifm-ai/pan2-guardrail
```

## Bağlam paralelliği

[PAN2Transformer3DModel](/docs/diffusers/v0.43.0/tr/api/models/pan2_transformer3d#diffusers.PAN2Transformer3DModel), [context parallelism](../../optimization/context_parallelism) destekler. Metin ve video token sayıları genellikle cihaz sayısına (metin token sayısı prompt'a bağlıdır) tam bölünmez, bu nedenle çıkarım için `ulysses_anything` veya `ring_anything` kullanın. Örneğin eğitim için kullanılan düz `ulysses_degree` / `ring_degree`, her iki token sayısının da context parallel boyutuna tam bölünmesini gerektirir.

```py
# torchrun --nproc_per_node=2 pan2_context_parallel.py
import torch
import torch.distributed as dist
from diffusers import ContextParallelConfig, ModularPipeline

dist.init_process_group("nccl")
rank = dist.get_rank()
torch.cuda.set_device(rank)

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)
pipe.to(f"cuda:{rank}")
pipe.transformer.enable_parallelism(config=ContextParallelConfig(ulysses_degree=2, ulysses_anything=True))

video = pipe(prompt="A red fox trots through fresh snow.", generator=torch.Generator().manual_seed(0), output="videos")[0]
dist.destroy_process_group()
```

## PAN2ModularPipeline[[diffusers.PAN2ModularPipeline]]

#### diffusers.PAN2ModularPipeline[[diffusers.PAN2ModularPipeline]]

```python
diffusers.PAN2ModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```

[Kaynak](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L42)

PAN 2 için metinden videoya ve ilk kareden videoya dönüştürme işlemleri için bir ModularPipeline.

```py
import torch
from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)
```

#### check_safety_checker_loaded[[diffusers.PAN2ModularPipeline.check_safety_checker_loaded]]

```python
check_safety_checker_loaded()
```

[Kaynak](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L103)

Kontroller açıkken PAN 2 guardrail yüklenmediyse hata fırlatın.

#### disable_safety_checker[[diffusers.PAN2ModularPipeline.disable_safety_checker]]

```python
disable_safety_checker()
```

[Kaynak](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L118)

Kendi sorumluluğunuzda, istek ve video kontrollerini kapatın.

#### enable_safety_checker[[diffusers.PAN2ModularPipeline.enable_safety_checker]]

```python
enable_safety_checker()
```

[Kaynak](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L97)

PAN 2 koruma bariyeri ile istemi ve oluşturulan videoları kontrol edin.

## PAN2Blocks[[diffusers.PAN2Blocks]]

#### diffusers.PAN2Blocks[[diffusers.PAN2Blocks]]

```python
diffusers.PAN2Blocks()
```

[Kaynak](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/modular_pipelines/pan2/modular_blocks_pan2.py#L251)

PAN 2 ile metinden videoya ve görüntüden videoya üretim için modüler pipeline blokları.

Desteklenen iş akışları:
- `t2v`: `prompt` gerektirir
- `i2v`: `prompt` ve `image` gerektirir

Bileşenler: text_encoder (`Qwen3_5TextModel`) tokenizer (`Qwen2Tokenizer`) safety_checker (`PAN2SafetyChecker`) vae (`AutoencoderKLWan`) video_processor (`VideoProcessor`) scheduler (`FlowMatchEulerDiscreteScheduler`) transformer (`PAN2Transformer3DModel`) guider (`ClassifierFreeGuidance`)

Yapılandırmalar: enable_safety_checker (varsayılan: True)

Inputs: prompt (`str`): The prompt to guide generation, a single string. negative_prompt (`str`, *optional*): The prompt not to guide generation, a single string. When guidance needs one and none (or an empty one) is passed, PAN 2's default negative prompt is used, its time ranges set to the clip's duration. max_sequence_length (`int`, *optional*, defaults to 1536): Maximum sequence length for prompt encoding. num_frames (`int`, *optional*, defaults to 313): Number of video frames to generate, of the form `4 * n + 1`. fps (`float`, *optional*, defaults to 24.0): The frame rate of the video, which sets its duration in the default negative prompt. image (`Image`, *optional*): The first frame, a single image. height (`int`, *optional*): The height in pixels of the generated video, 704 by default. width (`int`, *optional*): The width in pixels of the generated video, 1248 by default. num_videos_per_prompt (`int`, *optional*, defaults to 1): The number of videos to generate per prompt. image_latents (`Tensor`, *optional*): The normalized first-frame latents. Can be generated from the vae_encoder step. num_inference_steps (`int`): The number of denoising steps. sigmas (`list`, *optional*): Custom sigmas for the denoising process. latents (`Tensor`): Pre-generated noisy latents to use as inputs for video generation. generator (`Generator`, *optional*): Torch generator for deterministic generation. attention_kwargs (`dict`, *optional*): Additional kwargs for attention processors. output_type (`str`, *optional*, defaults to np): Output format: 'pil', 'np', 'pt'.

Çıktılar: videolar (`list`): Oluşturulan videolar.

