Diffusers documentation

HunyuanVideoTransformer3DModel

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

HunyuanVideoTransformer3DModel

腾讯在 HunyuanVideo: A Systematic Framework For Large Video Generative Models 中介绍了一种用于 3D 类视频数据的 Diffusion Transformer 模型。

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

from diffusers import HunyuanVideoTransformer3DModel

transformer = HunyuanVideoTransformer3DModel.from_pretrained("hunyuanvideo-community/HunyuanVideo", subfolder="transformer", dtype=torch.bfloat16)

HunyuanVideoTransformer3DModel

class diffusers.HunyuanVideoTransformer3DModel

< >

( in_channels: int = 16out_channels: int = 16num_attention_heads: int = 24attention_head_dim: int = 128num_layers: int = 20num_single_layers: int = 40num_refiner_layers: int = 2mlp_ratio: float = 4.0patch_size: int = 2patch_size_t: int = 1qk_norm: str = 'rms_norm'guidance_embeds: bool = Truetext_embed_dim: int = 4096pooled_projection_dim: int = 768rope_theta: float = 256.0rope_axes_dim: tuple = (16, 56, 56)image_condition_type: str | None = None )

参数

  • in_channels (int,默认为 16) — 输入数据的通道数。
  • out_channels (int,默认为 16) — 输出中的通道数。
  • num_attention_heads (int,默认为 24) — 多头注意力机制中使用的注意力头数量。
  • attention_head_dim (int,默认为 128) — 每个头中的通道数。
  • num_layers (int,默认为 20) — 要使用的双流块层数。
  • num_single_layers (int,默认为 40) — 要使用的单流块层数。
  • num_refiner_layers (int,默认为 2) — 要使用的 refiner 块层数。
  • mlp_ratio (float,默认为 4.0) — 前馈网络中隐藏层大小与输入大小的比率。
  • patch_size (int,默认为 2) — 用于 patch 嵌入层的空间 patch 大小。
  • patch_size_t (int,默认为 1) — 用于 patch 嵌入层的时间 patch 大小。
  • qk_norm (str,默认为 rms_norm) — 注意力层中查询和键投影所使用的归一化方法。
  • guidance_embeds (bool,默认为 True) — 是否在模型中使用 guidance embeddings。
  • text_embed_dim (int,默认为 4096) — 来自文本编码器的文本嵌入的输入维度。
  • pooled_projection_dim (int,默认为 768) — 文本嵌入池化投影的维度。
  • rope_theta (float,默认为 256.0) — RoPE 层中使用的 theta 值。
  • rope_axes_dim (tuple[int],默认为 (16, 56, 56)) — RoPE 层中使用的各轴维度。
  • image_condition_type (str, 可选, 默认为 None) — 要使用的图像条件类型。如果为 None,则不使用图像条件。如果为 latent_concat,则将图像拼接到潜在流中。如果为 token_replace,则使用图像替换潜在流中的首帧 token 并应用条件。

用于 HunyuanVideo 的、处理类视频数据的 Transformer 模型。

forward

< >

( hidden_states: Tensortimestep: LongTensorencoder_hidden_states: Tensorencoder_attention_mask: Tensorpooled_projections: Tensorguidance: Tensor = Noneattention_kwargs: dict[str, typing.Any] | None = Nonereturn_dict: bool = True )

参数

  • hidden_states(形状为 (batch_size, num_channels, num_frames, height, width) 的 torch.Tensor)— 输入的 hidden_states。
  • timestep (torch.LongTensor) — 用于指示去噪步骤。
  • encoder_hidden_states (torch.Tensor,形状为 (batch_size, sequence_len, embed_dims)) — 要使用的条件嵌入(从输入条件(例如提示词)计算得出的嵌入)。
  • encoder_attention_mask (torch.Tensor) — 在注意力机制中应用于 encoder_hidden_states 的掩码。
  • pooled_projections(形状为 (batch_size, projection_dim) 的 torch.Tensor)— 由输入条件的嵌入投影得到的嵌入。
  • guidance (torch.Tensor, 可选) — 用于模型引导蒸馏变体的引导尺度嵌入。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.transformer_2d.Transformer2DModelOutput 而不是普通的元组。

HunyuanVideoTransformer3DModel 的前向方法。

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