Diffusers documentation

QwenImageTransformer2DModel

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

QwenImageTransformer2DModel

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

from diffusers import QwenImageTransformer2DModel

transformer = QwenImageTransformer2DModel.from_pretrained("Qwen/QwenImage-20B", subfolder="transformer", dtype=torch.bfloat16)

QwenImageTransformer2DModel

类 diffusers.QwenImageTransformer2DModel

< >

( patch_size: int = 2in_channels: int = 64out_channels: int | None = 16num_layers: int = 60attention_head_dim: int = 128num_attention_heads: int = 24joint_attention_dim: int = 3584guidance_embeds: bool = Falseaxes_dims_rope: tuple[int, int, int] = (16, 56, 56)zero_cond_t: bool = Falseuse_additional_t_cond: bool = Falseuse_layer3d_rope: bool = False )

参数

  • patch_size (int,默认为 2) — 用于将输入数据划分为小块的块大小。
  • in_channels (int,默认为 64) — 输入数据的通道数。
  • out_channels (int,可选,默认为 None) — 输出通道数。如果未指定,则默认为 in_channels。
  • num_layers (int,默认为 60) — 要使用的双流 DiT 块层数。
  • attention_head_dim (int,默认为 128) — 每个注意力头使用的维度数。
  • num_attention_heads (int,默认为 24) — 要使用的注意力头数量。
  • joint_attention_dim (int,默认为 3584) — 用于联合注意力的维度数(encoder_hidden_states 的嵌入/通道维度)。
  • guidance_embeds(bool,默认为 False)— 是否对模型的 guidance 蒸馏变体使用 guidance 嵌入。
  • axes_dims_rope (tuple[int],默认为 (16, 56, 56)) — 用于旋转位置嵌入的维度。

Qwen 中引入的 Transformer 模型。

forward

< >

( hidden_states: Tensorencoder_hidden_states: Tensor = Noneencoder_hidden_states_mask: Tensor = Nonetimestep: LongTensor = Noneimg_shapes: list[tuple[int, int, int]] | None = Noneguidance: Tensor = Noneattention_kwargs: dict[str, typing.Any] | None = Nonecontrolnet_block_samples = Noneadditional_t_cond = Nonereturn_dict: bool = True )

参数

  • hidden_states(形状为 (batch_size, image_sequence_length, in_channels) 的 torch.Tensor)— 输入的 hidden_states。
  • encoder_hidden_states(形状为 (batch_size, text_sequence_length, joint_attention_dim) 的 torch.Tensor)— 要使用的条件嵌入(由输入条件(例如提示词)计算得出的嵌入)。
  • encoder_hidden_states_mask (torch.Tensor,形状为 (batch_size, text_sequence_length),可选) — 编码器隐藏状态的掩码。有效 token 处应为 1.0,填充 token 处应为 0.0。 该掩码在注意力处理器中使用,以防止注意力机制关注填充 token。由于掩码在注意力计算中是逐元素应用的,因此它可以具有任意模式(而不仅仅是连续的有效 token 后跟填充)。
  • timestep ( torch.LongTensor) — 用于指示去噪步骤。
  • img_shapes (list[tuple[int, int, int]],可选) — 用于 RoPE 计算的图像形状。
  • guidance (torch.Tensor, 可选) — 用于条件生成的引导张量。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • controlnet_block_samples(可选)— 要添加到 transformer 块中的 ControlNet 块样本。
  • additional_t_cond (torch.Tensor,可选) — 添加到时间步嵌入中的额外时间步条件。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.transformer_2d.Transformer2DModelOutput 而不是普通的元组。

QwenTransformer2DModel 的前向方法。

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