Diffusers documentation

LTX-Video

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

LoRA MPS

LTX-Video

LTX-Video هو محوّل انتشار مصمم لتوليد فيديوهات عالية الدقة بسرعة وفي الوقت الفعلي من النصوص والصور. الميزة الرئيسية في LTX-Video هي Video-VAE. تتمتع Video-VAE بنسبة ضغط أعلى من البكسل إلى الكمون (1:192) مما يتيح معالجة بيانات الفيديو بكفاءة أكبر وسرعة توليد أسرع. لدعم التفاصيل الدقيقة ومنع فقدانها أثناء التوليد، يقوم فك تشفير Video-VAE بتحويل الكمون إلى بكسل و خطوة إزالة الضوضاء الأخيرة.

يمكنك العثور على جميع نقاط التفتيش الأصلية لنموذج LTX-Video تحت منظمة Lightricks.

انقر على نماذج LTX-Video في الشريط الجانبي الأيمن لمزيد من الأمثلة على مهام توليد الفيديو الأخرى.

يُبيّن المثال أدناه كيفية توليد فيديو مُحسَّن للذاكرة أو لسرعة الاستدلال.

الذاكرة
سرعة الاستدلال

راجع دليل تقليل استهلاك الذاكرة لمزيد من التفاصيل حول تقنيات توفير الذاكرة المختلفة.

يتطلب نموذج LTX-Video أدناه حوالي 10 جيجابايت من ذاكرة VRAM.

import torch
from diffusers import LTXPipeline, AutoModel
from diffusers.hooks import apply_group_offloading
from diffusers.utils import export_to_video

# fp8 layerwise weight-casting
transformer = AutoModel.from_pretrained(
    "Lightricks/LTX-Video",
    subfolder="transformer",
    dtype=torch.bfloat16
)
transformer.enable_layerwise_casting(
    storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16
)

pipeline = LTXPipeline.from_pretrained("Lightricks/LTX-Video", transformer=transformer, dtype=torch.bfloat16)

# group-offloading
onload_device = torch.device("cuda")
offload_device = torch.device("cpu")
pipeline.transformer.enable_group_offload(onload_device=onload_device, offload_device=offload_device, offload_type="leaf_level", use_stream=True)
apply_group_offloading(pipeline.text_encoder, onload_device=onload_device, offload_type="block_level", num_blocks_per_group=2)
apply_group_offloading(pipeline.vae, onload_device=onload_device, offload_type="leaf_level")

prompt = """
A woman with long brown hair and light skin smiles at another woman with long blonde hair.
The woman with brown hair wears a black jacket and has a small, barely noticeable mole on her right cheek.
The camera angle is a close-up, focused on the woman with brown hair's face. The lighting is warm and 
natural, likely from the setting sun, casting a soft glow on the scene. The scene appears to be real-life footage
"""
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

video = pipeline(
    prompt=prompt,
    negative_prompt=negative_prompt,
    width=768,
    height=512,
    num_frames=161,
    decode_timestep=0.03,
    decode_noise_scale=0.025,
    num_inference_steps=50,
).frames[0]
export_to_video(video, "output.mp4", fps=24)

ملاحظات

  • راجع الإعدادات الموصى بها التالية للتوليد من مستودع LTX-Video.

    • النوع الموصى به لـ dtype في المحوّل (transformer) وVAE ومشفّر النص هو torch.bfloat16. كما يمكن أن يكون VAE ومشفّر النص من النوع torch.float32 أو torch.float16.
    • لإصدارات LTX-Video المُصفاة بالتوجيه، اضبط guidance_scale على 1.0. أما guidance_scale لأي نموذج آخر فيجب ضبطه على قيمة أعلى، مثل 5.0، لضمان جودة توليد جيدة.
    • لأنواع VAE الواعية بخطوة الزمن (LTX-Video 0.9.1 وما بعده)، اضبط decode_timestep على 0.05 وimage_cond_noise_scale على 0.025.
    • بالنسبة للتحويرات التي تدعم الاستيفاء بين صور وفيديوهات شرطية متعددة (LTX-Video 0.9.5 وما بعده)، استخدم صوراً وفيديوهات مشابهة للحصول على أفضل النتائج. قد يؤدي الانحراف عن مدخلات الشرط إلى انتقالات مفاجئة في الفيديو المولّد.
  • يتضمن LTX-Video 0.9.7 مُكبِّرًا كامنًا مكانيًا ومحوّلًا (Transformer) يحتوي على 13 مليار معامل. أثناء الاستدلال، يتم توليد فيديو بدقة منخفضة بسرعة أولاً، ثم يُكبَّر ويُحسَّن.

    عرض كود مثال
    import torch
    from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
    from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
    from diffusers.utils import export_to_video, load_video
    
    pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.7-dev", dtype=torch.bfloat16)
    pipeline_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.7", vae=pipeline.vae, dtype=torch.bfloat16)
    pipeline.to("cuda")  # or "mps", "xpu", "cpu"
    pipe_upsample.to("cuda")
    pipeline.vae.enable_tiling()
    
    def round_to_nearest_resolution_acceptable_by_vae(height, width):
        height = height - (height % pipeline.vae_temporal_compression_ratio)
        width = width - (width % pipeline.vae_temporal_compression_ratio)
        return height, width
    
    video = load_video(
        "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4"
    )[:21]  # only use the first 21 frames as conditioning
    condition1 = LTXVideoCondition(video=video, frame_index=0)
    
    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.
    """
    negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
    expected_height, expected_width = 768, 1152
    downscale_factor = 2 / 3
    num_frames = 161
    
    # 1. Generate video at smaller resolution
    # Text-only conditioning is also supported without the need to pass `conditions`
    downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
    downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
    latents = pipeline(
        conditions=[condition1],
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=downscaled_width,
        height=downscaled_height,
        num_frames=num_frames,
        num_inference_steps=30,
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=5.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="latent",
    ).frames
    
    # 2. Upscale generated video using latent upsampler with fewer inference steps
    # The available latent upsampler upscales the height/width by 2x
    upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
    upscaled_latents = pipe_upsample(
        latents=latents,
        output_type="latent"
    ).frames
    
    # 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
    video = pipeline(
        conditions=[condition1],
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=upscaled_width,
        height=upscaled_height,
        num_frames=num_frames,
        denoise_strength=0.4,  # Effectively, 4 inference steps out of 10
        num_inference_steps=10,
        latents=upscaled_latents,
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=5.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="pil",
    ).frames[0]
    
    # 4. Downscale the video to the expected resolution
    video = [frame.resize((expected_width, expected_height)) for frame in video]
    
    export_to_video(video, "output.mp4", fps=24)
  • نموذج LTX-Video 0.9.7 المُقطّر مُقطّر من حيث التوجيه (guidance) والخطوات الزمنية (timestep) لتسريع عملية التوليد. يتطلب ضبط guidance_scale على 1.0، ويجب ضبط num_inference_steps بين 4 و10 للحصول على جودة توليد جيدة. كما ينبغي استخدام الخطوات الزمنية المخصصة التالية للحصول على أفضل النتائج.

    • استدلال النموذج الأساسي للتحضير للتصعيد: [1000, 993, 987, 981, 975, 909, 725, 0.03].
    • التحجيم: [1000, 909, 725, 421, 0].
    عرض كود مثال
    import torch
    from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
    from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
    from diffusers.utils import export_to_video, load_video
    
    pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.7-distilled", dtype=torch.bfloat16)
    pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.7", vae=pipeline.vae, dtype=torch.bfloat16)
    pipeline.to("cuda")  # or "mps", "xpu", "cpu"
    pipe_upsample.to("cuda")
    pipeline.vae.enable_tiling()
    
    def round_to_nearest_resolution_acceptable_by_vae(height, width):
        height = height - (height % pipeline.vae_spatial_compression_ratio)
        width = width - (width % pipeline.vae_spatial_compression_ratio)
        return height, width
    
    prompt = """
    artistic anatomical 3d render, utlra quality, human half full male body with transparent 
    skin revealing structure instead of organs, muscular, intricate creative patterns, 
    monochromatic with backlighting, lightning mesh, scientific concept art, blending biology 
    with botany, surreal and ethereal quality, unreal engine 5, ray tracing, ultra realistic, 
    16K UHD, rich details. camera zooms out in a rotating fashion
    """
    negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
    expected_height, expected_width = 768, 1152
    downscale_factor = 2 / 3
    num_frames = 161
    
    # 1. Generate video at smaller resolution
    downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
    downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
    latents = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=downscaled_width,
        height=downscaled_height,
        num_frames=num_frames,
        timesteps=[1000, 993, 987, 981, 975, 909, 725, 0.03],
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=1.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="latent",
    ).frames
    
    # 2. Upscale generated video using latent upsampler with fewer inference steps
    # The available latent upsampler upscales the height/width by 2x
    upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
    upscaled_latents = pipe_upsample(
        latents=latents,
        adain_factor=1.0,
        output_type="latent"
    ).frames
    
    # 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
    video = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=upscaled_width,
        height=upscaled_height,
        num_frames=num_frames,
        denoise_strength=0.999,  # Effectively, 4 inference steps out of 5
        timesteps=[1000, 909, 725, 421, 0],
        latents=upscaled_latents,
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=1.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="pil",
    ).frames[0]
    
    # 4. Downscale the video to the expected resolution
    video = [frame.resize((expected_width, expected_height)) for frame in video]
    
    export_to_video(video, "output.mp4", fps=24)
  • يُشبه نموذج LTX-Video 0.9.8 المُقطّر (distilled) النسخة 0.9.7. فهو مُقطّر من حيث التوجيه (guidance) وخطوة الزمن (timestep)، ويمكن استخدام كود استنتاج مشابه لما هو موضح أعلاه. تتمثل تحسينات هذه النسخة في دعمها لتوليد مقاطع فيديو طويلة جدًا. بالإضافة إلى ذلك، تدعم استخدام خرائط النغمة (tone mapping) لتحسين جودة الفيديو المولّد باستخدام معامل tone_map_compression_ratio. يُوصى بالقيمة الافتراضية 0.6.

    عرض كود مثال
    import torch
    from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
    from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
    from diffusers.models.latent_upscaler import LTXLatentUpsamplerModel
    from diffusers.utils import export_to_video, load_video
    
    pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.8-13B-distilled", dtype=torch.bfloat16)
    # TODO: Update the checkpoint here once updated in LTX org
    upsampler = LTXLatentUpsamplerModel.from_pretrained("a-r-r-o-w/LTX-0.9.8-Latent-Upsampler", dtype=torch.bfloat16)
    pipe_upsample = LTXLatentUpsamplePipeline(vae=pipeline.vae, latent_upsampler=upsampler).to(torch.bfloat16)
    pipeline.to("cuda")  # or "mps", "xpu", "cpu"
    pipe_upsample.to("cuda")
    pipeline.vae.enable_tiling()
    
    def round_to_nearest_resolution_acceptable_by_vae(height, width):
        height = height - (height % pipeline.vae_spatial_compression_ratio)
        width = width - (width % pipeline.vae_spatial_compression_ratio)
        return height, width
    
    prompt = """The camera pans over a snow-covered mountain range, revealing a vast expanse of snow-capped peaks and valleys.The mountains are covered in a thick layer of snow, with some areas appearing almost white while others have a slightly darker, almost grayish hue. The peaks are jagged and irregular, with some rising sharply into the sky while others are more rounded. The valleys are deep and narrow, with steep slopes that are also covered in snow. The trees in the foreground are mostly bare, with only a few leaves remaining on their branches. The sky is overcast, with thick clouds obscuring the sun. The overall impression is one of peace and tranquility, with the snow-covered mountains standing as a testament to the power and beauty of nature."""
    # prompt = """A woman walks away from a white Jeep parked on a city street at night, then ascends a staircase and knocks on a door. The woman, wearing a dark jacket and jeans, walks away from the Jeep parked on the left side of the street, her back to the camera; she walks at a steady pace, her arms swinging slightly by her sides; the street is dimly lit, with streetlights casting pools of light on the wet pavement; a man in a dark jacket and jeans walks past the Jeep in the opposite direction; the camera follows the woman from behind as she walks up a set of stairs towards a building with a green door; she reaches the top of the stairs and turns left, continuing to walk towards the building; she reaches the door and knocks on it with her right hand; the camera remains stationary, focused on the doorway; the scene is captured in real-life footage."""
    negative_prompt = "bright colors, symbols, graffiti, watermarks, worst quality, inconsistent motion, blurry, jittery, distorted"
    expected_height, expected_width = 480, 832
    downscale_factor = 2 / 3
    # num_frames = 161
    num_frames = 361
    
    # 1. Generate video at smaller resolution
    downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
    downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
    latents = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=downscaled_width,
        height=downscaled_height,
        num_frames=num_frames,
        timesteps=[1000, 993, 987, 981, 975, 909, 725, 0.03],
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=1.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="latent",
    ).frames
    
    # 2. Upscale generated video using latent upsampler with fewer inference steps
    # The available latent upsampler upscales the height/width by 2x
    upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
    upscaled_latents = pipe_upsample(
        latents=latents,
        adain_factor=1.0,
        tone_map_compression_ratio=0.6,
        output_type="latent"
    ).frames
    
    # 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
    video = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        width=upscaled_width,
        height=upscaled_height,
        num_frames=num_frames,
        denoise_strength=0.999,  # Effectively, 4 inference steps out of 5
        timesteps=[1000, 909, 725, 421, 0],
        latents=upscaled_latents,
        decode_timestep=0.05,
        decode_noise_scale=0.025,
        image_cond_noise_scale=0.0,
        guidance_scale=1.0,
        guidance_rescale=0.7,
        generator=torch.Generator().manual_seed(0),
        output_type="pil",
    ).frames[0]
    
    # 4. Downscale the video to the expected resolution
    video = [frame.resize((expected_width, expected_height)) for frame in video]
    
    export_to_video(video, "output.mp4", fps=24)
  • يدعم LTX-Video نماذج LoRA من خلال load_lora_weights().

    عرض مثال على الكود
    import torch
    from diffusers import LTXConditionPipeline
    from diffusers.utils import export_to_video, load_image
    
    pipeline = LTXConditionPipeline.from_pretrained(
        "Lightricks/LTX-Video-0.9.5", dtype=torch.bfloat16
    )
    
    pipeline.load_lora_weights("Lightricks/LTX-Video-Cakeify-LoRA", adapter_name="cakeify")
    pipeline.set_adapters("cakeify")
    
    # use "CAKEIFY" to trigger the LoRA
    prompt = "CAKEIFY a person using a knife to cut a cake shaped like a Pikachu plushie"
    image = load_image("https://huggingface.co/Lightricks/LTX-Video-Cakeify-LoRA/resolve/main/assets/images/pikachu.png")
    
    video = pipeline(
        prompt=prompt,
        image=image,
        width=576,
        height=576,
        num_frames=161,
        decode_timestep=0.03,
        decode_noise_scale=0.025,
        num_inference_steps=50,
    ).frames[0]
    export_to_video(video, "output.mp4", fps=26)
  • LTX-Video supports loading from single files, such as GGUF checkpoints, with loaders.FromOriginalModelMixin.from_single_file() or loaders.FromSingleFileMixin.from_single_file().

    عرض مثال برمجي
    import torch
    from diffusers.utils import export_to_video
    from diffusers import LTXPipeline, AutoModel, GGUFQuantizationConfig
    
    transformer = AutoModel.from_single_file(
        "https://huggingface.co/city96/LTX-Video-gguf/blob/main/ltx-video-2b-v0.9-Q3_K_S.gguf"
        quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16),
        dtype=torch.bfloat16
    )
    pipeline = LTXPipeline.from_pretrained(
        "Lightricks/LTX-Video",
        transformer=transformer,
        dtype=torch.bfloat16
    )

LTXI2VLongMultiPromptPipeline

فئة diffusers.LTXI2VLongMultiPromptPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLLTXVideotext_encoder: T5EncoderModeltokenizer: T5TokenizerFasttransformer: LTXVideoTransformer3DModel )

المعاملات

  • transformer (LTXVideoTransformer3DModel) — بنية Transformer شرطية لإزالة الضوضاء من كامنات الفيديو المُرمّزة.
  • scheduler (FlowMatchEulerDiscreteScheduler أو LTXEulerAncestralRFScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كامنات الصورة المُرمّزة.
  • vae (AutoencoderKLLTXVideo) — نموذج الترميز التبايني التلقائي (VAE) لتشفير الصور وفك تشفيرها إلى التمثيلات الكامنة ومنها.
  • text_encoder (T5EncoderModel) — T5، وتحديداً النسخة google/t5-v1_1-xxl.
  • tokenizer (T5TokenizerFast) — مُقسِّم من الفئة T5TokenizerFast.

خط أنابيب متعدد التوجيهات لتحويل الصور إلى فيديو (I2V) بمدة طويلة، مع توافق كامل مع ComfyUI.

الميزات الرئيسية:

  • عينة النافذة المنزلقة الزمنية فقط (بدون تقسيم مكاني للأبعاد H/W)؛ والدمج التلقائي التتابعي عبر النوافذ.
  • تجزئة متعددة الموجهات لكل نافذة مع انتقالات سلسة عند رؤوس النوافذ.
  • شرط صارم للإطار الأول عبر قناع لكل رمز لتوليد الفيديو من صورة.
  • التحكم في ذاكرة الفيديو (VRAM) عبر النافذة الزمنية وفك ترميز VAE على شكل بلاطات.

مرجع: https://github.com/Lightricks/LTX-Video

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneprompt_segments: list[dict[str, Any]] | None = Noneheight: int = 512width: int = 704num_frames: int = 161frame_rate: float = 25guidance_scale: float = 1.0guidance_rescale: float = 0.0num_inference_steps: int | None = 8sigmas: list[float, torch.Tensor] | None = Nonegenerator: torch.Generator | list[torch.Generator] | None = Noneseed: int | None = 0cond_image: 'PIL.Image.Image' | torch.Tensor | None = Nonecond_strength: float = 0.5latents: torch.Tensor | None = Nonetemporal_tile_size: int = 80temporal_overlap: int = 24temporal_overlap_cond_strength: float = 0.5adain_factor: float = 0.25guidance_latents: torch.Tensor | None = Noneguiding_strength: float = 1.0negative_index_latents: torch.Tensor | None = Nonenegative_index_strength: float = 1.0skip_steps_sigma_threshold: float | None = 1decode_timestep: float | None = 0.05decode_noise_scale: float | None = 0.025decode_horizontal_tiles: int = 4decode_vertical_tiles: int = 4decode_overlap: int = 3output_type: str | None = 'latent'return_dict: bool = Trueattention_kwargs: dict[str, Any] | None = Nonecallback_on_step_end: Callable[[int, int], None] | None = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents']max_sequence_length: int = 128 ) → ~pipelines.ltx.LTXPipelineOutput or tuple

المعاملات

  • prompt (str أو list[str]، اختياري) — أوامر نصية إيجابية لكل نافذة. إذا احتوت سلسلة واحدة على ’|’، يتم تقسيم الأجزاء بواسطة علامات العمودية.
  • negative_prompt (str أو list[str]، اختياري) — موجّه سلبي أو أكثر لتثبيط المحتوى غير المرغوب فيه.
  • prompt_segments (list[dict], اختياري) — خريطة تقسيمات تحتوي على {“start_window”, “end_window”, “text”} لتجاوز الأوامر (prompts) لكل نافذة.
  • height (int، القيمة الافتراضية 512) — ارتفاع الصورة الناتجة بالبكسلات؛ يجب أن يكون قابلاً للقسمة على 32.
  • width (int، القيمة الافتراضية 704) — عرض الصورة الناتج بالبكسلات؛ يجب أن يكون قابلاً للقسمة على 32.
  • num_frames (int، القيمة الافتراضية 161) — عدد الإطارات الناتجة (في فضاء البكسلات المُفكَّكة).
  • frame_rate (float، القيمة الافتراضية 25) — إطار في الثانية؛ يُستخدم لتطبيع الإحداثيات الزمنية في video_coords.
  • guidance_scale (float، القيمة الافتراضية 1.0) — مقياس CFG؛ القيم > 1 تفعّل التوجيه بدون مُصنِّف.
  • guidance_rescale (float، القيمة الافتراضية 0.0) — إعادة تحجيم اختيارية للتخفيف من الإفراط في التعرض تحت CFG (انظر rescale_noise_cfg).
  • num_inference_steps (int، اختياري، القيمة الافتراضية 8) — خطوات إزالة الضوضاء لكل نافذة. يتم تجاهلها إذا تم توفير sigmas.
  • sigmas (list[float] أو torch.Tensor، اختياري) — جدول صريح لقيم sigma لكل نافذة؛ إذا تم تعيينه، يتجاوز num_inference_steps.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — يتحكم في العشوائية؛ يُقبل إدخال قائمة لكن يُستخدم العنصر الأول فقط (batch=1).
  • seed (int، اختياري، القيمة الافتراضية 0) — إذا تم تقديمه، يُهيّئ المولّد المشترك للقيم الكامنة العالمية ويشتق مولّدًا محليًا لكل نافذة زمنية باستخدام seed + w_start لكل نافذة زمنية.
  • cond_image (PIL.Image.Image أو torch.Tensor، اختياري) — صورة التكييف؛ تُثبّت الإطار 0 عبر قناع لكل رمز عندما يكون cond_strength > 0.
  • cond_strength (float، القيمة الافتراضية 0.5) — قوة التكييف الصارم للإطار الأول (كلما كان cond_mask أصغر، كان الحفظ أقوى).
  • latents (torch.Tensor، اختياري) — القيم الكامنة الأولية [B, C_lat, F_lat, H_lat, W_lat]؛ إذا كانت None، يتم أخذها عشوائياً باستخدام randn_tensor.
  • temporal_tile_size (int، القيمة الافتراضية 80) — حجم النافذة الزمنية (بإطار فك الترميز)؛ يتم تحجيمها داخليًا بواسطة ضغط VAE الزمني.
  • temporal_overlap (int، القيمة الافتراضية 24) — التداخل بين النوافذ المتتالية (بإطار مُفكَّك)؛ يتم تحجيمه داخلياً بواسطة الضغط.
  • temporal_overlap_cond_strength (float، القيمة الافتراضية 0.5) — قوة حقن كامنات ذيل النافذة السابقة في رأس النافذة الجديدة.
  • adain_factor (float، القيمة الافتراضية 0.25) — قوة تطبيع AdaIN لتحقيق الاتساق بين النوافذ (0 لتعطيله).
  • guidance_latents (torch.Tensor، اختياري) — كائنات مرجعية تُحقن في رأس النافذة؛ يتم تقصير طولها بواسطة التداخل للنافذات اللاحقة.
  • guiding_strength (float، القيمة الافتراضية 1.0) — قوة الحقن لـ guidance_latents.
  • negative_index_latents (torch.Tensor، اختياري) — كامن لإطار واحد يُضاف في بداية النافذة لدلالات “الفهرس السالب”.
  • negative_index_strength (float، القيمة الافتراضية 1.0) — قوة الحقن لـ negative_index_latents.
  • skip_steps_sigma_threshold (float، اختياري، القيمة الافتراضية 1) — تخطي الخطوات التي يتجاوز فيها قيمة sigma هذا الحد.
  • decode_timestep (float، اختياري، القيمة الافتراضية 0.05) — خطوة الزمن أثناء فك الترميز (إذا كان VAE يدعم timestep_conditioning).
  • decode_noise_scale (float، اختياري، القيمة الافتراضية 0.025) — مقياس مزيج الضوضاء أثناء فك الترميز (إذا كان VAE يدعم timestep_conditioning).
  • decode_horizontal_tiles (int، القيمة الافتراضية 4) — عدد البلاطات الأفقية أثناء فك ترميز VAE.
  • decode_vertical_tiles (int، القيمة الافتراضية 4) — عدد البلاطات العمودية أثناء فك ترميز VAE.
  • decode_overlap (int، القيمة الافتراضية 3) — التداخل (بوحدة البكسلات الكامنة) بين البلاطات أثناء فك ترميز VAE.
  • output_type (str، اختياري، القيمة الافتراضية "latent") — صيغة مخرجات الفيديو المولّد. اختر بين “latent” أو “pt” أو “np” أو “pil”. إذا كانت القيمة “latent”، تُعاد الكمونيات (latents) دون فك الترميز.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ~pipelines.ltx.LTXPipelineOutput بدلاً من tuple عادي.
  • attention_kwargs (dict، اختياري) — معاملات انتباه إضافية تُمرَّر إلى المحوّل.
  • callback_on_step_end (PipelineCallback أو MultiPipelineCallbacks، اختياري) — خطاف استدعاء لكل خطوة.
  • callback_on_step_end_tensor_inputs (list[str]، القيمة الافتراضية ["latents"]) — المفاتيح من locals() التي يجب تمريرها إلى الاستدعاء الوسيط.
  • max_sequence_length (int، القيمة الافتراضية 128) — الحد الأقصى لطول المُرمِّز (Tokenizer) عند ترميز الاستعلام.

يعيد

~pipelines.ltx.LTXPipelineOutput أو tuple

إذا كان return_dict هو True، يُعاد ~pipelines.ltx.LTXPipelineOutput، وإلا يُعاد tuple يكون عنصره الأول قائمة تحتوي على الإطارات المولّدة. يعتمد تنسيق المخرجات على output_type:

  • “latent”/“pt”: torch.Tensor [B, C, F, H, W]؛ حيث يكون “latent” في فضاء الكامنين المعيار، و“pt” في فضاء مخرجات VAE.
  • “np”: np.ndarray بعد المعالجة.
  • “pil”: list[PIL.Image.Image] قائمة من صور PIL.

توليد تسلسل صورة إلى فيديو عبر النوافذ الزمنية المنزلقة وجدولة متعددة الموجهات.

أمثلة:

>>> import torch
>>> from diffusers import LTXEulerAncestralRFScheduler, LTXI2VLongMultiPromptPipeline

>>> pipe = LTXI2VLongMultiPromptPipeline.from_pretrained("LTX-Video-0.9.8-13B-distilled")
>>> # For ComfyUI parity, swap in the RF scheduler (keeps the original config).
>>> pipe.scheduler = LTXEulerAncestralRFScheduler.from_config(pipe.scheduler.config)
>>> pipe = pipe.to("cuda").to(dtype=torch.bfloat16)
>>> # Example A: get decoded frames (PIL)
>>> out = pipe(
...     prompt="a chimpanzee walks | a chimpanzee eats",
...     num_frames=161,
...     height=512,
...     width=704,
...     temporal_tile_size=80,
...     temporal_overlap=24,
...     output_type="pil",
...     return_dict=True,
... )
>>> frames = out.frames[0]  # list of PIL.Image.Image
>>> # Example B: get latent video and decode later (saves VRAM during sampling)
>>> out_latent = pipe(prompt="a chimpanzee walking", output_type="latent", return_dict=True).frames
>>> frames = pipe.vae_decode_tiled(out_latent, output_type="pil")[0]

الأشكال: أحجام الكمون (عند التوليد التلقائي):

  • F_lat = (num_frames - 1) // vae_temporal_compression_ratio + 1
  • H_lat = height // vae_spatial_compression_ratio
  • W_lat = width // vae_spatial_compression_ratio

ملاحظات:

  • التبذير: عند توفير seed، يستخدم كل نافذة زمنية مولّدًا محليًا مبذّرًا بـ seed + w_start، بينما يُبذَّر المولّد المشترك مرة واحدة للكائنات الكامنة العالمية إذا لم يُمرَّر مولّد؛ وإلا يُعاد استخدام المولّد المُمرَّر.
  • CFG: تنبؤ موحّد للضوضاء noise_pred = uncond + w * (text - uncond) مع guidance_rescale اختياري.
  • الذاكرة: يؤدي إزالة الضوضاء تنبؤات بإطار كامل (بدون تقطيع مكاني)؛ ويمكن تقطيع فك الترميز لتجنب نفاد الذاكرة.

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: torch.Tensor | None = Nonenegative_prompt_embeds: torch.Tensor | None = Noneprompt_attention_mask: torch.Tensor | None = Nonenegative_prompt_attention_mask: torch.Tensor | None = Nonemax_sequence_length: int = 128device: torch.device | None = Nonedtype: torch.dtype | None = 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

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

prepare_latents

< >

( batch_size: intnum_channels_latents: intheight: intwidth: intnum_frames: intdevice: torch.devicegenerator: torch.Generator | Nonedtype: torch.dtype = torch.float32latents: torch.Tensor | None = Nonecond_latents: torch.Tensor | None = Nonecond_strength: float = 0.0negative_index_latents: torch.Tensor | None = None )

جهّز الكمونيات الأساسية وأدر كمونيات تكييف الإطار الأول اختيارياً.

vae_decode_tiled

< >

( latents: torch.Tensordecode_timestep: float | None = Nonedecode_noise_scale: float | None = Nonehorizontal_tiles: int = 4vertical_tiles: int = 4overlap: int = 3last_frame_fix: bool = Truegenerator: torch.Generator | None = Noneoutput_type: str = 'pt'auto_denormalize: bool = Truecompute_dtype: torch.dtype = torch.float32enable_vae_tiling: bool = False ) →

  • If output_type=“latent”

المعاملات

  • latents — [B, C_latent, F_latent, H_latent, W_latent]
  • decode_timestep — خطوة فك الترميز الاختيارية (تكون فعالة فقط إذا كان VAE يدعم timestep_conditioning)
  • decode_noise_scale — استيفاء اختياري لضوضاء فك الترميز (يكون فعالاً فقط إذا كان VAE يدعم timestep_conditioning)
  • horizontal_tiles, vertical_tiles — عدد البلاطات أفقيًا/رأسيًا (>= 1)
  • overlap — التداخل في الفضاء الكامن (بالبكسلات الكامنة، >= 0)
  • last_frame_fix — ما إذا كان سيتم تفعيل إصلاح «تكرار الإطار الأخير»
  • generator — مولّد عشوائي (يُستخدم لضجيج decode_noise_scale)
  • output_type — “«latent» | «pt» | «np» | «pil»
    • “latent”: إرجاع الكمونيات دون تغيير (مفيد للمعالجة اللاحقة)
    • “pt”: إرجاع المتجه في فضاء مخرجات VAE
    • “np”/“pil”: مخرجات بعد المعالجة عبر VideoProcessor.postprocess_video
  • auto_denormalize — إذا كانت True، تُطبَّق إزالة تطبيع LTX على latents داخليًا (موصى به)
  • compute_dtype — الدقة المستخدمة أثناء دمج البلاطات (الافتراضي float32؛ يقلل بشكل كبير من ضبابية الحدود)
  • enable_vae_tiling — إذا كانت True، فتمنح التفويض للتقسيم إلى tiled_decode المدمج في VAE (يُعيّن vae.use_tiling).

يعيد

  • إذا كان output_type="latent"

يعيد latents المدخلات دون تغيير

  • إذا كان output_type="pt": يُرجع [B, C, F, H, W] (قيم تقريبية ضمن [-1, 1])
  • إذا كان output_type=“np”/“pil”: تُرجع المخرجات بعد المعالجة عبر postprocess_video

فك الترميز المكاني المُقسّم إلى بلاطات (تطابق مع ComfyUI) القائم على VAE، والمُنفَّذ بأسلوب Diffusers.

  • Linearly feather and blend overlapping tiles to avoid seams.
  • اختياري last_frame_fix: انسخ الإطار الكامن الأخير قبل فك الترميز، ثم احذف time_scale_factor إطارات في النهاية.
  • يدعم حقن timestep_conditioning و decode_noise_scale.
  • بشكل افتراضي، يتم إلغاء تطبيع “القيم الكامنة المُطبَّعة” (ناتج إزالة الضوضاء) داخليًا (auto_denormalize=True).
  • يتم حساب دمج البلاطات في compute_dtype (الافتراضي هو float32) لتقليل الضبابية وانزياحات الألوان.

LTXPipeline

فئة diffusers.LTXPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLLTXVideotext_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: LTXVideoTransformer3DModel )

المعاملات

  • transformer (LTXVideoTransformer3DModel) — بنية Transformer شرطية لإزالة الضوضاء من كامنات الفيديو المُرمّزة.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLLTXVideo) — نموذج الترميز التبايني التلقائي (VAE) لتشفير الصور وفك تشفيرها إلى التمثيلات الكامنة ومنها.
  • text_encoder (T5EncoderModel) — T5، وتحديداً النسخة google/t5-v1_1-xxl.
  • tokenizer (CLIPTokenizer) — مقسّم من الفئة CLIPTokenizer.
  • tokenizer (T5TokenizerFast) — المُرمِّز الثاني من الفئة T5TokenizerFast.

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

مرجع: https://github.com/Lightricks/LTX-Video

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 512width: int = 704num_frames: int = 161frame_rate: int = 25num_inference_steps: int = 50timesteps: list = Noneguidance_scale: float = 3guidance_rescale: float = 0.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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonedecode_timestep: float | list[float] = 0.0decode_noise_scale: float | list[float] | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 128 ) → ~pipelines.ltx.LTXPipelineOutput or tuple

المعاملات

  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً منه. يتم تجاهله عند عدم استخدام التوجيه (guidance_scale < 1).
  • height (int، القيمة الافتراضية 512) — ارتفاع الصورة المولّدة بالبكسل. يتم ضبطه على 480 افتراضيًا للحصول على أفضل النتائج.
  • width (int)، القيمة الافتراضية 704) — عرض الصورة المولدة بالبكسلات. يتم ضبطه على 848 افتراضيًا للحصول على أفضل النتائج.
  • num_frames (int، القيمة الافتراضية 161) — عدد إطارات الفيديو التي سيتم توليدها
  • frame_rate (int، القيمة الافتراضية 25) — معدل الإطارات المستهدف للفيديو المولّد.
  • num_inference_steps (int، اختياري، القيمة الافتراضية 50) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • timesteps (list[int], اختياري) — خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء مع المجدولين الذين يدعمون معامل timesteps في طريقة set_timesteps الخاصة بهم. إذا لم يُعرَّف، فسيتم استخدام السلوك الافتراضي عند تمرير num_inference_steps. يجب أن تكون بترتيب تنازلي.
  • guidance_scale (float، القيمة الافتراضية 3 ) — مقياس التوجيه كما هو مُعرَّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1. كلما زاد مقياس التوجيه، شجّع ذلك على توليد صور مرتبطة ارتباطًا وثيقًا بـ prompt النصي، وعادةً على حساب انخفاض جودة الصورة.
  • guidance_rescale (float, اختياري، القيمة الافتراضية 0.0) — معامل إعادة الضبط للتوجيه المقترح في جداول ضوضاء الانتشار الشائعة وخطوات العينة معيبة حيث يُعرَّف guidance_scale على أنه φ في المعادلة 16 من جداول ضوضاء الانتشار الشائعة وخطوات العينة معيبة. يجب أن يُصلح معامل إعادة الضبط للتوجيه مشكلة الإفراط في التعرض عند استخدام SNR نهائي صفر.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد مقاطع الفيديو التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — مولّد واحد أو قائمة من مولّدات torch لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، سيتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • prompt_attention_mask (torch.Tensor، اختياري) — قناع الانتباه المُولَّد مسبقًا لتضمينات النص.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • negative_prompt_attention_mask (torch.FloatTensor، اختياري) — قناع انتباه مُولّد مسبقًا لتضمينات النص السلبية.
  • decode_timestep (float، القيمة الافتراضية 0.0) — خطوة الزمن التي يتم عندها فك ترميز الفيديو المولّد.
  • decode_noise_scale (float، القيمة الافتراضية None) — عامل الاستيفاء بين الضوضاء العشوائية واللاتنتات المُزالة الضوضاء عند خطوة فك الترميز.
  • output_type (str، اختياري، القيمة الافتراضية "pil") — صيغة مخرجات توليد الصورة. اختر بين PIL: PIL.Image.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ~pipelines.ltx.LTXPipelineOutput بدلاً من tuple عادي.
  • attention_kwargs (dict، اختياري) — قاموس kwargs يُمرَّر إلى AttentionProcessor إذا تم تحديده، كما هو معرَّف تحت self.processor في diffusers.models.attention_processor.
  • callback_on_step_end (Callable، اختياري) — دالة تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال. تُستدعى الدالة بالحجج التالية: 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 الافتراضي 128 ) — أقصى طول تسلسل يُستخدم مع prompt.

يعيد

~pipelines.ltx.LTXPipelineOutput أو tuple

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

الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.

أمثلة:

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

>>> pipe = LTXPipeline.from_pretrained("Lightricks/LTX-Video", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair. The woman with brown hair wears a black jacket and has a small, barely noticeable mole on her right cheek. The camera angle is a close-up, focused on the woman with brown hair's face. The lighting is warm and natural, likely from the setting sun, casting a soft glow on the scene. The scene appears to be real-life footage"
>>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

>>> video = pipe(
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     width=704,
...     height=480,
...     num_frames=161,
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=24)

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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 128device: 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

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

LTXImageToVideoPipeline

فئة diffusers.LTXImageToVideoPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLLTXVideotext_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: LTXVideoTransformer3DModel )

المعاملات

  • transformer (LTXVideoTransformer3DModel) — بنية Transformer شرطية لإزالة الضوضاء من كامنات الفيديو المُرمّزة.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLLTXVideo) — نموذج الترميز التبايني التلقائي (VAE) لتشفير الصور وفك تشفيرها إلى التمثيلات الكامنة ومنها.
  • text_encoder (T5EncoderModel) — T5، وتحديداً النسخة google/t5-v1_1-xxl.
  • tokenizer (CLIPTokenizer) — مقسّم من الفئة CLIPTokenizer.
  • tokenizer (T5TokenizerFast) — المُرمِّز الثاني من الفئة T5TokenizerFast.

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

مرجع: https://github.com/Lightricks/LTX-Video

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 512width: int = 704num_frames: int = 161frame_rate: int = 25num_inference_steps: int = 50timesteps: list = Noneguidance_scale: float = 3guidance_rescale: float = 0.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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonedecode_timestep: float | list[float] = 0.0decode_noise_scale: float | list[float] | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 128 ) → ~pipelines.ltx.LTXPipelineOutput or tuple

المعاملات

  • image (PipelineImageInput) — الصورة المدخلة التي تُشترط عليها عملية التوليد. يجب أن تكون صورة، أو قائمة من الصور، أو torch.Tensor.
  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً منه. يتم تجاهله عند عدم استخدام التوجيه (guidance_scale < 1).
  • height (int، القيمة الافتراضية 512) — ارتفاع الصورة المولّدة بالبكسل. يتم ضبطه على 480 افتراضيًا للحصول على أفضل النتائج.
  • width (int)، القيمة الافتراضية 704) — عرض الصورة المولدة بالبكسلات. يتم ضبطه على 848 افتراضيًا للحصول على أفضل النتائج.
  • num_frames (int، القيمة الافتراضية 161) — عدد إطارات الفيديو التي سيتم توليدها
  • frame_rate (int، القيمة الافتراضية 25) — معدل الإطارات المستهدف للفيديو المولّد.
  • num_inference_steps (int، اختياري، القيمة الافتراضية 50) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • timesteps (list[int], اختياري) — خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء مع المجدولين الذين يدعمون معامل timesteps في طريقة set_timesteps الخاصة بهم. إذا لم يُعرَّف، فسيتم استخدام السلوك الافتراضي عند تمرير num_inference_steps. يجب أن تكون بترتيب تنازلي.
  • guidance_scale (float، القيمة الافتراضية 3 ) — مقياس التوجيه كما هو مُعرَّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1. كلما زاد مقياس التوجيه، شجّع ذلك على توليد صور مرتبطة ارتباطًا وثيقًا بـ prompt النصي، وعادةً على حساب انخفاض جودة الصورة.
  • guidance_rescale (float, optional, defaults to 0.0) — Guidance rescale factor proposed by Common Diffusion Noise Schedules and Sample Steps are Flawed guidance_scale is defined as φ in equation 16. of Common Diffusion Noise Schedules and Sample Steps are Flawed. Guidance rescale factor should fix overexposure when using zero terminal SNR.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد مقاطع الفيديو التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — مولّد واحد أو قائمة من مولّدات torch لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، سيتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • prompt_attention_mask (torch.Tensor، اختياري) — قناع الانتباه المُولَّد مسبقًا لتضمينات النص.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • negative_prompt_attention_mask (torch.FloatTensor، اختياري) — قناع انتباه مُولّد مسبقًا لتضمينات النص السلبية.
  • decode_timestep (float، القيمة الافتراضية 0.0) — خطوة الزمن التي يتم عندها فك ترميز الفيديو المولّد.
  • decode_noise_scale (float، القيمة الافتراضية None) — عامل الاستيفاء بين الضوضاء العشوائية واللاتنتات المُزالة الضوضاء عند خطوة فك الترميز.
  • output_type (str، اختياري، القيمة الافتراضية "pil") — صيغة مخرجات توليد الصورة. اختر بين PIL: PIL.Image.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ~pipelines.ltx.LTXPipelineOutput بدلاً من tuple عادي.
  • attention_kwargs (dict، اختياري) — قاموس kwargs يُمرَّر إلى AttentionProcessor إذا تم تحديده، كما هو معرَّف تحت self.processor في diffusers.models.attention_processor.
  • callback_on_step_end (Callable، اختياري) — دالة تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال. تُستدعى الدالة بالحجج التالية: 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 الافتراضي 128 ) — أقصى طول تسلسل يُستخدم مع prompt.

يعيد

~pipelines.ltx.LTXPipelineOutput أو tuple

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

الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.

أمثلة:

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

>>> pipe = LTXImageToVideoPipeline.from_pretrained("Lightricks/LTX-Video", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> image = load_image(
...     "https://huggingface.co/datasets/a-r-r-o-w/tiny-meme-dataset-captioned/resolve/main/images/8.png"
... )
>>> prompt = "A young girl stands calmly in the foreground, looking directly at the camera, as a house fire rages in the background. Flames engulf the structure, with smoke billowing into the air. Firefighters in protective gear rush to the scene, a fire truck labeled '38' visible behind them. The girl's neutral expression contrasts sharply with the chaos of the fire, creating a poignant and emotionally charged scene."
>>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

>>> video = pipe(
...     image=image,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     width=704,
...     height=480,
...     num_frames=161,
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=24)

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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 128device: 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

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

LTXConditionPipeline

فئة diffusers.LTXConditionPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLLTXVideotext_encoder: T5EncoderModeltokenizer: T5Tokenizertransformer: LTXVideoTransformer3DModel )

المعاملات

  • transformer (LTXVideoTransformer3DModel) — بنية Transformer شرطية لإزالة الضوضاء من كامنات الفيديو المُرمّزة.
  • scheduler (FlowMatchEulerDiscreteScheduler) — جدول زمني يُستخدم بالاقتران مع transformer لإزالة الضوضاء من كائنات الصورة المُرمّزة.
  • vae (AutoencoderKLLTXVideo) — نموذج الترميز التبايني التلقائي (VAE) لتشفير الصور وفك تشفيرها إلى التمثيلات الكامنة ومنها.
  • text_encoder (T5EncoderModel) — T5، وتحديداً النسخة google/t5-v1_1-xxl.
  • tokenizer (CLIPTokenizer) — مقسّم من الفئة CLIPTokenizer.
  • tokenizer (T5TokenizerFast) — المُرمِّز الثاني من الفئة T5TokenizerFast.

خط أنابيب لتوليد فيديو من نص/صورة/فيديو.

مرجع: https://github.com/Lightricks/LTX-Video

__call__

< >

( conditions: diffusers.pipelines.ltx.pipeline_ltx_condition.LTXVideoCondition | list[diffusers.pipelines.ltx.pipeline_ltx_condition.LTXVideoCondition] = Noneimage: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]]] = Nonevideo: list = Noneframe_index: int | list[int] = 0strength: float | list[float] = 1.0denoise_strength: float = 1.0prompt: str | list[str] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 512width: int = 704num_frames: int = 161frame_rate: int = 25num_inference_steps: int = 50timesteps: list = Noneguidance_scale: float = 3guidance_rescale: float = 0.0image_cond_noise_scale: float = 0.15num_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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonedecode_timestep: float | list[float] = 0.0decode_noise_scale: float | list[float] | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 256 ) → ~pipelines.ltx.LTXPipelineOutput or tuple

المعاملات

  • conditions (list[LTXVideoCondition], *optional*) — قائمة عناصر تكييف الإطارات لتوليد الفيديو. إذا لم تُقدَّم، فسيتم إنشاء الشروط باستخدام image وvideo وframe_index وstrength.
  • image (PipelineImageInput أو list[PipelineImageInput]، اختياري) — الصورة أو الصور التي تُشترط عليها عملية توليد الفيديو. إذا لم تُقدَّم، يجب تمرير video أو conditions.
  • video (list[PipelineImageInput], اختياري) — الفيديو الذي يُشترط على أساسه توليد الفيديو. إذا لم يُقدَّم، يجب تمرير image أو conditions.
  • frame_index (int أو list[int]، اختياري) — مؤشر الإطار أو مؤشرات الإطارات التي سيؤثر فيها الصورة أو الفيديو بشكل شرطي على توليد الفيديو. إذا لم يُقدَّم، يجب تمرير conditions.
  • strength (float أو list[float]، اختياري) — قوة أو قوى تأثير الشرط. إذا لم يُقدَّم، يجب تمرير conditions.
  • denoise_strength (float، القيمة الافتراضية 1.0) — قوة الضوضاء المضافة إلى الكمونيات (latents) لأغراض التحرير. كلما زادت القوة، زادت كمية الضوضاء المضافة إلى الكمونيات، مما يؤدي إلى زيادة الفروق بين الفيديو الأصلي والفيديو المولّد. وهذا مفيد لتحرير الفيديو إلى فيديو.
  • prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي توجّه توليد الصورة. إذا لم يُعرَّف، يجب تمرير prompt_embeds بدلاً من ذلك.
  • negative_prompt (str أو list[str]، اختياري) — الموجّه أو الموجّهات التي لا ينبغي استخدامها لتوجيه توليد الصورة. إذا لم يُعرَّف، يجب تمرير negative_prompt_embeds بدلاً منه. يتم تجاهله عند عدم استخدام التوجيه (guidance_scale < 1).
  • height (int، القيمة الافتراضية 512) — ارتفاع الصورة المولّدة بالبكسل. يتم ضبطه على 480 افتراضيًا للحصول على أفضل النتائج.
  • width (int)، القيمة الافتراضية 704) — عرض الصورة المولدة بالبكسلات. يتم ضبطه على 848 افتراضيًا للحصول على أفضل النتائج.
  • num_frames (int، القيمة الافتراضية 161) — عدد إطارات الفيديو التي سيتم توليدها
  • frame_rate (int، القيمة الافتراضية 25) — معدل الإطارات المستهدف للفيديو المولّد.
  • num_inference_steps (int، اختياري، القيمة الافتراضية 50) — عدد خطوات إزالة الضوضاء. تؤدي زيادة عدد خطوات إزالة الضوضاء عادةً إلى صورة بجودة أعلى على حساب بطء الاستدلال.
  • timesteps (list[int], اختياري) — خطوات زمنية مخصصة لاستخدامها في عملية إزالة الضوضاء مع المجدولين الذين يدعمون معامل timesteps في طريقة set_timesteps الخاصة بهم. إذا لم يُعرَّف، فسيتم استخدام السلوك الافتراضي عند تمرير num_inference_steps. يجب أن تكون بترتيب تنازلي.
  • guidance_scale (float، القيمة الافتراضية 3 ) — مقياس التوجيه كما هو مُعرَّف في Classifier-Free Diffusion Guidance. يُعرَّف guidance_scale على أنه w في المعادلة 2 من Imagen Paper. يتم تفعيل مقياس التوجيه عن طريق تعيين guidance_scale > 1. كلما زاد مقياس التوجيه، شجّع ذلك على توليد صور مرتبطة ارتباطًا وثيقًا بـ prompt النصي، وعادةً على حساب انخفاض جودة الصورة.
  • guidance_rescale (float, اختياري، القيمة الافتراضية 0.0) — معامل إعادة الضبط للتوجيه المقترح في جداول ضوضاء الانتشار الشائعة وخطوات العينة معيبة حيث يُعرَّف guidance_scale على أنه φ في المعادلة 16 من جداول ضوضاء الانتشار الشائعة وخطوات العينة معيبة. يجب أن يُصلح معامل إعادة الضبط للتوجيه مشكلة الإفراط في التعرض عند استخدام SNR نهائي صفر.
  • image_cond_noise_scale (float، القيمة الافتراضية 0.15) — مقياس الضوضاء المضافة إلى كامنات صورة الشرط.
  • num_videos_per_prompt (int، اختياري، القيمة الافتراضية 1) — عدد مقاطع الفيديو التي سيتم توليدها لكل موجه.
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — مولّد واحد أو قائمة من مولّدات torch لجعل التوليد حتميًا.
  • latents (torch.Tensor، اختياري) — كائنات latents ضجيجية مُولّدة مسبقًا، مُستخرجة من توزيع غاوسي، تُستخدم كمدخلات لتوليد الصور. يمكن استخدامها لتعديل نفس التوليد باستخدام أوامر مختلفة. إذا لم تُقدَّم، سيتم توليد كائن latents عن طريق الاستخراج باستخدام generator العشوائي المُقدَّم.
  • prompt_embeds (torch.Tensor، اختياري) — تضمينات نصية مُولَّدة مسبقًا. يمكن استخدامها لتعديل مدخلات النص بسهولة، مثلًا وزن الموجه. إذا لم تُقدَّم، فسيتم توليد تضمينات النص من معامل الإدخال prompt.
  • prompt_attention_mask (torch.Tensor، اختياري) — قناع الانتباه المُولَّد مسبقًا لتضمينات النص.
  • negative_prompt_embeds (torch.FloatTensor، اختياري) — تضمينات نصية سالبة مُولّدة مسبقًا. بالنسبة إلى PixArt-Sigma، يجب أن يكون هذا الموجه السلبي "". إذا لم يُقدَّم، فسيتم توليد negative_prompt_embeds من معامل الإدخال negative_prompt.
  • negative_prompt_attention_mask (torch.FloatTensor، اختياري) — قناع انتباه مُولّد مسبقًا لتضمينات النص السلبية.
  • decode_timestep (float، القيمة الافتراضية 0.0) — خطوة الزمن التي يتم عندها فك ترميز الفيديو المولّد.
  • decode_noise_scale (float، القيمة الافتراضية None) — عامل الاستيفاء بين الضوضاء العشوائية واللاتنتات المُزالة الضوضاء عند خطوة فك الترميز.
  • output_type (str، اختياري، القيمة الافتراضية "pil") — صيغة مخرجات توليد الصورة. اختر بين PIL: PIL.Image.Image أو np.array.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ~pipelines.ltx.LTXPipelineOutput بدلاً من tuple عادي.
  • attention_kwargs (dict، اختياري) — قاموس kwargs يُمرَّر إلى AttentionProcessor إذا تم تحديده، كما هو معرَّف تحت self.processor في diffusers.models.attention_processor.
  • callback_on_step_end (Callable، اختياري) — دالة تُستدعى في نهاية كل خطوة إزالة ضوضاء أثناء الاستدلال. تُستدعى الدالة بالحجج التالية: 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 الافتراضي 128 ) — أقصى طول تسلسل يُستخدم مع prompt.

يعيد

~pipelines.ltx.LTXPipelineOutput أو tuple

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

الدالة التي تُستدعى عند استدعاء خط الأنابيب للتوليد.

أمثلة:

>>> import torch
>>> from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXConditionPipeline, LTXVideoCondition
>>> from diffusers.utils import export_to_video, load_video, load_image

>>> pipe = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.5", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> # Load input image and video
>>> video = load_video(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4"
... )
>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input.jpg"
... )

>>> # Create conditioning objects
>>> condition1 = LTXVideoCondition(
...     image=image,
...     frame_index=0,
... )
>>> condition2 = LTXVideoCondition(
...     video=video,
...     frame_index=80,
... )

>>> 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. And then the camera switch to 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."
>>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

>>> # Generate video
>>> generator = torch.Generator("cuda").manual_seed(0)
>>> # Text-only conditioning is also supported without the need to pass `conditions`
>>> video = pipe(
...     conditions=[condition1, condition2],
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     width=768,
...     height=512,
...     num_frames=161,
...     num_inference_steps=40,
...     generator=generator,
... ).frames[0]

>>> export_to_video(video, "output.mp4", fps=24)

add_noise_to_image_conditioning_latents

< >

( t: floatinit_latents: Tensorlatents: Tensornoise_scale: floatconditioning_mask: Tensorgeneratoreps = 1e-06 )

أضف ضوضاء تعتمد على خطوة الزمن إلى الكمونيات الشرطية الصلبة. يساعد ذلك في استمرارية الحركة، خاصة عند الاشتراط على إطار واحد.

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] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 256device: 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

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

trim_conditioning_sequence

< >

( start_frame: intsequence_num_frames: inttarget_num_frames: int ) → int

المعاملات

  • start_frame (int) — رقم الإطار المستهدف للإطار الأول في التسلسل.
  • sequence_num_frames (int) — عدد الإطارات في التسلسل.
  • target_num_frames (int) — عدد الإطارات المستهدف في الفيديو المولّد.

يعيد

int

طول التسلسل المحدّث

اقتصاص تسلسل الشرط إلى عدد الإطارات المسموح به.

LTXLatentUpsamplePipeline

فئة diffusers.LTXLatentUpsamplePipeline

< >

( vae: AutoencoderKLLTXVideolatent_upsampler: LTXLatentUpsamplerModel )

__call__

< >

( video: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = Noneheight: int = 512width: int = 704latents: typing.Optional[torch.Tensor] = Nonedecode_timestep: float | list[float] = 0.0decode_noise_scale: float | list[float] | None = Noneadain_factor: float = 0.0tone_map_compression_ratio: float = 0.0generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneoutput_type: str | None = 'pil'return_dict: bool = True ) → ~pipelines.ltx.LTXPipelineOutput or tuple

المعاملات

  • video (list[PipelineImageInput], اختياري) — إطارات الفيديو المدخلة التي سيتم رفع دقتها. يتعارض مع latents.
  • height (int، القيمة الافتراضية 512) — الارتفاع بالبكسلات للمخرجات المُوسَّعة.
  • width (int، القيمة الافتراضية 704) — العرض بالبكسلات للمخرجات المُوسَّعة.
  • latents (torch.Tensor، اختياري) — كائنات فيديو مُرمّزة مسبقًا لرفع عيّنتها. يتعارض مع video.
  • decode_timestep (float أو list[float]، القيمة الافتراضية 0.0) — خطوة الزمن التي يتم فيها فك ترميز الكمون المُوسَّعة.
  • decode_noise_scale (float أو list[float]، اختياري) — معامل الاستيفاء بين الضوضاء العشوائية واللاتنتات المُزالة الضوضاء عند خطوة فك الترميز.
  • adain_factor (float، القيمة الافتراضية 0.0) — قوة مطابقة إحصاءات AdaIN المطبقة على الكمون المُوسَّع.
  • tone_map_compression_ratio (float، القيمة الافتراضية 0.0) — نسبة الضغط المستخدمة في تطبيق تدرج النغمات (tone mapping) على الكميات الكامنة المُوسَّعة. يجب أن تكون ضمن المدى [0, 1].
  • generator (torch.Generator أو list[torch.Generator]، اختياري) — torch.Generator لجعل التوليد حتميًا.
  • output_type (str، اختياري، الافتراضي "pil") — صيغة مخرجات الفيديو المولّد. اختر بين PIL.Image أو np.array أو latent.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ~pipelines.ltx.LTXPipelineOutput بدلاً من tuple عادي.

يعيد

~pipelines.ltx.LTXPipelineOutput أو tuple

~pipelines.ltx.LTXPipelineOutput إذا كان return_dict هو True، وإلا tuple. عند إرجاع tuple، يكون العنصر الأول هو الفيديو المُوسَّع (أو الكمونيات إذا كان output_type="latent").

الدالة التي تُستدعى عند استدعاء خط الأنابيب لرفع دقة الصور الكامنة.

adain_filter_latent

< >

( latents: Tensorreference_latents: Tensorfactor: float = 1.0 ) → torch.Tensor

المعاملات

  • latents (torch.Tensor) — القيم الكامنة المدخلة التي يجب تطبيعها
  • reference_latents (torch.Tensor) — القيم الكامنة المرجعية التي توفر إحصاءات الأسلوب.
  • factor (float) — معامل الدمج بين الحالة الكامنة الأصلية والحالة الكامنة المحوّلة. النطاق: من -10.0 إلى 10.0، الافتراضي: 1.0

يعيد

torch.Tensor

الموتر الكامن المُحوَّل

يطبّق تطبيع الأمثلة التكيفية (AdaIN) على متجه كامن (latent tensor) بناءً على الإحصاءات المستخرجة من متجه كامن مرجعي.

tone_map_latents

< >

( latents: Tensorcompression: float )

المعاملات

  • latents — torch.Tensor مصفوفة الكامنة (Latent) المدخلة ذات الشكل التعسفي. يُتوقع أن تكون قيمها تقريبًا ضمن النطاق [-1, 1] أو [0, 1].
  • compression — float قوة الضغط في المدى [0, 1].
    • 0.0: لا يوجد تحويل نبرة (تحويل هوية)
    • 1.0: تأثير الضغط الكامل

يطبّق دالة خرائط نغمات غير خطية على القيم الكامنة لتقليل نطاقها الديناميكي بطريقة سلسة إدراكياً باستخدام ضغط يعتمد على دالة سيجمويد.

يُعدّ هذا مفيدًا لتنظيم الكامنات عالية التباين أو لتوجيه المخرجات أثناء التوليد، لا سيما عند التحكم في السلوك الديناميكي باستخدام معامل compression.

LTXPipelineOutput

فئة diffusers.pipelines.ltx.pipeline_output.LTXPipelineOutput

< >

( frames: Tensor )

المعاملات

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

فئة الإخراج لخطوط أنابيب LTX.

Update on GitHub