Buckets:
| # AnyFlow | |
| [AnyFlow: نموذج انتشار فيديو بخطوات حرة مع تقطير خريطة التدفق وفق السياسة](https://huggingface.co/papers/2605.13724) من NVIDIA وجامعة سنغافورة الوطنية ومعهد ماساتشوستس للتكنولوجيا، بقلم Yuchao Gu وGuian Fang وYuxin Jiang وWeijia Mao وSong Han وHan Cai وMike Zheng Shou. | |
| > **ملخص سريع:** يُعد AnyFlow أول إطار عمل لتوليد الفيديو بالانتشار (Diffusion) يعتمد على خرائط التدفق (Flow Maps)، مما يتيح لنموذج واحد (سواء كان ثنائي الاتجاه أو سببي) التكيف مع ميزانيات الاستدلال (Inference) المتغيرة. | |
| *شهد توليد الفيديو بعدد قليل من الخطوات تقدماً كبيراً بفضل نماذج الاتساق. ومع ذلك، فإن أدائها غالباً ما يتدهور في نماذج انتشار الفيديو التي تعمل بأي عدد من الخطوات بسبب صياغة النقطة الثابتة. لمعالجة هذه القيود، نقدم AnyFlow، وهو أول إطار لتقطير انتشار الفيديو الذي يعمل بأي عدد من الخطوات، مبني على خرائط التدفق. بدلاً من تعلم التحويل z_t → z_0 فقط، يتعلم AnyFlow الانتقالات z_t → z_r عبر فترات زمنية اختيارية، مما يتيح لنموذج واحد التكيف مع ميزانيات استنتاج مختلفة. صممنا وصفة تدريب محسّنة لخريطة التدفق الأمامية التي تعيد ضبط نماذج انتشار الفيديو المُسبقة التدريب لتصبح نماذج خرائط تدفق، وقدمنا محاكاة خلفية لخريطة التدفق (Flow Map Backward Simulation) لتمكين التقطير وفق السياسة (on-policy distillation) لنماذج خرائط التدفق. تُظهر التجارب الواسعة عبر كل من البنى المعمارية ثنائية الاتجاه والسببية، بمقاييس تتراوح من 1.3B إلى 14B، على مهام النص إلى الفيديو والصورة إلى الفيديو، أن AnyFlow يتفوق على الخطوط الأساسية القائمة على الاتساق مع الحفاظ على دقة عالية وعينة مرنة تحت ميزانيات خطوات متغيرة.* | |
| تمت مساهمة خطوط أنابيب AnyFlow من قبل فريق AnyFlow. الكود الأصلي متاح على [GitHub](https://github.com/NVlabs/AnyFlow)، وصفحة المشروع متاحة على [nvlabs.github.io/AnyFlow](https://nvlabs.github.io/AnyFlow)، ويمكن العثور على النماذج المُسبقة التدريب في مجموعة [nvidia/anyflow](https://huggingface.co/collections/nvidia/anyflow) على Hugging Face. | |
| النماذج المتاحة: | |
| | نقطة التفتيش | الهيكل | الوصف | | |
| |---|---|---| | |
| | [`nvidia/AnyFlow-Wan2.1-T2V-1.3B-Diffusers`](https://huggingface.co/nvidia/AnyFlow-Wan2.1-T2V-1.3B-Diffusers) | Wan2.1 1.3B | T2V ثنائي الاتجاه | | |
| | [`nvidia/AnyFlow-Wan2.1-T2V-14B-Diffusers`](https://huggingface.co/nvidia/AnyFlow-Wan2.1-T2V-14B-Diffusers) | Wan2.1 14B | T2V ثنائي الاتجاه | | |
| | [`nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers`](https://huggingface.co/nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers) | FAR + Wan2.1 1.3B | T2V / I2V / V2V السببي | | |
| | [`nvidia/AnyFlow-FAR-Wan2.1-14B-Diffusers`](https://huggingface.co/nvidia/AnyFlow-FAR-Wan2.1-14B-Diffusers) | FAR + Wan2.1 14B | T2V / I2V / V2V السببي | | |
| > [!TIP] | |
| > `AnyFlowPipeline` مصمَّم لنماذج الانتشار ثنائية الاتجاه في توليد الفيديو من النص (T2V). أما `AnyFlowFARPipeline` فهو نموذج انتشار سببي على مستوى المقاطع يدعم توليد الفيديو من النص (T2V)، وتوليد الفيديو من الصورة (I2V)، واستكمال الفيديو (V2V). | |
| ### التوليد باستخدام AnyFlow (T2V ثنائي الاتجاه) | |
| ```py | |
| import torch | |
| from diffusers import AnyFlowPipeline | |
| from diffusers.utils import export_to_video | |
| pipe = AnyFlowPipeline.from_pretrained( | |
| "nvidia/AnyFlow-Wan2.1-T2V-1.3B-Diffusers", dtype=torch.bfloat16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| prompt = ( | |
| "An astronaut runs smoothly and appears almost weightless on the lunar surface, " | |
| "as seen from a low-angle shot that highlights the vast, desolate background of the moon. " | |
| "The moon's craters and rocky terrain are clearly visible, creating a stark contrast against " | |
| "the running astronaut who moves with graceful, fluid motions." | |
| ) | |
| video = pipe(prompt, num_inference_steps=4, num_frames=81).frames[0] | |
| export_to_video(video, "anyflow_t2v.mp4", fps=16) | |
| ``` | |
| ### التوليد باستخدام AnyFlow (FAR Causal) | |
| تختار خط أنابيب السببية بين T2V / I2V / V2V عبر الحجة ``video`` (أو ``video_latents``): احذف كليهما للحصول على تحويل نص إلى فيديو عادي، أو مرر ``video=<tensor>`` بشكل ``(B, T, C, H, W)`` ضمن ``[0, 1]`` حيث ``T = 4n + 1`` لتأسيس الشرط على إطارات موجودة. استخدم إطار شرط واحد لـ I2V ومقطعًا أطول لاستكمال V2V. إذا كان لديك بالفعل كامنات مشفّرة مسبقًا في تخطيط النموذج، فمررها عبر ``video_latents=<tensor>`` لتخطي ترميز VAE. ``video`` و``video_latents`` متنافيان. | |
| > [!IMPORTANT] | |
| > تُدمج نقاط التفتيش المُصدَّرة `chunk_partition=[1, 3, 3, 3, 3, 3, 3, 2]` (مجموعها 21) في إعدادات التحويلي، بما يتوافق مع 81 إطارًا خامًا قياسيًّا (21 إطارًا كامنًا عند خطوة VAE الزمنية البالغة 4). عند تغيير `num_frames`، مرِّر `chunk_partition` متطابقًا يكون مجموع قيمه `(num_frames - 1) // 4 + 1`، وإلا فإن خط الأنابيب يرمي `ValueError`. | |
| ```py | |
| import torch | |
| from diffusers import AnyFlowFARPipeline | |
| from diffusers.utils import export_to_video | |
| pipe = AnyFlowFARPipeline.from_pretrained( | |
| "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| prompt = ( | |
| "An astronaut runs smoothly and appears almost weightless on the lunar surface, " | |
| "as seen from a low-angle shot that highlights the vast, desolate background of the moon." | |
| ) | |
| video = pipe(prompt, num_inference_steps=4, num_frames=81).frames[0] | |
| export_to_video(video, "anyflow_far_t2v.mp4", fps=16) | |
| ``` | |
| ```py | |
| import numpy as np | |
| import torch | |
| from diffusers import AnyFlowFARPipeline | |
| from diffusers.utils import export_to_video, load_image | |
| pipe = AnyFlowFARPipeline.from_pretrained( | |
| "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| # Example conditioning image from the AnyFlow repo. | |
| first_frame = load_image( | |
| "https://raw.githubusercontent.com/NVlabs/AnyFlow/main/assets/evaluation/example/images/1.jpg" | |
| ).resize((832, 480)) | |
| arr = np.asarray(first_frame).astype("float32") / 255.0 # (480, 832, 3) | |
| context_tensor = torch.from_numpy(arr).permute(2, 0, 1).unsqueeze(0).unsqueeze(1).to("cuda") # (1, 1, 3, 480, 832) | |
| prompt = ( | |
| "A towering, battle-scarred humanoid robot, reminiscent of a Transformer with powerful, segmented armor " | |
| "and glowing red optics, walking through the skeletal remains of a city ruin. Twisted metal and shattered " | |
| "concrete crunch under its heavy steps, as the robot scans the desolate, dust-choked skyline under an dark sky." | |
| ) | |
| video = pipe( | |
| prompt=prompt, | |
| video=context_tensor, | |
| num_inference_steps=4, | |
| num_frames=81, | |
| ).frames[0] | |
| export_to_video(video, "anyflow_far_i2v.mp4", fps=16) | |
| ``` | |
| ```py | |
| import numpy as np | |
| import torch | |
| from diffusers import AnyFlowFARPipeline | |
| from diffusers.utils import export_to_video, load_video | |
| pipe = AnyFlowFARPipeline.from_pretrained( | |
| "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| # Example conditioning clip from the AnyFlow repo — take the first 9 frames (3 latent frames at VAE temporal stride 4). | |
| context_frames = load_video( | |
| "https://raw.githubusercontent.com/NVlabs/AnyFlow/main/assets/evaluation/example/videos/2.mp4" | |
| )[:9] | |
| arr = np.stack([np.asarray(f.resize((832, 480))) for f in context_frames]).astype("float32") / 255.0 | |
| context_tensor = torch.from_numpy(arr).permute(0, 3, 1, 2).unsqueeze(0).to("cuda") # (1, 9, 3, 480, 832) | |
| prompt = ( | |
| "A focused trail runner's powerful strides through a dense, sun-dappled forest. " | |
| "The camera tracks alongside, highlighting muscular exertion, sweat, and determined facial expression." | |
| ) | |
| video = pipe( | |
| prompt=prompt, | |
| video=context_tensor, | |
| num_inference_steps=4, | |
| num_frames=81, | |
| # Override chunk_partition so the first chunk covers exactly the 3 latent context frames. | |
| chunk_partition=[3, 3, 3, 3, 3, 3, 3], | |
| ).frames[0] | |
| export_to_video(video, "anyflow_far_v2v.mp4", fps=16) | |
| ``` | |
| ## ملاحظات | |
| - يُدمج التوجيه الحر من التصنيف (Classifier-free guidance) في نقاط التفتيش المنشورة، لذا لا يُنفَّذ مسار أمامي موجّه ثانٍ أثناء الاستدلال. حافظ على القيمة الافتراضية `guidance_scale=1.0` ما لم تتطلب نقطة تفتيشك الخاصة غير ذلك. | |
| - `FlowMapEulerDiscreteScheduler` هو مُجدول عام الاستخدام. يمكنك إرفاقه بأي نقطة تحقق مُقطّرة لخريطة التدفق عبر `from_pretrained(..., scheduler=FlowMapEulerDiscreteScheduler.from_config(...))`. | |
| - `AnyFlowPipeline` يستخدم [`AnyFlowTransformer3DModel`](../models/anyflow_transformer3d) (ثنائي الاتجاه). يستخدم `AnyFlowFARPipeline` [`AnyFlowFARTransformer3DModel`](../models/anyflow_far_transformer3d)، الذي يضيف تضمين بقع إطار مضغوط وقناع كتلة سببية FAR. | |
| - يُؤمَّن تحميل LoRA عبر `WanLoraLoaderMixin`، وهو نفس الميكسين المستخدم في خطوط إنتاج Wan الأصلية. | |
| - بالنسبة لوصفات التدريب (تدريب تدفق الخريطة الأمامية والتقطير وفق السياسة)، يُرجى الرجوع إلى إطار عمل AnyFlow الأصلي للتدريب في [`NVlabs/AnyFlow`](https://github.com/NVlabs/AnyFlow)؛ التدريب خارج نطاق diffusers. | |
| ## AnyFlowPipeline[[diffusers.AnyFlowPipeline]] | |
| #### diffusers.AnyFlowPipeline[[diffusers.AnyFlowPipeline]] | |
| ```python | |
| diffusers.AnyFlowPipeline(tokenizer: AutoTokenizer, text_encoder: UMT5EncoderModel, transformer: AnyFlowTransformer3DModel, vae: AutoencoderKLWan, scheduler: FlowMapEulerDiscreteScheduler) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow.py#L80) | |
| **المعاملات:** | |
| tokenizer ([*AutoTokenizer*]) : مُقسِّم (Tokenizer) من [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| text_encoder ([*UMT5EncoderModel*]) : مُشفّر النصوص [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| transformer ([*AnyFlowTransformer3DModel*]) : نموذج Transformer ثلاثي الأبعاد لخريطة التدفق ثنائي الاتجاه. | |
| vae ([*AutoencoderKLWan*]) : نموذج VAE يقوم بتشفير/فك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها. | |
| scheduler ([*FlowMapEulerDiscreteScheduler*]) : مُعيّن عيّنات خريطة التدفق. تُشغّل خط الأنابيب `scheduler.step(..., timestep, sample, r_timestep)` في كل خطوة استنتاج. | |
| خط أنابيب ثنائي الاتجاه لتوليد الفيديو من النص لنقاط التفتيش المُقطّرة عبر خرائط التدفق في AnyFlow، كما طُرحت في [AnyFlow](https://huggingface.co/papers/2605.13724). | |
| AnyFlow learns arbitrary-interval transitions \\(z_t \to z_r\\) rather than the fixed \\(z_t \to z_0\\) mapping of consistency models, so a single distilled checkpoint can be evaluated at 1, 2, 4, 8, 16... NFE without retraining. This pipeline operates over the full video tensor in one bidirectional pass; for chunk-wise autoregressive (causal) generation use `AnyFlowFARPipeline`. | |
| تتم عملية العينة باستخدام أويلر العادي بصيغة السرعة المتوسطة (`z_r = z_t - (t - r) * u`) دون إعادة الضجيج. تُدمج نقاط التفتيش التي أصدرتها NVIDIA التوجيه الحر من التصنيف في أوزان النموذج، لذا فإن الإعداد الافتراضي `guidance_scale=1.0` هو الإعداد الموصى به. | |
| يرث هذا النموذج من [*DiffusionPipeline*]. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ). | |
| #### __call__[[diffusers.AnyFlowPipeline.__call__]] | |
| ```python | |
| __call__(prompt: typing.Union[str, typing.List[str]] = None, video: typing.Optional[torch.Tensor] = None, video_latents: typing.Optional[torch.Tensor] = None, negative_prompt: typing.Union[str, typing.List[str]] = None, height: int = 480, width: int = 832, num_frames: int = 81, num_inference_steps: int = 50, sigmas: typing.Optional[typing.List[float]] = None, timesteps: typing.Optional[typing.List[float]] = None, guidance_scale: float = 1.0, num_videos_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'np', return_dict: bool = True, attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512, use_mean_velocity: bool = True) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow.py#L380) | |
| **المعاملات:** | |
| prompt (`str` أو `List[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الفيديو. إذا لم تُعرَّف، فمرّر `prompt_embeds` بدلاً من ذلك. | |
| video (`torch.Tensor`, *اختياري*) : إطارات شرطية قبل VAE ذات الشكل `(B, T, C, H, W)` ضمن `[0, 1]`. عند تقديمها، يقوم خط الأنابيب بتشفيرها باستخدام VAE ويُبقي البادئة الكامنة المقابلة ثابتة أثناء أخذ العينات. متعارضة مع `video_latents`. | |
| video_latents (`torch.Tensor`، *اختياري*) : كامنات VAE مُرمّزة مسبقًا بتنسيق AnyFlow `(B, T_latent, C, H_latent, W_latent)`. يتخطى ترميز VAE على جانب خط الأنابيب. متنافٍ مع `video`. | |
| negative_prompt (`str` أو `List[str]`، *اختياري*) : الأمر أو الأوامر التي يجب تجنّبها أثناء توليد الفيديو. يتم تجاهلها عند عدم استخدام التوجيه (`guidance_scale < 1`). | |
| height (`int`، القيمة الافتراضية `480`) : ارتفاع الفيديو المولّد بالبكسلات. | |
| width (`int`، القيمة الافتراضية `832`) : عرض الفيديو المولّد بالبكسلات. | |
| num_frames (`int`، القيمة الافتراضية `81`) : عدد الإطارات في الفيديو المولّد. يجب أن يحقق الشرط `(num_frames - 1) % vae_scale_factor_temporal == 0`. | |
| num_inference_steps (`int`، القيمة الافتراضية `50`) : عدد خطوات إزالة الضوضاء. تدعم نقاط التفتيش المُقطّرة من AnyFlow أخذ عينات بأي عدد من الخطوات، لذا فإن القيم المنخفضة مثل `1` أو `2` أو `4` أو `8` هي قيم شائعة. يتم تجاهل هذا المعامل عند تقديم `sigmas` أو `timesteps`. | |
| sigmas (`List[float]`، *اختياري*) : جدول سيجما مخصص للعينة ذات الخطوات الحرة، ضمن `[0, 1]` ومرتب من الضوضاء إلى النقاء. يحدد الطول قيمة `num_inference_steps` الفعلية؛ حيث يضيف المجدول قيمة سيجما النهائية `0`. | |
| timesteps (`List[float]`، *اختياري*) : جدول خطوات زمنية مخصص للعينة ذات الخطوات الحرة، بنفس وحدات `self.scheduler.timesteps` (أي مُقيّمة بواسطة `num_train_timesteps`). يتعارض مع `sigmas`. | |
| guidance_scale (`float`، القيمة الافتراضية `1.0`) : مقياس التوجيه الحر من التصنيف. نقاط التفتيش الخاصة بـ AnyFlow التي تم إصدارها تدمج CFG في الأوزان أثناء التدريب؛ حافظ على القيمة عند `1.0` ما لم تكن على علم بأن نقطة التفتيش الخاصة بك تتوقع خلاف ذلك. | |
| num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية `1`) : عدد مقاطع الفيديو التي سيتم توليدها لكل موجه. | |
| generator (`torch.Generator` أو `List[torch.Generator]`، *اختياري*) : [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) لجعل التوليد حتميًا. | |
| latents (`torch.Tensor`، *اختياري*) : كامنات ضجيج مُولّدة مسبقًا لاستخدامها كمدخلات. إذا لم تُوفَّر، تُسحب الكامنات من `generator` المُقدَّم. | |
| prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل المدخلات النصية (مثل وزن الأوامر). إذا لم تُقدَّم، يتم توليد التمثيلات من `prompt`. | |
| negative_prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. | |
| output_type (`str`، *اختياري*، الافتراضي `"np"`) : صيغة المخرجات. واحدة من `"pil"`، `"np"`، `"pt"`، أو `"latent"`. | |
| return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `AnyFlowPipelineOutput` بدلاً من tuple عادي. | |
| attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py). | |
| callback_on_step_end (`Callable`، *اختياري*) : دالة أو `PipelineCallback` تُستدعى في نهاية كل خطوة استنتاج. راجع [`callbacks`](../callbacks) للتفاصيل. | |
| callback_on_step_end_tensor_inputs (`List[str]`، *اختياري*، القيمة الافتراضية `["latents"]`) : مدخلات المصفوفات المُرسلة إلى الاستدعاء العكسي. يجب أن تكون مجموعة فرعية من `self._callback_tensor_inputs`. | |
| max_sequence_length (`int`، القيمة الافتراضية `512`) : الحد الأقصى لطول تسلسل مُشفِّر النص. يتم اقتطاع الأوامر الأطول من ذلك. | |
| use_mean_velocity (`bool`، القيمة الافتراضية `True`) : عندما تكون `True`، يُشترط نموذج خريطة التدفق على كل من خطوة الزمن المصدر `t` وخطوة الزمن الهدف `r` للتنبؤ بسرعة متوسطة، بما يتوافق مع سلوك وقت التدريب. عطّل هذا الخيار لمحاكاة خطوات أويلر الخام (`r = t`). | |
| **يعيد:** `~AnyFlowPipelineOutput` أو `tuple` | |
| إذا كان `return_dict` هو `True`، يُعاد `AnyFlowPipelineOutput`، وإلا يُعاد `tuple` يكون عنصره الأول هو الفيديو المولّد. | |
| دالة الاستدعاء call لخط الأنابيب pipeline الخاص بالتوليد. | |
| أمثلة: | |
| ```python | |
| >>> import torch | |
| >>> from diffusers import AnyFlowPipeline | |
| >>> from diffusers.utils import export_to_video | |
| >>> pipe = AnyFlowPipeline.from_pretrained( | |
| ... "nvidia/AnyFlow-Wan2.1-T2V-14B-Diffusers", torch_dtype=torch.bfloat16 | |
| ... ).to("cuda") | |
| >>> prompt = "A red panda eating bamboo in a forest, cinematic lighting" | |
| >>> video = pipe(prompt, num_inference_steps=4, num_frames=33).frames[0] | |
| >>> export_to_video(video, "anyflow_t2v.mp4", fps=16) | |
| ``` | |
| #### encode_prompt[[diffusers.AnyFlowPipeline.encode_prompt]] | |
| ```python | |
| encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow.py#L180) | |
| **المعاملات:** | |
| prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه | |
| negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`). | |
| do_classifier_free_guidance (`bool`، *اختياري*، الافتراضي `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا. | |
| num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد مقاطع الفيديو التي يجب توليدها لكل موجه. جهاز torch الذي سيتم وضع التضمينات الناتجة عليه | |
| prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`. | |
| negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`. | |
| device : (`torch.device`, *اختياري*): جهاز torch | |
| dtype : (`torch.dtype`, *اختياري*): torch dtype | |
| يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص. | |
| #### encode_video[[diffusers.AnyFlowPipeline.encode_video]] | |
| ```python | |
| encode_video(video: Tensor, height: int, width: int) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow.py#L360) | |
| ترميز فيديو في فضاء البكسلات إلى التخطيط الكامن الخاص بـ AnyFlow. | |
| Mirrors the single-helper convention of other diffusers pipelines (cf. `WanImageToVideoPipeline.encode_image`): wraps preprocessing, VAE encoding, and latent normalization into one call. Output layout is `(B, T_latent, C, H, W)`, which is what the AnyFlow transformer expects for conditioning frames. | |
| ## AnyFlowFARPipeline[[diffusers.AnyFlowFARPipeline]] | |
| #### diffusers.AnyFlowFARPipeline[[diffusers.AnyFlowFARPipeline]] | |
| ```python | |
| diffusers.AnyFlowFARPipeline(tokenizer: AutoTokenizer, text_encoder: UMT5EncoderModel, transformer: AnyFlowFARTransformer3DModel, vae: AutoencoderKLWan, scheduler: FlowMapEulerDiscreteScheduler) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow_far.py#L92) | |
| **المعاملات:** | |
| tokenizer ([*AutoTokenizer*]) : مُقسِّم (Tokenizer) من [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| text_encoder ([*UMT5EncoderModel*]) : مُشفّر النصوص [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| transformer ([*AnyFlowFARTransformer3DModel*]) : نموذج Transformer ثلاثي الأبعاد لخريطة التدفق السببية FAR. | |
| vae ([*AutoencoderKLWan*]) : نموذج VAE يقوم بتشفير/فك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها. | |
| scheduler ([*FlowMapEulerDiscreteScheduler*]) : مُعيّن عيّنات خريطة التدفق. | |
| Causal خط أنابيب (مبني على FAR) لتحويل النص إلى فيديو / الصورة إلى فيديو / الفيديو إلى فيديو لنقاط التفتيش الخاصة بـ AnyFlow، كما تم تقديمه في [AnyFlow](https://huggingface.co/papers/2605.13724). | |
| تقود خط المعالجة حلقة أخذ عينات ذاتية التوليد على مستوى المقاطع: يُزال الضوضاء عن كل مقطع عبر خطوات خريطة التدفق مع الانتباه حصريًا إلى المقاطع السابقة عبر الانتباه السببي المتناثر على مستوى الكتل، ويُعاد استخدام ذاكرة التخزين المؤقت لـ KV بين المقاطع. | |
| يتم تحديد وضع المهمة (T2V / I2V / V2V) بناءً على حجة الشرط التي يتم تمريرها إلى `__call__`: | |
| - كلٌّ من `video=None` و`video_latents=None` — نص إلى فيديو خالص. | |
| - `video=&lt;tensor of shape (B, T, C, H, W) in [0, 1] with T = 4n + 1>` — إطارات التكييف قبل VAE؛ يقوم خط الأنابيب بتشفيرها باستخدام VAE. مرّر فيديو بإطار واحد لـ I2V أو مقطع متعدد الإطارات لـ V2V. | |
| - `video_latents=&lt;latent tensor of shape (B, T_latent, C, H_latent, W_latent)>` — متغيرات مُرمّزة مسبقًا بتنسيق FAR (تتخطّى خطوة ترميز VAE). | |
| يعتمد هيكل FAR على النسخة السببية من Wan2.1 التي قدمها [FAR](https://huggingface.co/papers/2503.19325). يتم الاستدلال باستخدام Euler العادي بصيغة متوسط السرعة لكل كتلة دون إعادة الضجيج. يدعم نموذج واحد مُقطّر (distilled) كلًا من T2V / I2V / V2V بشكل مشترك. | |
| يرث هذا النموذج من [*DiffusionPipeline*]. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ). | |
| #### __call__[[diffusers.AnyFlowFARPipeline.__call__]] | |
| ```python | |
| __call__(prompt: typing.Union[str, typing.List[str]] = None, video: typing.Optional[torch.Tensor] = None, video_latents: typing.Optional[torch.Tensor] = None, negative_prompt: typing.Union[str, typing.List[str]] = None, height: int = 480, width: int = 832, num_frames: int = 81, num_inference_steps: int = 50, sigmas: typing.Optional[typing.List[float]] = None, timesteps: typing.Optional[typing.List[float]] = None, guidance_scale: float = 1.0, num_videos_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'np', return_dict: bool = True, attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512, use_mean_velocity: bool = True, use_kv_cache: bool = True, chunk_partition: typing.Optional[typing.List[int]] = None) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow_far.py#L448) | |
| **المعاملات:** | |
| prompt (`str` أو `List[str]`، *اختياري*) : الأمر أو الأوامر التي تُوجّه توليد الفيديو. إذا لم تُعرَّف، فمرّر `prompt_embeds` بدلاً من ذلك. | |
| video (`torch.Tensor`, *اختياري*) : إطارات شرطية قبل VAE ذات الشكل `(B, T, C, H, W)` ضمن `[0, 1]` (`T = 4n + 1`). عند تقديمها، يقوم خط الأنابيب بتشفيرها باستخدام VAE ويُبقي البادئة الكامنة المقابلة ثابتة أثناء أخذ العينات. متعارضة مع `video_latents`. | |
| video_latents (`torch.Tensor`، *اختياري*) : كامنات VAE مُرمّزة مسبقًا في تخطيط FAR `(B, T_latent, C, H_latent, W_latent)`. يتخطى ترميز VAE على جانب خط الأنابيب. متنافٍ مع `video`. | |
| negative_prompt (`str` أو `List[str]`، *اختياري*) : الأمر أو الأوامر التي يجب تجنّبها أثناء توليد الفيديو. يتم تجاهلها عند عدم استخدام التوجيه (`guidance_scale < 1`). | |
| height (`int`، القيمة الافتراضية `480`) : ارتفاع الفيديو المولّد بالبكسلات. | |
| width (`int`، القيمة الافتراضية `832`) : عرض الفيديو المولّد بالبكسلات. | |
| num_frames (`int`، القيمة الافتراضية `81`) : عدد الإطارات في الفيديو المولّد. يجب أن يحقق الشرط `(num_frames - 1) % vae_scale_factor_temporal == 0`. | |
| num_inference_steps (`int`، القيمة الافتراضية `50`) : عدد خطوات إزالة الضوضاء لكل شريحة. تدعم نقاط التفتيش المُقطّرة من AnyFlow-FAR أخذ عينات بأي عدد من الخطوات (1، 2، 4، 8، ...). يتم تجاهل هذا المعامل عند تقديم `sigmas` أو `timesteps`. | |
| sigmas (`List[float]`، *اختياري*) : جدول سيجما مخصص للعينة ذات الخطوات الحرة، ضمن `[0, 1]` ومرتب من الضوضاء إلى النقاء. يحدد الطول قيمة `num_inference_steps` الفعلية؛ حيث يضيف المجدول قيمة سيجما النهائية `0`. | |
| timesteps (`List[float]`، *اختياري*) : جدول خطوات زمنية مخصص للعينة ذات الخطوات الحرة، بنفس وحدات `self.scheduler.timesteps` (أي مُقيّمة بواسطة `num_train_timesteps`). يتعارض مع `sigmas`. | |
| guidance_scale (`float`، القيمة الافتراضية `1.0`) : مقياس التوجيه الحر من التصنيف. نقاط التفتيش الخاصة بـ AnyFlow التي تم إصدارها تدمج CFG في الأوزان أثناء التدريب؛ حافظ على القيمة عند `1.0` ما لم تتطلب نقطة التفتيش خلاف ذلك. | |
| num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية `1`) : عدد مقاطع الفيديو التي سيتم توليدها لكل موجه. | |
| generator (`torch.Generator` أو `List[torch.Generator]`، *اختياري*) : المولّد المستخدم لبذر العينة. | |
| latents (`torch.Tensor`، *اختياري*) : كامنات ضجيج مُولّدة مسبقًا. إذا لم تُقدَّم، تُسحب الكامنات من `generator` المُقدَّم. | |
| prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. إذا لم تُقدَّم، يتم توليد التمثيلات من `prompt`. | |
| negative_prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. | |
| output_type (`str`، *اختياري*، الافتراضي `"np"`) : صيغة الإخراج. واحدة من `"pil"`، `"np"`، `"pt"`، أو `"latent"`. | |
| return_dict (`bool`، *اختياري*، القيمة الافتراضية `True`) : ما إذا كان يجب إرجاع `AnyFlowPipelineOutput` بدلاً من tuple عادي. | |
| attention_kwargs (`dict`، *اختياري*) : قاموس kwargs يُمرَّر إلى `AttentionProcessor` إذا تم تحديده، كما هو معرَّف تحت `self.processor` في [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py). | |
| callback_on_step_end (`Callable`، *اختياري*) : دالة أو `PipelineCallback` تُستدعى في نهاية كل خطوة من خطوات الاستدلال. | |
| callback_on_step_end_tensor_inputs (`List[str]`، *اختياري*، القيمة الافتراضية `["latents"]`) : مدخلات الموترات المُمرَّرة إلى الاستدعاء العكسي. يجب أن تكون مجموعة فرعية من `self._callback_tensor_inputs`. | |
| max_sequence_length (`int`، القيمة الافتراضية `512`) : الحد الأقصى لطول تسلسل مُشفِّر النص. | |
| use_mean_velocity (`bool`، القيمة الافتراضية `True`) : عند تعيين `True`، يُشترط على نموذج خريطة التدفق (flow-map) على كل من خطوة الزمن المصدر `t` وخطوة الزمن الهدف `r` للتنبؤ بسرعة متوسطة. عطّل هذا الخيار لمحاكاة خطوات أويلر الخام (raw Euler stepping). | |
| use_kv_cache (`bool`، القيمة الافتراضية `True`) : إعادة استخدام ذاكرة KV الخاصة بانتباه FAR عبر المقاطع السببية. عطّل هذا الخيار فقط لأغراض التصحيح. | |
| chunk_partition (`List[int]`، *اختياري*) : عدد الإطارات لكل شريحة. القيمة الافتراضية هي `self.transformer.config.chunk_partition` (مطابقة لنقاط التفتيش المصروفة ذات 81 إطارًا). عند تغيير `num_frames`، قم بتوفير `chunk_partition` يكون مجموعها `(num_frames - 1) // vae_scale_factor_temporal + 1`. | |
| **يعيد:** `~AnyFlowPipelineOutput` أو `tuple` | |
| إذا كان `return_dict` هو `True`، يُعاد `AnyFlowPipelineOutput`، وإلا يُعاد `tuple` يكون عنصره الأول هو الفيديو المولّد. | |
| دالة الاستدعاء call لخط الأنابيب pipeline الخاص بالتوليد. | |
| أمثلة: | |
| ```python | |
| >>> import numpy as np | |
| >>> import torch | |
| >>> from diffusers import AnyFlowFARPipeline | |
| >>> from diffusers.utils import export_to_video, load_image | |
| >>> pipe = AnyFlowFARPipeline.from_pretrained( | |
| ... "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", torch_dtype=torch.bfloat16 | |
| ... ).to("cuda") | |
| >>> # Single-frame I2V: wrap the conditioning image as a (1, 1, 3, H, W) tensor in [0, 1]. | |
| >>> first_frame = load_image("path/to/first_frame.png").resize((832, 480)) | |
| >>> arr = np.asarray(first_frame).astype("float32") / 255.0 | |
| >>> context = torch.from_numpy(arr).permute(2, 0, 1).unsqueeze(0).unsqueeze(1).to("cuda") | |
| >>> video = pipe( | |
| ... prompt="a cat walks across a sunlit lawn", | |
| ... video=context, | |
| ... num_inference_steps=4, | |
| ... num_frames=81, | |
| ... ).frames[0] | |
| >>> export_to_video(video, "anyflow_far.mp4", fps=16) | |
| ``` | |
| #### encode_prompt[[diffusers.AnyFlowFARPipeline.encode_prompt]] | |
| ```python | |
| encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow_far.py#L197) | |
| **المعاملات:** | |
| prompt (`str` أو `list[str]`، *اختياري*) : النص الذي سيتم ترميزه | |
| negative_prompt (`str` أو `list[str]`، *اختياري*) : الموجه أو الموجهات التي لا ينبغي توجيه توليد الصورة بها. إذا لم يُعرَّف، يجب تمرير `negative_prompt_embeds` بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا كان `guidance_scale` أقل من `1`). | |
| do_classifier_free_guidance (`bool`، *اختياري*، الافتراضي `True`) : ما إذا كان سيتم استخدام classifier free guidance أم لا. | |
| num_videos_per_prompt (`int`، *اختياري*، القيمة الافتراضية 1) : عدد مقاطع الفيديو التي يجب توليدها لكل موجه. جهاز torch الذي سيتم وضع التضمينات الناتجة عليه | |
| prompt_embeds (`torch.Tensor`، *اختياري*) : تمثيلات نصية مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد تمثيلات النص من معامل الإدخال `prompt`. | |
| negative_prompt_embeds (`torch.Tensor`, *اختياري*) : تمثيلات نصية سالبة مُولّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، *مثلًا* وزن الأوامر. إذا لم تُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال `negative_prompt`. | |
| device : (`torch.device`, *اختياري*): جهاز torch | |
| dtype : (`torch.dtype`, *اختياري*): torch dtype | |
| يقوم بتشفير الموجه إلى حالات مخفية لمشفّر النص. | |
| #### encode_video[[diffusers.AnyFlowFARPipeline.encode_video]] | |
| ```python | |
| encode_video(video: Tensor, height: int, width: int) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_anyflow_far.py#L380) | |
| ترميز فيديو في فضاء البكسلات إلى التخطيط الكامن الخاص بـ AnyFlow. | |
| Mirrors the single-helper convention of other diffusers pipelines (cf. `WanImageToVideoPipeline.encode_image`): wraps preprocessing, VAE encoding, and latent normalization into one call. Output layout is `(B, T_latent, C, H, W)`, which is what the AnyFlow transformer expects for conditioning frames. | |
| ## AnyFlowPipelineOutput[[diffusers.pipelines.anyflow.pipeline_output.AnyFlowPipelineOutput]] | |
| #### diffusers.pipelines.anyflow.pipeline_output.AnyFlowPipelineOutput[[diffusers.pipelines.anyflow.pipeline_output.AnyFlowPipelineOutput]] | |
| ```python | |
| diffusers.pipelines.anyflow.pipeline_output.AnyFlowPipelineOutput(frames: Tensor) | |
| ``` | |
| [المصدر](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/anyflow/pipeline_output.py#L23) | |
| **المعاملات:** | |
| frames (`torch.Tensor` أو `np.ndarray` أو list[list[PIL.Image.Image]]) : قائمة من مخرجات الفيديو - يمكن أن تكون قائمة متداخلة بطول `batch_size,` حيث تحتوي كل قائمة فرعية على تسلسلات من صور PIL منزوعة الضوضاء بطول `num_frames.` كما يمكن أن تكون مصفوفة NumPy أو متجه Torch بشكل `(batch_size, num_frames, channels, height, width)`. | |
| فئة الإخراج لخطوط أنابيب AnyFlow. | |
Xet Storage Details
- Size:
- 40.5 kB
- Xet hash:
- 5b2630631fc6826f172fb1d03e4586cbc8d3a094ed8af552d5f2f6216ef834ad
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.