Diffusers documentation

AnyFlowTransformer3DModel

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

AnyFlowTransformer3DModel

由 AnyFlowPipeline. 使用的双向 3D Transformer。它是 v0.35.1 Wan2.1 主干网络,但有一处结构变更:时间步嵌入器被替换为 AnyFlowDualTimestepTextImageEmbedding, ,因此每次前向调用都会同时以源时间步 t 和目标时间步 r. 作为条件。这是学习 Φr←t\Phi_{r\leftarrow t} 中引入的流映射 所需的嵌入。. 请参阅 AnyFlowPipeline 页面,了解相关论文、作者及发布的检查点。

对于分块自回归(FAR 因果)生成,请改用 AnyFlowFARTransformer3DModel。

from diffusers import AnyFlowTransformer3DModel

# Bidirectional AnyFlow checkpoint (T2V):
transformer = AnyFlowTransformer3DModel.from_pretrained(
    "nvidia/AnyFlow-Wan2.1-T2V-1.3B-Diffusers", subfolder="transformer"
)

AnyFlowTransformer3DModel

类 diffusers.AnyFlowTransformer3DModel

< >

( patch_size: typing.Tuple[int] = (1, 2, 2)num_attention_heads: int = 40attention_head_dim: int = 128in_channels: int = 16out_channels: int = 16text_dim: int = 4096freq_dim: int = 256ffn_dim: int = 13824num_layers: int = 40cross_attn_norm: bool = Trueeps: float = 1e-06image_dim: typing.Optional[int] = Nonerope_max_seq_len: int = 1024gate_value: float = 0.25deltatime_type: str = 'r' )

参数

  • patch_size (Tuple[int],默认为 (1, 2, 2)) — 用于视频嵌入的 3D patch 维度 (t_patch, h_patch, w_patch)。
  • num_attention_heads (int,默认为 40) — 注意力头的数量。
  • attention_head_dim (int,默认为 128) — 每个头中的通道数。
  • in_channels (int,默认为 16) — 输入潜在变量的通道数。
  • out_channels (int,默认为 16) — 输出潜在张量的通道数。
  • text_dim (int,默认为 4096) — 文本嵌入(UMT5)的输入维度。
  • freq_dim (int,默认为 256) — 正弦时间嵌入的维度。
  • ffn_dim (int,默认为 13824) — 前馈网络中的中间维度。
  • num_layers (int,默认为 40) — Transformer 块的数量。
  • cross_attn_norm (bool,默认为 True) — 启用交叉注意力归一化。
  • eps (float,默认为 1e-6) — 归一化层的 epsilon 值。
  • image_dim (Optional[int], 可选, 默认为 None) — 用于 I2V 条件化的图像嵌入维度(原始 Wan2.1-I2V 模型为 1280)。
  • rope_max_seq_len (int,默认为 1024) — 用于预计算旋转位置频率的最大序列长度。
  • gate_value (float, defaults to 0.25) — Mixing gate between source-timestep and delta-timestep embeddings (the AnyFlow paper’s{@html "ggg"} parameter, fixed at 0.25 in stage-1 distillation).
  • deltatime_type (str,默认为 ‘r’) — 可以是 "r"(delta 为目标时间步)或 "t-r"(delta 为绝对间隔)。

用于 AnyFlow 流图采样的双向 3D Transformer。

该架构基于 v0.35.1 Wan2.1 3D DiT 骨干网络,并做了一处结构性改动:将时间步嵌入器替换为 AnyFlowDualTimestepTextImageEmbedding ,使得每次前向调用都同时以源时间步 t 和目标时间步 r. 作为条件。这是学习Φr←t\Phi_{r\leftarrow t} 中引入的流映射 所需的嵌入。.

对于分块自回归(FAR causal)生成,请改用 AnyFlowFARTransformer3DModel;该变体在相同的骨干网络之上增加了 FAR causal 块掩码和压缩帧补丁嵌入。

forward

< >

( hidden_states: Tensortimestep: Tensorr_timestep: Tensorencoder_hidden_states: Tensorencoder_hidden_states_image: typing.Optional[torch.Tensor] = Noneattention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = Nonereturn_dict: bool = True )

参数

  • hidden_states(形状为 (batch_size, num_frames, num_channels, height, width) 的 torch.Tensor)— 输入视频潜变量。
  • timestep (torch.Tensor) — 源(噪声更大)流映射时间步 t。
  • r_timestep (torch.Tensor) — 目标(更干净的)流映射时间步 r;定义流映射步骤的目标位置。
  • encoder_hidden_states (torch.Tensor,形状为 (batch_size, sequence_len, embed_dims)) — 文本条件嵌入。
  • encoder_hidden_states_image (torch.Tensor,可选) — 图像条件嵌入;如果提供,将在文本标记之前进行拼接。
  • attention_kwargs (dict, 可选) — 转发给 diffusers.models.attention_processor 中 self.processor 下定义的 AttentionProcessor 的关键字参数。
  • return_dict (bool,可选,默认为 True) — 是否返回 [~models.transformer_2d.Transformer2DModelOutput] 而不是普通元组。

双向流图前向传播。hidden_states 的布局为 (B, F, C, H, W)(逐帧潜在变量)。 输入通过标准的 patch_embedding(kernel = stride = patch_size)进行分块, 并对由此得到的扁平 token 序列执行全局双向自注意力去噪。

Update on GitHub