Diffusers documentation

LTXVideoTransformer3DModel

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

LTXVideoTransformer3DModel

Lightricks 推出了一款用于 3D 数据的 Diffusion Transformer 模型,来自 LTX。

可以使用以下代码片段加载该模型。

from diffusers import LTXVideoTransformer3DModel

transformer = LTXVideoTransformer3DModel.from_pretrained("Lightricks/LTX-Video", subfolder="transformer", dtype=torch.bfloat16).to("cuda")  # or "mps", "xpu", "cpu"

LTXVideoTransformer3DModel

class diffusers.LTXVideoTransformer3DModel

< >

( in_channels: int = 128out_channels: int = 128patch_size: int = 1patch_size_t: int = 1num_attention_heads: int = 32attention_head_dim: int = 64cross_attention_dim: int = 2048num_layers: int = 28activation_fn: str = 'gelu-approximate'qk_norm: str = 'rms_norm_across_heads'norm_elementwise_affine: bool = Falsenorm_eps: float = 1e-06caption_channels: int = 4096attention_bias: bool = Trueattention_out_bias: bool = True )

参数

  • in_channels (int,默认为 128) — 输入中的通道数。
  • out_channels (int,默认为 128) — 输出中的通道数。
  • patch_size (int,默认为 1) — 用于 patch 嵌入层的空间 patch 大小。
  • patch_size_t (int,默认为 1) — 用于 patch 嵌入层的时间 patch 大小。
  • num_attention_heads (int,默认为 32) — 多头注意力机制中使用的注意力头数量。
  • attention_head_dim (int,默认为 64) — 每个头中的通道数。
  • cross_attention_dim (int,默认为 2048 ) — 交叉注意力头的通道数。
  • num_layers (int,默认为 28) — 要使用的 Transformer 块层数。
  • activation_fn (str,默认为 "gelu-approximate") — 前馈网络中使用的激活函数。
  • qk_norm (str,默认为 "rms_norm_across_heads") — 要使用的归一化层。

用于 LTX 中类视频数据的 Transformer 模型。

forward

< >

( hidden_states: Tensorencoder_hidden_states: Tensortimestep: LongTensorencoder_attention_mask: Tensornum_frames: int | None = Noneheight: int | None = Nonewidth: int | None = Nonerope_interpolation_scale: typing.Union[tuple[float, float, float], torch.Tensor, NoneType] = Nonevideo_coords: typing.Optional[torch.Tensor] = Noneattention_kwargs: dict[str, typing.Any] | None = Nonereturn_dict: bool = True ) → torch.Tensor

参数

  • hidden_states(形状为 (batch_size, sequence_length, in_channels) 的 torch.Tensor)— 输入的 hidden_states。
  • encoder_hidden_states (torch.Tensor,形状为 (batch_size, sequence_len, embed_dims)) — 要使用的条件嵌入(从输入条件(例如提示词)计算得出的嵌入)。
  • timestep (torch.LongTensor) — 用于指示去噪步骤。
  • encoder_attention_mask (torch.Tensor) — 在注意力机制中应用于 encoder_hidden_states 的掩码。
  • num_frames (int, 可选) — 用于计算旋转位置嵌入的视频帧数。
  • height (int, 可选) — 用于计算旋转位置嵌入的潜在表示的高度。
  • width (int, 可选) — 用于计算旋转位置嵌入的潜在表示的宽度。
  • rope_interpolation_scale (tuple of float or torch.Tensor, 可选) — 旋转位置嵌入所使用的插值比例。
  • video_coords (torch.Tensor, 可选) — 预计算的用于旋转位置嵌入的视频坐标。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.transformer_2d.Transformer2DModelOutput 而不是普通的元组。

返回值

torch.Tensor

形状为 (batch_size, sequence_length, out_channels) 的去噪输出张量。

LTXVideoTransformer3DModel 的前向方法。

Transformer2DModelOutput

类 diffusers.models.modeling_outputs.Transformer2DModelOutput

< >

( sample: torch.Tensor )

参数

  • sample(形状为 (batch_size, num_channels, height, width) 的 torch.Tensor,或者如果 Transformer2DModel 是离散的,则为 (batch size, num_vector_embeds - 1, num_latent_pixels))— 以 encoder_hidden_states 输入为条件的隐藏状态输出。如果是离散的,则返回未加噪潜在像素的概率分布。

Transformer2DModel 的输出。

Update on GitHub