Diffusers documentation

Cosmos

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Cosmos

منصة نموذج الأساس الكوني Cosmos للذكاء الاصطناعي الفيزيائي من NVIDIA.

يتطلب الذكاء الاصطناعي المادي أن يُدرَّب رقميًا أولًا. فهو يحتاج إلى توأم رقمي لنفسه، وهو نموذج السياسة، وتوأم رقمي للعالم، وهو نموذج العالم. في هذه الورقة، نقدم منصة نماذج الأساس للعالم (Cosmos World Foundation Model Platform) لمساعدة المطورين على بناء نماذج عالم مخصصة لإعدادات الذكاء الاصطناعي المادي الخاصة بهم. نضع نموذج الأساس للعالم كنموذج عالم ذي استخدام عام يمكن ضبطه بدقة ليصبح نموذج عالم مخصص للتطبيقات اللاحقة. تغطي منصتنا خط أنابيب لفرز الفيديو، ونماذج أساس للعالم مُدرَّبة مسبقًا، وأمثلة على التدريب اللاحق لنماذج الأساس للعالم المُدرَّبة مسبقًا، ومُرمِّزات رموز الفيديو. وللمساعدة في حل أكثر مشاكل مجتمعنا إلحاحًا، نجعل منصتنا مفتوحة المصدر ونماذجنا مفتوحة الأوزان مع تراخيص سائبة متاحة عبر https://github.com/NVIDIA/Cosmos.

تأكد من الاطلاع على دليل المجدولين لمعرفة كيفية استكشاف التوازن بين سرعة المجدول وجودة النتائج، واطّلع على قسم إعادة استخدام المكونات عبر خطوط الأنابيب لمعرفة كيفية تحميل نفس المكونات بكفاءة في خطوط أنابيب متعددة.

الاستخدام الأساسي

import torch
from diffusers import Cosmos2_5_PredictBasePipeline
from diffusers.utils import export_to_video

model_id = "nvidia/Cosmos-Predict2.5-2B"
pipe = Cosmos2_5_PredictBasePipeline.from_pretrained(
    model_id, revision="diffusers/base/post-trained", dtype=torch.bfloat16
)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

prompt = "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow advance of traffic through the frosty city corridor."
negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."

output = pipe(
    image=None,
    video=None,
    prompt=prompt,
    negative_prompt=negative_prompt,
    num_frames=93,
    generator=torch.Generator().manual_seed(1),
).frames[0]
export_to_video(output, "text2world.mp4", fps=16)

Cosmos2_5_TransferPipeline

فئة diffusers.Cosmos2_5_TransferPipeline

< >

( text_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: AutoTokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLWanscheduler: UniPCMultistepSchedulercontrolnet: CosmosControlNetModelsafety_checker: typing.Optional[diffusers.pipelines.cosmos.pipeline_cosmos2_5_transfer.CosmosSafetyChecker] = None )

المعاملات

  • text_encoder (Qwen2_5_VLForConditionalGeneration) — مُشفِّر نص مُجمَّد. يستخدم Cosmos Transfer2.5 مُشفِّر Qwen2.5 VL.
  • tokenizer (AutoTokenizer) — المُجزِّئ المرتبط بمُشفِّر Qwen2.5 VL.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (UniPCMultistepScheduler) — جدولة تُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLWan) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.
  • controlnet (CosmosControlNetModel) — ControlNet المستخدم لتكييف التوليد على مدخلات التحكم.

خط أنابيب لنموذج Cosmos Transfer2.5، يدعم الاستدلال التلقائي التتابعي.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( controls: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], typing.List[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]]]controls_conditioning_scale: typing.Union[float, typing.List[float]] = 1.0prompt: typing.Union[str, typing.List[str], NoneType] = Nonenegative_prompt: typing.Union[str, typing.List[str]] = 'The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality.'height: int = 704width: typing.Optional[int] = Nonenum_frames: typing.Optional[int] = Nonenum_frames_per_chunk: int = 93num_inference_steps: int = 36guidance_scale: float = 3.0num_videos_per_prompt: int = 1generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: typing.Optional[str] = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: typing.List[str] = ['latents']max_sequence_length: int = 512conditional_frame_timestep: float = 0.1num_ar_conditional_frames: typing.Optional[int] = 1num_ar_latent_conditional_frames: typing.Optional[int] = None ) → ~CosmosPipelineOutput or tuple

المعاملات

  • controls (PipelineImageInput, List[PipelineImageInput]) — صورة أو فيديو إدخال للتحكم تُستخدم بواسطة ControlNet.
  • controls_conditioning_scale (float أو List[float]، اختياري، القيمة الافتراضية 1.0) — معاملات المقياس لمخرجات ControlNet. يتم بث قيمة float واحدة إلى جميع كتل التحكم.
  • prompt (str أو List[str]، اختياري) — الموجّه أو الموجّهات التي تُوجّه عملية التوليد. مطلوب ما لم يُقدَّم prompt_embeds.
  • negative_prompt (str أو List[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int، القيمة الافتراضية 704) — ارتفاع الصورة المولّدة بالبكسل.
  • width (int, اختياري) — عرض الصورة المولّدة بالبكسل. إذا لم يُقدَّم، فسيتم تحديده بناءً على نسبة أبعاد الإدخال والارتفاع المُقدَّم.
  • num_frames (int, اختياري) — عدد الإطارات المُخرَجة. القيمة الافتراضية هي None لإخراج نفس عدد الإطارات الموجودة في مدخلات controls.
  • num_frames_per_chunk (int, اختياري، القيمة الافتراضية 93) — عدد الإطارات المولَّدة لكل كتلة توليد ذاتي. عندما يتجاوز إجمالي عدد الإطارات هذه القيمة، يتم تقسيم التوليد إلى عدة كتل باستخدام نهج النافذة المنزلقة.
  • num_inference_steps (int، القيمة الافتراضية 36) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 3.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو List[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كعوب ضجيج مُولّدة مسبقًا ومُسحوبة من توزيع غاوسي، تُستخدم كمدخلات. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كعوب latents عن طريق السحب باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosPipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (List, اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين سوى المتغيرات المدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.
  • conditional_frame_timestep (float، اختياري، القيمة الافتراضية 0.1) — قيمة الخطوة الزمنية المستخدمة للإطارات الشرطية أثناء إزالة الضوضاء. يجب أن تكون ضمن الفترة [0, 1].
  • num_ar_conditional_frames (int, اختياري, القيمة الافتراضية هي 1) — عدد الإطارات التي تُشترط على حلقات الاستدلال اللاحقة في الاستدلال التلقائي التتابعي، أي للقطعة الثانية وما يليها. يُستخدم فقط إذا كانت num_ar_latent_conditional_frames قيمة None.

    يُستخدم هذا فقط عند تنفيذ الاستدلال التلقائي التتابعي، أي عندما يكون عدد الإطارات في controls أكبر من num_frames_per_chunk

  • num_ar_latent_conditional_frames (int, اختياري) — عدد الإطارات الكامنة التي تُشترط على حلقات الاستدلال اللاحقة في الاستدلال التلقائي التتابعي، أي للقطعة الثانية وما بعدها. يُستخدم فقط إذا كانت num_ar_conditional_frames قيمة None.

    يُستخدم هذا فقط عند تنفيذ الاستدلال التلقائي التتابعي، أي عندما يكون عدد الإطارات في controls أكبر من num_frames_per_chunk

يعيد

~CosmosPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosPipelineOutput، وإلا يُعاد tuple حيث العنصر الأول هو قائمة بالصور المولّدة والعنصر الثاني هو قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

controls تتحكم في عملية التكييف عبر ControlNet. يُفترض أن تكون عناصر التحكم مُعالجة مسبقًا، على سبيل المثال تكون خرائط الحواف محسوبة مسبقًا.

سيؤدي تعيين num_frames إلى تقييد إجمالي عدد الإطارات المُخرَجة، أما إذا لم يُقدَّم أو تم تعيينه إلى None (الافتراضي) فسيطابق عدد الإطارات المُخرَجة عدد إطارات الإدخال controls.

يُؤيَّد الاستدلال التلقائي التتابعي، ولذلك تُستخدم نافذة منزلقة من num_frames_per_chunk إطارات في كل حلقة إزالة الضوضاء. بالإضافة إلى ذلك، عند تنفيذ الاستدلال التلقائي التتابعي، تُستخدم الإطارات السابقة num_ar_latent_conditional_frames أو num_ar_conditional_frames لتكييف حلقات الاستدلال لإزالة الضوضاء التالية.

أمثلة:

>>> import cv2
>>> import numpy as np
>>> from PIL import Image
>>> import torch
>>> from diffusers import Cosmos2_5_TransferPipeline, AutoModel
>>> from diffusers.utils import export_to_video, load_video

>>> model_id = "nvidia/Cosmos-Transfer2.5-2B"
>>> # Load a Transfer2.5 controlnet variant (edge, depth, seg, or blur)
>>> controlnet = AutoModel.from_pretrained(
...     model_id, revision="diffusers/controlnet/general/edge", torch_dtype=torch.bfloat16
... )
>>> pipe = Cosmos2_5_TransferPipeline.from_pretrained(
...     model_id, controlnet=controlnet, revision="diffusers/general", torch_dtype=torch.bfloat16
... )
>>> pipe = pipe.to("cuda")

>>> # Video2World with edge control: Generate video guided by edge maps extracted from input video.
>>> prompt = (
...     "The video is a demonstration of robotic manipulation, likely in a laboratory or testing environment. It"
...     "features two robotic arms interacting with a piece of blue fabric. The setting is a room with a beige"
...     "couch in the background, providing a neutral backdrop for the robotic activity. The robotic arms are"
...     "positioned on either side of the fabric, which is placed on a yellow cushion. The left robotic arm is"
...     "white with a black gripper, while the right arm is black with a more complex, articulated gripper. At the"
...     "beginning, the fabric is laid out on the cushion. The left robotic arm approaches the fabric, its gripper"
...     "opening and closing as it positions itself. The right arm remains stationary initially, poised to assist."
...     "As the video progresses, the left arm grips the fabric, lifting it slightly off the cushion. The right arm"
...     "then moves in, its gripper adjusting to grasp the opposite side of the fabric. Both arms work in"
...     "coordination, lifting and holding the fabric between them. The fabric is manipulated with precision,"
...     "showcasing the dexterity and control of the robotic arms. The camera remains static throughout, focusing"
...     "on the interaction between the robotic arms and the fabric, allowing viewers to observe the detailed"
...     "movements and coordination involved in the task."
... )
>>> negative_prompt = (
...     "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, "
...     "over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, "
...     "underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky "
...     "movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, "
...     "fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. "
...     "Overall, the video is of poor quality."
... )
>>> input_video = load_video(
...     "https://github.com/nvidia-cosmos/cosmos-transfer2.5/raw/refs/heads/main/assets/robot_example/robot_input.mp4"
... )
>>> num_frames = 93

>>> # Extract edge maps from the input video using Canny edge detection
>>> edge_maps = [
...     cv2.Canny(cv2.cvtColor(np.array(frame.convert("RGB")), cv2.COLOR_RGB2BGR), 100, 200)
...     for frame in input_video[:num_frames]
... ]
>>> edge_maps = np.stack(edge_maps)[None]  # (T, H, W) -> (1, T, H, W)
>>> controls = torch.from_numpy(edge_maps).expand(3, -1, -1, -1)  # (1, T, H, W) -> (3, T, H, W)
>>> controls = [Image.fromarray(x.numpy()) for x in controls.permute(1, 2, 3, 0)]
>>> export_to_video(controls, "edge_controlled_video_edge.mp4", fps=30)

>>> # Transfer inference with controls.
>>> video = pipe(
...     controls=controls,
...     controls_conditioning_scale=1.0,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     num_frames=num_frames,
... ).frames[0]
>>> export_to_video(video, "edge_controlled_video.mp4", fps=30)

encode_prompt

< >

( prompt: typing.Union[str, typing.List[str]]negative_prompt: typing.Union[str, typing.List[str], NoneType] = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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

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

Cosmos2_5_PredictBasePipeline

فئة diffusers.Cosmos2_5_PredictBasePipeline

< >

( text_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: AutoTokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLWanscheduler: UniPCMultistepSchedulersafety_checker: CosmosSafetyChecker = None )

المعاملات

  • text_encoder (Qwen2_5_VLForConditionalGeneration) — مُشفِّر نص ثابت. يستخدم Cosmos Predict2.5 مُشفِّر Qwen2.5 VL.
  • tokenizer (AutoTokenizer) — المُجزِّئ المرتبط بمُشفِّر Qwen2.5 VL.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (UniPCMultistepScheduler) — جدولة تُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLWan) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

خط أنابيب لنموذج Cosmos Predict2.5 الأساسي.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Nonevideo: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = Noneprompt: str | list[str] | None = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 704width: int = 1280num_frames: int = 93num_inference_steps: int = 36guidance_scale: float = 7.0num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512conditional_frame_timestep: float = 0.0001num_latent_conditional_frames: int = 2 ) → ~CosmosPipelineOutput or tuple

المعاملات

  • image (PIL.Image.Image، np.ndarray، torch.Tensor، اختياري) — صورة واحدة اختيارية لتكييف Image2World. يجب أن تكون None عند تقديم video.
  • video (list[PIL.Image.Image], np.ndarray, torch.Tensor, اختياري) — فيديو إدخال اختياري لتكييف Video2World. يجب أن يكون None عند تقديم image.
  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي تُوجّه عملية التوليد. مطلوب ما لم يُقدَّم prompt_embeds.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int، القيمة الافتراضية 704) — ارتفاع الصورة المولّدة بالبكسل.
  • width (int، القيمة الافتراضية 1280) — عرض الصورة المولّدة بالبكسل.
  • num_frames (int، القيمة الافتراضية 93) — عدد الإطارات الناتجة. استخدم 93 لتوليد العالم (الفيديو)؛ اضبطها على 1 لإرجاع إطار واحد.
  • num_inference_steps (int، القيمة الافتراضية 35) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 7.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosPipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (List, اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين سوى المتغيرات المدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.
  • num_latent_conditional_frames (int، القيمة الافتراضية 2) — عدد الإطارات الشرطية الكامنة المستخدمة لتكييف Video2World. يتم حساب عدد إطارات البكسل المستخرجة من الفيديو المدخل على النحو التالي 4 * (num_latent_conditional_frames - 1) + 1. اضبطه على 1 للحصول على سلوك مشابه لـ Image2World (تكييف بإطار واحد).
  • conditional_frame_timestep (float، اختياري، القيمة الافتراضية 0.0001) — قيمة الخطوة الزمنية المستخدمة للإطارات الشرطية أثناء إزالة الضوضاء.

يعيد

~CosmosPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosPipelineOutput، وإلا يُعاد tuple حيث العنصر الأول هو قائمة بالصور المولّدة والعنصر الثاني هو قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

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

  • Text2World: image=None، video=None، تم توفير prompt. يولّد مقطعًا من العالم.
  • Image2World: تم توفير image، video=None، وتم توفير prompt. شروط على إطار واحد.
  • Video2World: يُوفَّر video، وimage=None، ويُوفَّر prompt. شروط على مقطع الإدخال.

اضبط num_frames=93 (الافتراضي) لإنتاج فيديو عالمي، أو num_frames=1 لإنتاج إطار صورة واحد (كما في “*2Image mode” أعلاه).

تتبع المخرجات output_type (على سبيل المثال، يعيد "pil" قائمة من num_frames صور PIL لكل موجه).

أمثلة:

>>> import torch
>>> from diffusers import Cosmos2_5_PredictBasePipeline
>>> from diffusers.utils import export_to_video, load_image, load_video

>>> model_id = "nvidia/Cosmos-Predict2.5-2B"
>>> pipe = Cosmos2_5_PredictBasePipeline.from_pretrained(
...     model_id, revision="diffusers/base/post-trained", torch_dtype=torch.bfloat16
... )
>>> pipe = pipe.to("cuda")

>>> # Common negative prompt reused across modes.
>>> negative_prompt = (
...     "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, "
...     "over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, "
...     "underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky "
...     "movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, "
...     "fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. "
...     "Overall, the video is of poor quality."
... )

>>> # Text2World: generate a 93-frame world video from text only.
>>> prompt = (
...     "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights "
...     "cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh "
...     "lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet "
...     "reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. "
...     "The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow "
...     "advance of traffic through the frosty city corridor."
... )
>>> video = pipe(
...     image=None,
...     video=None,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     num_frames=93,
...     generator=torch.Generator().manual_seed(1),
... ).frames[0]
>>> export_to_video(video, "text2world.mp4", fps=16)

>>> # Image2World: condition on a single image and generate a 93-frame world video.
>>> prompt = (
...     "A high-definition video captures the precision of robotic welding in an industrial setting. "
...     "The first frame showcases a robotic arm, equipped with a welding torch, positioned over a large metal structure. "
...     "The welding process is in full swing, with bright sparks and intense light illuminating the scene, creating a vivid "
...     "display of blue and white hues. A significant amount of smoke billows around the welding area, partially obscuring "
...     "the view but emphasizing the heat and activity. The background reveals parts of the workshop environment, including a "
...     "ventilation system and various pieces of machinery, indicating a busy and functional industrial workspace. As the video "
...     "progresses, the robotic arm maintains its steady position, continuing the welding process and moving to its left. "
...     "The welding torch consistently emits sparks and light, and the smoke continues to rise, diffusing slightly as it moves upward. "
...     "The metal surface beneath the torch shows ongoing signs of heating and melting. The scene retains its industrial ambiance, with "
...     "the welding sparks and smoke dominating the visual field, underscoring the ongoing nature of the welding operation."
... )
>>> image = load_image(
...     "https://media.githubusercontent.com/media/nvidia-cosmos/cosmos-predict2.5/refs/heads/main/assets/base/robot_welding.jpg"
... )
>>> video = pipe(
...     image=image,
...     video=None,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     num_frames=93,
...     generator=torch.Generator().manual_seed(1),
... ).frames[0]
>>> export_to_video(video, "image2world.mp4", fps=16)

>>> # Video2World: condition on an input clip and predict a 93-frame world video.
>>> prompt = (
...     "The video opens with an aerial view of a large-scale sand mining construction operation, showcasing extensive piles "
...     "of brown sand meticulously arranged in parallel rows. A central water channel, fed by a water pipe, flows through the "
...     "middle of these sand heaps, creating ripples and movement as it cascades down. The surrounding area features dense green "
...     "vegetation on the left, contrasting with the sandy terrain, while a body of water is visible in the background on the right. "
...     "As the video progresses, a piece of heavy machinery, likely a bulldozer, enters the frame from the right, moving slowly along "
...     "the edge of the sand piles. This machinery's presence indicates ongoing construction work in the operation. The final frame "
...     "captures the same scene, with the water continuing its flow and the bulldozer still in motion, maintaining the dynamic yet "
...     "steady pace of the construction activity."
... )
>>> input_video = load_video(
...     "https://github.com/nvidia-cosmos/cosmos-predict2.5/raw/refs/heads/main/assets/base/sand_mining.mp4"
... )
>>> video = pipe(
...     image=None,
...     video=input_video,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     num_frames=93,
...     generator=torch.Generator().manual_seed(1),
... ).frames[0]
>>> export_to_video(video, "video2world.mp4", fps=16)

>>> # To produce an image instead of a world (video) clip, set num_frames=1 and
>>> # save the first frame: pipe(..., num_frames=1).frames[0][0].

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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

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

CosmosTextToWorldPipeline

فئة diffusers.CosmosTextToWorldPipeline

< >

( text_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLCosmosscheduler: EDMEulerSchedulersafety_checker: CosmosSafetyChecker = None )

المعاملات

  • text_encoder (T5EncoderModel) — مُشفِّر نص ثابت. يستخدم Cosmos T5؛ وتحديداً النسخة t5-11b.
  • tokenizer (T5TokenizerFast) — مُقسِّم من فئة T5Tokenizer.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLCosmos) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

خط أنابيب لتوليد النص إلى عالم باستخدام Cosmos Predict1.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 704width: int = 1280num_frames: int = 121num_inference_steps: int = 36guidance_scale: float = 7.0fps: int = 30num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~CosmosPipelineOutput or tuple

المعاملات

  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int، القيمة الافتراضية 720) — ارتفاع الصورة المولّدة بالبكسل.
  • width (int، القيمة الافتراضية 1280) — عرض الصورة المولّدة بالبكسل.
  • num_frames (int، القيمة الافتراضية 121) — عدد الإطارات في الفيديو المولّد.
  • num_inference_steps (int، القيمة الافتراضية 36) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 7.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • fps (int، القيمة الافتراضية 30) — عدد الإطارات في الثانية للفيديو المولّد.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosPipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (list، اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين متغيرات غير مدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.

يعيد

~CosmosPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosPipelineOutput، وإلا يُعاد tuple حيث العنصر الأول هو قائمة بالصور المولّدة والعنصر الثاني هو قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

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

أمثلة:

>>> import torch
>>> from diffusers import CosmosTextToWorldPipeline
>>> from diffusers.utils import export_to_video

>>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Text2World"
>>> pipe = CosmosTextToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A sleek, humanoid robot stands in a vast warehouse filled with neatly stacked cardboard boxes on industrial shelves. The robot's metallic body gleams under the bright, even lighting, highlighting its futuristic design and intricate joints. A glowing blue light emanates from its chest, adding a touch of advanced technology. The background is dominated by rows of boxes, suggesting a highly organized storage system. The floor is lined with wooden pallets, enhancing the industrial setting. The camera remains static, capturing the robot's poised stance amidst the orderly environment, with a shallow depth of field that keeps the focus on the robot while subtly blurring the background for a cinematic effect."

>>> output = pipe(prompt=prompt).frames[0]
>>> export_to_video(output, "output.mp4", fps=30)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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

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

CosmosVideoToWorldPipeline

فئة diffusers.CosmosVideoToWorldPipeline

< >

( text_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLCosmosscheduler: EDMEulerSchedulersafety_checker: CosmosSafetyChecker = None )

المعاملات

  • text_encoder (T5EncoderModel) — مُشفِّر نص ثابت. يستخدم Cosmos T5؛ وتحديداً النسخة t5-11b.
  • tokenizer (T5TokenizerFast) — مُقسِّم من فئة T5Tokenizer.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLCosmos) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

خط أنابيب لتوليد العالم من الصورة وتوليد العالم من الفيديو باستخدام Cosmos Predict-1.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonevideo: list = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 704width: int = 1280num_frames: int = 121num_inference_steps: int = 36guidance_scale: float = 7.0input_frames_guidance: bool = Falseaugment_sigma: float = 0.001fps: int = 30num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~CosmosPipelineOutput or tuple

المعاملات

  • image (PIL.Image.Image، np.ndarray، torch.Tensor، اختياري) — الصورة التي سيتم استخدامها كمدخل شرطي لتوليد الفيديو.
  • video (list[PIL.Image.Image], np.ndarray, torch.Tensor, اختياري) — الفيديو الذي سيُستخدم كمدخل شرطي لتوليد الفيديو.
  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int، القيمة الافتراضية 720) — ارتفاع الصورة المولّدة بالبكسل.
  • width (int، القيمة الافتراضية 1280) — عرض الصورة المولّدة بالبكسل.
  • num_frames (int، القيمة الافتراضية 121) — عدد الإطارات في الفيديو المولّد.
  • num_inference_steps (int، القيمة الافتراضية 36) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 7.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • input_frames_guidance (bool، اختياري، القيمة الافتراضية False) — ما إذا كان سيتم تطبيق التوجيه على إطارات الإدخال الشرطية.
  • augment_sigma (float، اختياري، القيمة الافتراضية 0.001) — قيمة سيغما المستخدمة لتعزيز الكامنات الشرطية أثناء إزالة الضوضاء.
  • fps (int، القيمة الافتراضية 30) — عدد الإطارات في الثانية للفيديو المولّد.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosPipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (list، اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين متغيرات غير مدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.

يعيد

~CosmosPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosPipelineOutput، وإلا يُعاد tuple حيث العنصر الأول هو قائمة بالصور المولّدة والعنصر الثاني هو قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

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

أمثلة:

التحكم بالصور:

>>> import torch
>>> from diffusers import CosmosVideoToWorldPipeline
>>> from diffusers.utils import export_to_video, load_image

>>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Video2World"
>>> pipe = CosmosVideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "The video depicts a long, straight highway stretching into the distance, flanked by metal guardrails. The road is divided into multiple lanes, with a few vehicles visible in the far distance. The surrounding landscape features dry, grassy fields on one side and rolling hills on the other. The sky is mostly clear with a few scattered clouds, suggesting a bright, sunny day."
>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input.jpg"
... )

>>> video = pipe(image=image, prompt=prompt).frames[0]
>>> export_to_video(video, "output.mp4", fps=30)

شرط الفيديو:

>>> import torch
>>> from diffusers import CosmosVideoToWorldPipeline
>>> from diffusers.utils import export_to_video, load_video

>>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Video2World"
>>> pipe = CosmosVideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.transformer = torch.compile(pipe.transformer)
>>> pipe.to("cuda")

>>> prompt = "The video depicts a winding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region."
>>> video = load_video(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4"
... )[:21]  # This example uses only the first 21 frames

>>> video = pipe(video=video, prompt=prompt).frames[0]
>>> export_to_video(video, "output.mp4", fps=30)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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

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

Cosmos2TextToImagePipeline

فئة diffusers.Cosmos2TextToImagePipeline

< >

( text_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteSchedulersafety_checker: CosmosSafetyChecker = None )

المعاملات

  • text_encoder (T5EncoderModel) — مُشفِّر نص ثابت. يستخدم Cosmos T5؛ وتحديداً النسخة t5-11b.
  • tokenizer (T5TokenizerFast) — مُقسِّم من فئة T5Tokenizer.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLWan) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

خط أنابيب لتوليد الصور من النص باستخدام Cosmos Predict2.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 768width: int = 1360num_inference_steps: int = 35guidance_scale: float = 7.0num_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~CosmosImagePipelineOutput or tuple

المعاملات

  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int, defaults to 768) — The height in pixels of the generated image.
  • width (int، القيمة الافتراضية 1360) — عرض الصورة المولّدة بالبكسل.
  • num_inference_steps (int، القيمة الافتراضية 35) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 7.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • num_images_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosImagePipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (list، اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين متغيرات غير مدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.

يعيد

~CosmosImagePipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosImagePipelineOutput، وإلا يُعاد tuple حيث يكون العنصر الأول قائمة بالصور المولّدة والعنصر الثاني قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

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

أمثلة:

>>> import torch
>>> from diffusers import Cosmos2TextToImagePipeline

>>> # Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image
>>> model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
>>> pipe = Cosmos2TextToImagePipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess."
>>> negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."

>>> output = pipe(
...     prompt=prompt, negative_prompt=negative_prompt, generator=torch.Generator().manual_seed(1)
... ).images[0]
>>> output.save("output.png")

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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_images_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

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

Cosmos2VideoToWorldPipeline

فئة diffusers.Cosmos2VideoToWorldPipeline

< >

( text_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: CosmosTransformer3DModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteSchedulersafety_checker: CosmosSafetyChecker = None )

المعاملات

  • text_encoder (T5EncoderModel) — مُشفِّر نص ثابت. يستخدم Cosmos T5؛ وتحديداً النسخة t5-11b.
  • tokenizer (T5TokenizerFast) — مُقسِّم من فئة T5Tokenizer.
  • transformer (CosmosTransformer3DModel) — نموذج Transformer مشروط لإزالة الضوضاء من الكامنات المُرمّزة للصور.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLWan) — نموذج الترميز التبايني التلقائي (VAE) لتشفير وفك تشفير مقاطع الفيديو إلى تمثيلات كامنة ومنها.

خط أنابيب لتوليد العالم من الفيديو باستخدام Cosmos Predict2.

يرث هذا النموذج من DiffusionPipeline. راجع توثيق الفئة الأصلية لمعرفة الطرق العامة المُنفَّذة لجميع خطوط الأنابيب (التنزيل، الحفظ، التشغيل على جهاز معين، إلخ).

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonevideo: list = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 704width: int = 1280num_frames: int = 93num_inference_steps: int = 35guidance_scale: float = 7.0fps: int = 16num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512sigma_conditioning: float = 0.0001 ) → ~CosmosPipelineOutput or tuple

المعاملات

  • image (PIL.Image.Image، np.ndarray، torch.Tensor، اختياري) — الصورة التي سيتم استخدامها كمدخل شرطي لتوليد الفيديو.
  • video (list[PIL.Image.Image], np.ndarray, torch.Tensor, اختياري) — الفيديو الذي سيُستخدم كمدخل شرطي لتوليد الفيديو.
  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً من ذلك. يتم تجاهله عند عدم استخدام التوجيه (أي يتم تجاهله إذا لم يكن guidance_scale أكبر من 1).
  • height (int، القيمة الافتراضية 704) — ارتفاع الصورة المولّدة بالبكسل.
  • width (int، القيمة الافتراضية 1280) — عرض الصورة المولّدة بالبكسل.
  • num_frames (int، القيمة الافتراضية 93) — عدد الإطارات في الفيديو المولّد.
  • num_inference_steps (int، القيمة الافتراضية 35) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • guidance_scale (float، القيمة الافتراضية 7.0) — مقياس التوجيه كما هو معرّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1.
  • fps (int، القيمة الافتراضية 16) — عدد الإطارات في الثانية للفيديو المولّد.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد الصور التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، يتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الصورة المولّدة. اختر بين PIL.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع CosmosPipelineOutput بدلاً من tuple عادي.
  • callback_on_step_end (Callable، PipelineCallback، MultiPipelineCallbacks، اختياري) — دالة أو فئة فرعية من PipelineCallback أو MultiPipelineCallbacks تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال، مع الحُجج التالية: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). ستتضمن callback_kwargs قائمة بجميع المصفوفات كما حددتها callback_on_step_end_tensor_inputs.
  • callback_on_step_end_tensor_inputs (list، اختياري) — قائمة مدخلات المصفوفات (tensors) لدالة callback_on_step_end. سيتم تمرير المصفوفات المحددة في القائمة كحجة callback_kwargs. لن تتمكن من تضمين متغيرات غير مدرجة في خاصية ._callback_tensor_inputs لفئة خط الأنابيب (pipeline) الخاص بك.
  • max_sequence_length (int، القيمة الافتراضية 512) — الحد الأقصى لعدد الرموز في الاستعلام. إذا تجاوز الاستعلام هذا الطول، فسيتم اقتطاعه. وإذا كان الاستعلام أقصر من هذا الطول، فسيتم ملؤه.
  • sigma_conditioning (float) — القيمة الافتراضية 0.0001 — قيمة sigma المستخدمة لتقليص كامنات الشروط (conditioning latents). من الأفضل نظريا عدم تغييرها أو ضبطها على قيمة صغيرة قريبة من الصفر.

يعيد

~CosmosPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد CosmosPipelineOutput، وإلا يُعاد tuple حيث العنصر الأول هو قائمة بالصور المولّدة والعنصر الثاني هو قائمة من قيم bool تُشير إلى ما إذا كانت الصورة المولّدة المقابلة تحتوي على محتوى “غير آمن للعمل” (nsfw).

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

أمثلة:

>>> import torch
>>> from diffusers import Cosmos2VideoToWorldPipeline
>>> from diffusers.utils import export_to_video, load_image

>>> # Available checkpoints: nvidia/Cosmos-Predict2-2B-Video2World, nvidia/Cosmos-Predict2-14B-Video2World
>>> model_id = "nvidia/Cosmos-Predict2-2B-Video2World"
>>> pipe = Cosmos2VideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess."
>>> negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yellow-scrubber.png"
... )

>>> video = pipe(
...     image=image, prompt=prompt, negative_prompt=negative_prompt, generator=torch.Generator().manual_seed(1)
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=16)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 512device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

المعاملات

  • 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

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

CosmosPipelineOutput

فئة diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput

< >

( frames: Tensor )

المعاملات

  • frames (torch.Tensor أو np.ndarray أو قائمة[قائمة[PIL.Image.Image]]) — قائمة من مخرجات الفيديو - يمكن أن تكون قائمة متداخلة بطول batch_size, حيث تحتوي كل قائمة فرعية على سلاسل صور PIL منزوعة الضوضاء بطول num_frames. كما يمكن أن تكون مصفوفة NumPy أو متجه Torch بشكل (batch_size, num_frames, channels, height, width).

فئة الإخراج لخطوط أنابيب Cosmos من أي شيء إلى العالم/الفيديو.

CosmosImagePipelineOutput

فئة diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput

< >

( images: list[PIL.Image.Image] | numpy.ndarray )

المعاملات

  • images (list[PIL.Image.Image] أو np.ndarray) — قائمة من صور PIL منزوعة الضوضاء بطول batch_size أو مصفوفة numpy بأبعاد (batch_size, height, width, num_channels). تمثل صور PIL أو مصفوفة numpy الصور منزوعة الضوضاء من خط أنابيب الانتشار.

فئة الإخراج لخطوط أنابيب Cosmos من أي شيء إلى صورة.

Update on GitHub