Diffusers documentation

DiTTransformer2DModel

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

DiTTransformer2DModel

用于类图像数据的 Transformer 模型,源自 DiT。

DiTTransformer2DModel

class diffusers.DiTTransformer2DModel

< >

( num_attention_heads: int = 16attention_head_dim: int = 72in_channels: int = 4out_channels: int | None = Nonenum_layers: int = 28dropout: float = 0.0norm_num_groups: int = 32attention_bias: bool = Truesample_size: int = 32patch_size: int = 2activation_fn: str = 'gelu-approximate'num_embeds_ada_norm: int | None = 1000upcast_attention: bool = Falsenorm_type: str = 'ada_norm_zero'norm_elementwise_affine: bool = Falsenorm_eps: float = 1e-05 )

参数

  • num_attention_heads(int,可选,默认为 16)— 多头注意力机制中使用的注意力头数量。
  • attention_head_dim(int,可选,默认值为 72)— 每个注意力头中的通道数。
  • in_channels (int,默认为 4) — 输入数据的通道数。
  • out_channels (int, optional) — 输出中的通道数。如果输出通道数与输入不同,请指定此参数。
  • num_layers(int,可选,默认为 28)— 要使用的 Transformer 块层数。
  • dropout(float,可选,默认为 0.0)— 在 Transformer 块中使用的 dropout 概率。
  • norm_num_groups (int, 可选,默认为 32) — Transformer 块内组归一化的组数。
  • attention_bias(bool,可选,默认为 True)— 配置 Transformer 块中的注意力机制是否包含偏置参数。
  • sample_size (int, 默认为 32) — 潜在图像的宽度。此参数在训练过程中是固定的。
  • patch_size (int, 默认为 2) — 模型处理的块大小,适用于处理非顺序数据的架构。
  • activation_fn (str, optional, defaults to “gelu-approximate”) — Transformer 块中前馈网络所使用的激活函数。
  • num_embeds_ada_norm (int, 可选, 默认为 1000) — AdaLayerNorm 的嵌入数量,在训练期间固定,并影响推理时的最大去噪步数。
  • upcast_attention(bool,可选,默认为 False)— 如果为 true,则提升注意力机制的维度,以可能获得更好的性能。
  • norm_type (str, optional, defaults to “ada_norm_zero”) — 指定所使用的归一化类型,可以是 ‘ada_norm_zero’。
  • norm_elementwise_affine(bool,可选,默认为 False) — 如果为 true,则在归一化层中启用逐元素仿射参数。
  • norm_eps(float,可选,默认为 1e-5)—— 在归一化层中添加到分母的一个小常数,用于防止除以零。

DiT(https://huggingface.co/papers/2212.09748)中介绍的 2D Transformer 模型。

forward

< >

( hidden_states: Tensortimestep: typing.Optional[torch.LongTensor] = Noneclass_labels: typing.Optional[torch.LongTensor] = Nonecross_attention_kwargs: dict = Nonereturn_dict: bool = True )

参数

  • hidden_states(如果为离散值,则为形状 (batch size, num latent pixels) 的 torch.LongTensor;如果为连续值,则为形状 (batch size, channel, height, width) 的 torch.FloatTensor) — 输入 hidden_states。
  • timestep ( torch.LongTensor, 可选) — 用于指示去噪步骤。作为嵌入应用于 AdaLayerNorm 的可选时间步。
  • class_labels ( torch.LongTensor,形状为 (batch size, num classes),可选) — 用于指示类别标签条件。作为嵌入应用于 AdaLayerZeroNorm 的可选类别标签。
  • cross_attention_kwargs ( dict[str, Any], 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中 self.processor 下定义的 AttentionProcessor。
  • return_dict (bool,可选,默认为 True) — 是否返回 UNet2DConditionOutput 而不是普通元组。

DiTTransformer2DModel 的前向方法。

Update on GitHub