Buckets:
| # PAN 2 | |
| PAN2 هو نموذج عالمي أساسي يحاكي كيفية تطور المشهد تحت خطة زمنية للأفعال وحركات الكاميرا. محاكيه التوليدي بحجم 29B هو محوّل انتشار متعدد الوسائط ذو تدفق مزدوج، وقد تم دمجه هنا؛ أما [الهيكل الاستدلالي](https://huggingface.co/IFM/PAN2#reasoning-backbone) الذي يكتب أوامره التوجيهية فلم يتم دمجه. | |
| يُدمج PAN 2 على شكل كتل [Modular Diffusers](../../modular_diffusers/overview) فقط. يدعم [PAN2Blocks](/docs/diffusers/main/ar/api/pipelines/pan2#diffusers.PAN2Blocks) مساري عمل: | |
| | سير العمل | المدخلات | | |
| |---|---| | |
| | `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) | |
| ``` | |
| يتم تكوين التوجيه الحر من التصنيف على الموجّه (`guidance_scale=2.5` افتراضيًا): | |
| ```py | |
| pipe.update_components(guider=pipe.guider.new(guidance_scale=5.0)) | |
| ``` | |
| تستقبل كل استدعاءً موجهًا واحدًا، يُرمَّز دون حشو. لذا لا يحتاج المحوِّل إلى قناع انتباه أبدًا، ويتوفر كل [خلفية انتباه](../../optimization/attention_backends): | |
| ```py | |
| pipe.transformer.set_attention_backend("flash_hub") # FlashAttention-2 | |
| ``` | |
| ## فاحص الأمان | |
| يعمل PAN 2 على تطبيق ضوابط السلامة على الاستعلام قبل التوليد وعلى كل فيديو مُولَّد بعد ذلك، ويؤدي الاستعلام أو الفيديو المحظور إلى رفع `ValueError`. تكون هذه الفحوصات مفعّلة افتراضيًا، ويحمّل `load_components()` ضوابط السلامة، التي تتطلب حزمة [PAN 2 guardrail](https://github.com/ifm-ai/pan2-guardrail): | |
| ```bash | |
| pip install git+https://github.com/ifm-ai/pan2-guardrail | |
| ``` | |
| ## توازي السياق | |
| يدعم [PAN2Transformer3DModel](/docs/diffusers/main/ar/api/models/pan2_transformer3d#diffusers.PAN2Transformer3DModel) [context parallelism](../../optimization/context_parallelism). عادةً لا تكون أعداد رموز النص والفيديو قابلة للقسمة على عدد الأجهزة (حيث يعتمد عدد رموز النص على الأمر)، لذا استخدم `ulysses_anything` أو `ring_anything` للاستدلال. أما `ulysses_degree` / `ring_degree` العادي، على سبيل المثال للتدريب، فيشترط أن تكون كلا العددين من الرموز قابلين للقسمة على حجم موازاة السياق. | |
| ```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) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L42) | |
| ModularPipeline لـ PAN 2: من النص إلى الفيديو، ومن الصورة إلى الفيديو من إطار أول. | |
| ```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() | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L103) | |
| ارفع استثناءً إذا كانت الفحوصات مفعّلة لكن حاجز الأمان PAN 2 غير محمّل. | |
| #### disable_safety_checker[[diffusers.PAN2ModularPipeline.disable_safety_checker]] | |
| ```python | |
| disable_safety_checker() | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L118) | |
| أطفئ فحوصات الموجه والفيديو، على مسؤوليتك الخاصة. | |
| #### enable_safety_checker[[diffusers.PAN2ModularPipeline.enable_safety_checker]] | |
| ```python | |
| enable_safety_checker() | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L97) | |
| تحقق من الأمر (prompt) والفيديوهات المولّدة باستخدام حاجز الأمان PAN 2. | |
| ## PAN2Blocks[[diffusers.PAN2Blocks]] | |
| #### diffusers.PAN2Blocks[[diffusers.PAN2Blocks]] | |
| ```python | |
| diffusers.PAN2Blocks() | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_blocks_pan2.py#L255) | |
| كتل خط أنابيب معيارية لتوليد الفيديو من النص والفيديو من الصورة باستخدام PAN 2. | |
| سير العمل المدعومة: | |
| - `t2v`: يتطلب `prompt` | |
| - `i2v`: يتطلب `prompt`، `image` | |
| المكوّنات: | |
| - text_encoder (`Qwen3_5TextModel`) | |
| - tokenizer (`Qwen2Tokenizer`) | |
| - safety_checker (`PAN2SafetyChecker`) | |
| - vae (`AutoencoderKLWan`) | |
| - video_processor (`VideoProcessor`) | |
| - scheduler (`FlowMatchEulerDiscreteScheduler`) | |
| - transformer (`PAN2Transformer3DModel`) | |
| - guider (`ClassifierFreeGuidance`) | |
| إعدادات: | |
| - enable_safety_checker (الافتراضي: True) | |
| المدخلات: prompt (`str`): الأمر الموجّه للتوليد، وهو نص واحد. negative_prompt (`str`, *اختياري*): الأمر الذي لا يُوجَّه به التوليد، وهو نص واحد. عندما يتطلب التوجيه أمرًا سالبًا ولم يُمرَّر أي أمر (أو كان الأمر فارغًا)، يُستخدم الأمر السلبي الافتراضي الخاص بـ PAN 2، مع ضبط نطاقاته الزمنية على مدة المقطع. max_sequence_length (`int`, *اختياري*, الافتراضي 1536): الحد الأقصى لطول التسلسل لتشفير الأمر. num_frames (`int`, *اختياري*, الافتراضي 313): عدد إطارات الفيديو المراد توليدها، بصيغة `4 * n + 1`. fps (`float`, *اختياري*, الافتراضي 24.0): معدل الإطارات للفيديو، وهو ما يحدد مدته في الأمر السلبي الافتراضي. image (`Image`, *اختياري*): الإطار الأول، وهو صورة واحدة. height (`int`, *اختياري*): ارتفاع الفيديو المولّد بالبكسلات، 704 افتراضيًا. width (`int`, *اختياري*): عرض الفيديو المولّد بالبكسلات، 1248 افتراضيًا. num_videos_per_prompt (`int`, *اختياري*, الافتراضي 1): عدد الفيديوهات المراد توليدها لكل أمر. image_latents (`Tensor`, *اختياري*): قيم latents المُعايرة للإطار الأول. يمكن توليدها من خطوة vae_encoder. num_inference_steps (`int`): عدد خطوات إزالة الضوضاء. sigmas (`list`, *اختياري*): قيم sigmas مخصصة لعملية إزالة الضوضاء. latents (`Tensor`): قيم latents ضوضائية مُولّدة مسبقًا لاستخدامها كمدخلات لتوليد الفيديو. generator (`Generator`, *اختياري*): مولّد Torch لتوليد حتمي. attention_kwargs (`dict`, *اختياري*): معاملات إضافية لمعالجات الانتباه. output_type (`str`, *اختياري*, الافتراضي np): صيغة الإخراج: 'pil'، 'np'، 'pt'. | |
| المخرجات: مقاطع فيديو (`list`): مقاطع الفيديو المولّدة. | |
Xet Storage Details
- Size:
- 9.27 kB
- Xet hash:
- aff258626aec7aa20d4af1909055d37ca5557da1b3d93b54f0edb2b2904e812c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.