Diffusers documentation

LTX2VideoDiffusionDecoderModel

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

LTX2VideoDiffusionDecoderModel

Lightricks의 LTX-2.5에서 도입된 diffusion video decoder입니다. Neighborhood-attention 단계는 latent를 context volume으로 upsample하고, 최종 단계는 해당 context에 조건부으로 픽셀의 노이즈를 제거합니다.

이것은 오토인코더가 아닌 디코더입니다. 인코딩은 AutoencoderKLLTX2Video에 남아 있으며, 이 모델은 해당 모델의 잠재 공간(latent space)을 그대로 소비하므로, 컨볼루션 디코더와 이 디코더 간에 잠재 변수(latents)를 상호 교환할 수 있습니다. 이 모델 자체가 확산 모델(diffusion model)이므로, 파이프라인의 vae로 전달되는 대신 LTX2VideoDiffusionDecodePipeline에 의해 구동됩니다. output_type="latent"로 LTX-2 파이프라인을 실행한 후 디코딩하면 됩니다.

import torch
from diffusers import LTX2Pipeline, LTX2VideoDiffusionDecodePipeline, LTX2VideoDiffusionDecoderModel

pipe = LTX2Pipeline.from_pretrained("Lightricks/LTX-2.5-Diffusers", dtype=torch.bfloat16).to("cuda")  # or "mps", "xpu", "cpu"
latents = pipe(prompt="a potter shaping a clay vase", output_type="latent").frames

decoder = LTX2VideoDiffusionDecoderModel.from_pretrained(
    "Lightricks/LTX-2.5-Diffusers", subfolder="diffusion_decoder", dtype=torch.bfloat16
).to("cuda")
decode_pipe = LTX2VideoDiffusionDecodePipeline(diffusion_decoder=decoder, scheduler=pipe.scheduler)

# `denormalize=False`: `output_type="latent"` already applied the latent statistics, so applying them
# again here would scale every channel by its std a second time.
# The decoder also draws the noise it denoises, so decoding is only reproducible with a generator.
video = decode_pipe(
    latents, generator=torch.Generator("cuda").manual_seed(0), denormalize=False
).frames[0]

vae는 디코딩 파이프라인의 선택적 구성 요소입니다. denormalize=True인 경우에만 잠재 통계에 대해 참조되며, 디코더는 자체적으로 이를 보유하고 있으므로 디코딩 전용 워크플로에서는 두 번째 오토인코더를 로드할 필요가 없습니다.

Attention 백엔드

neighborhood-attention 윈도우는 BlockMask로 표현되므로, 디코더는 기본적으로 flex attention 백엔드에서 실행되며 추가적인 의존성이 필요하지 않습니다. PyTorch는 명시적으로 요청하지 않는 한 flex_attention을 컴파일하지 않으며, 컴파일되지 않은 상태에서는 전체 score matrix를 materialize합니다. 이는 full-resolution 시퀀스 길이에서는 비현실적입니다. 이러한 경우, 디코더를 컴파일하거나 원래 구현에서도 사용하는 NATTEN의 커널로 전환할 수 있습니다. 프로세서가 kernels 패키지를 통해 Hub(shi-labs/natten)에서 NATTEN을 가져오므로, 로컬 NATTEN 빌드 대신 pip install kernels가 필요합니다:

from diffusers.models.autoencoders.ltx2_diffusion_decoder import LTX2VideoVaeNeighborhoodNattenProcessor

decoder.set_attn_processor(LTX2VideoVaeNeighborhoodNattenProcessor())

Hub에서 커널 다운로드 코드를 가져오므로, DIFFUSERS_DISABLE_REMOTE_CODE=true로 원격 코드가 전역적으로 비활성화된 경우 프로세서가 예외를 발생시킵니다.

디코더의 모든 attention 모듈은 동일한 neighborhood attention입니다(커널 크기 같은 단계별 차이는 프로세서가 아닌 모듈에 존재하므로), set_attn_processor는 이를 하나의 공유 인스턴스로 모두 교체합니다.

flex가 아닌 다른 backend로 변경하면(decoder.set_attention_backend(...)) BlockMask를 다른 어떤 backend도 지원하지 않으므로 예외가 발생합니다. 대신 위의 NATTEN 프로세서를 사용하세요.

타일링

decoder.enable_tiling()는 오버랩되는 타일 단위로 디코딩한 뒤 이를 블렌딩하여 결합하며, 피크 메모리를 비디오 크기가 아닌 타일 크기로 제한합니다. 비용이 낮은 초기 업샘플링 단계는 여전히 전체 latent를 확인하지만, 디코딩 메모리를 지배하는 마지막 업샘플링 단계와 diffusion 단계만 타일별로 실행되므로 타일링은 타일 경계 근처에서만 출력을 변경합니다. diffusion 단계가 각 타일을 개별적으로 디노이즈하기 때문에 타일링된 디코딩은 타일링되지 않은 결과를 정확히 재현하지 않으며, 기본 타일 및 오버랩 크기는 참조 구현과 일치합니다. Neighborhood attention은 커널보다 작은 그리드를 거부하므로, 끝부분의 잔여 타일은 단독으로 디코딩되지 않고 이웃 타일에 병합됩니다.

LTX2VideoDiffusionDecoderModel

클래스 diffusers.LTX2VideoDiffusionDecoderModel

< >

( out_channels: int = 3latent_channels: int = 128patch_size: int = 4scaling_factor: float = 1.0decoder_head_dim: int = 64decoder_stage_channels: tuple = (2048, 1024, 512, 512, 256)decoder_stage_depths: tuple = (4, 6, 4, 2, 8)decoder_stage_kernels: tuple = ((3, 7, 7), (3, 7, 7), (3, 5, 5), (3, 5, 5))decoder_upsample_strides: tuple = ((1, 2, 2), (2, 1, 1), (2, 2, 2), (2, 2, 2))decoder_upsample_channel_reductions: tuple = (2, 2, 1, 2)decoder_stage5_kernel: tuple = (11, 11, 11)decoder_t_emb_dim: int = 384decoder_timestep_scale_multiplier: float = 1000.0decoder_model_output_type: str = 'x0'decoder_num_inference_steps: int = 1spatial_compression_ratio: int = 32temporal_compression_ratio: int = 8 )

LTX-2.5에서 소개된 LTX-2 diffusion video decoder입니다.

이것은 디코더이며 오토인코더가 아닙니다. 인코더가 없으며 latents를 생성할 수 없습니다. 인코딩은 AutoencoderKLLTX2Video에서 수행되며, 이 모델은 해당 모델의 latent space를 그대로 소비하므로 latents는 컨볼루션 디코더와 이 디코더 사이에 호환됩니다.

이는 결정론적 디코더가 아닌 확산 모델이며, latents에서 구축된 컨텍스트 볼륨에 조건부 설정된 픽셀의 노이즈를 제거합니다. 따라서 파이프라인의 vae로 전달되는 것이 아니라 LTX2VideoDiffusionDecodePipeline에 의해 구동됩니다.

latent statistics는 버퍼로 유지되며, 이를 통해 디코딩 파이프라인은 두 개의 벡터만을 위해 별도의 autoencoder를 로드하지 않고도 비정규화(denormalize)를 수행할 수 있습니다.

이 모델은 ModelMixin에서 상속됩니다. 모든 모델에 대해 구현된 일반적 메서드(다운로드 또는 저장 등)에 대해서는 상위 클래스 문서를 확인하세요.

decode

< >

( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonenum_inference_steps: int | None = Nonereturn_dict: bool = True )

latents 배치 디코딩

z는 이미 비정규화되어 있을 것으로 예상됩니다(파이프라인이 latents_mean / latents_std를 적용하므로) AutoencoderKLLTX2Video와 일치합니다. 이 디코더는 노이즈를 제거하므로 재현성을 위해 generator를 전달하세요.

enable_tiling

< >

( tile_sample_min_height: int | None = Nonetile_sample_min_width: int | None = Nonetile_sample_min_num_frames: int | None = Nonetile_sample_stride_height: int | None = Nonetile_sample_stride_width: int | None = Nonetile_sample_stride_num_frames: int | None = None )

매개변수

  • tile_sample_min_height (int, 선택 사항) — 픽셀 단위로, 디코딩된 타일 하나의 높이입니다.
  • tile_sample_min_width (int, 선택 사항) — 픽셀 단위로, 디코딩된 타일 하나의 너비입니다.
  • tile_sample_min_num_frames (int, 선택 사항) — 해독된 타일 하나의 프레임 수입니다.
  • tile_sample_stride_height (int, 선택 사항) — 연속된 두 세로 타일의 상단 사이의 픽셀 단위 거리입니다. tile_sample_min_height와의 차이는 블렌딩 오버랩입니다.
  • tile_sample_stride_width (int, 선택 사항) — 연속된 두 수평 타일의 왼쪽 가장자리 사이의 픽셀 단위 거리입니다.
  • tile_sample_stride_num_frames (int, 선택 사항) — 연속된 두 개의 시간 타일 시작 지점 사이의 프레임 간격입니다.

타일 디코딩을 활성화합니다. 마지막 단계를 제외한 결정론적 업샘플링 단계는 항상 전체 latent를 처리합니다(낮은 해상도로 실행되며 비용이 적게 듭니다). 디코딩 메모리를 지배하는 마지막 단계와 stage-5 diffusion 블록은 선형으로 블렌딩된 이음을 가진 겹치는 타일에서 실행됩니다.

disable_tiling

< >

( )

tile 디코딩을 비활성화하여 전체 비디오를 한 번에 디코딩하도록 합니다.

forward

< >

( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonenum_inference_steps: int | None = Nonereturn_dict: bool = True ) → DecoderOutput or tuple

매개변수

  • z (torch.Tensor) — (B, C, F, H, W) 형태의 Latents. 이미 비정규화(denormalized)되어 있어야 하며, 파이프라인이 latents_mean / latents_std를 적용합니다. AutoencoderKLLTX2Video와 일치해야 합니다.
  • generator (torch.Generator, 선택 사항) — 이 디코더는 노이즈를 제거하므로, 디코딩을 재현 가능하게 하려면 생성자를 전달하세요.
  • num_inference_steps (int, 선택 사항) — 디노이징 단계 수. 기본값은 디코더의 decoder_num_inference_steps 설정 값입니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 DecoderOutput를 반환할지 여부.

반환값

DecoderOutput 또는 tuple

tiled_decode

< >

( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonenum_inference_steps: int | None = None )

마지막 결정론적 단계와 타일별로 실행되는 diffusion 단계를 사용하여 latent 배치 하나를 디코딩합니다.

Tiles은 마지막 결정론적 단계에 진입하는 그리드에 존재하며, 이 단계에서는 하나의 셀이 출력 픽셀의 고정 블록에 매핑됩니다. tile_sample_* 크기는 해당 그리드로 변환되므로 셀 크기(프로덕션 구성의 경우 공간적으로 8px, 시간적으로 2프레임)의 배수여야 합니다. 시간적 Tiles은 인과적 프레임 매핑을 따릅니다. t=0을 포함하는 Tiles는 시간적 업샘플링의 중복된 앞선 프레임을 제거하고, 비디오 끝을 포함하는 Tiles만 NATTEN 경계 패딩을 적용합니다.

Update on GitHub