Diffusers documentation

OvisImageTransformer2DModel

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

OvisImageTransformer2DModel

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

from diffusers import OvisImageTransformer2DModel

transformer = OvisImageTransformer2DModel.from_pretrained("AIDC-AI/Ovis-Image-7B", subfolder="transformer", dtype=torch.bfloat16)

OvisImageTransformer2DModel

class diffusers.OvisImageTransformer2DModel

< >

( patch_size: int = 1in_channels: int = 64out_channels: int | None = 64num_layers: int = 6num_single_layers: int = 27attention_head_dim: int = 128num_attention_heads: int = 24joint_attention_dim: int = 2048axes_dims_rope: tuple[int, int, int] = (16, 56, 56) )

参数

  • patch_size (int,默认为 1) — 用于将输入数据划分为小块的块大小。
  • in_channels (int,默认为 64) — 输入数据的通道数。
  • out_channels (int,可选,默认为 None) — 输出通道数。如果未指定,则默认为 in_channels。
  • num_layers (int,默认为 6) — 要使用的双流 DiT 块层数。
  • num_single_layers (int,默认为 27) — 要使用的单流 DiT 块层数。
  • attention_head_dim (int,默认为 128) — 每个注意力头使用的维度数。
  • num_attention_heads (int,默认为 24) — 要使用的注意力头数量。
  • joint_attention_dim (int,默认为 2048) — 用于联合注意力的维度数(encoder_hidden_states 的嵌入/通道维度)。
  • axes_dims_rope (tuple[int],默认为 (16, 56, 56)) — 用于旋转位置嵌入的维度。

Ovis-Image 中引入的 Transformer 模型。

参考:https://github.com/AIDC-AI/Ovis-Image

forward

< >

( hidden_states: Tensorencoder_hidden_states: Tensor = Nonetimestep: LongTensor = Noneimg_ids: Tensor = Nonetxt_ids: Tensor = Nonejoint_attention_kwargs: dict[str, typing.Any] | None = 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)— 要使用的条件嵌入(由输入条件(例如提示词)计算得出的嵌入)。
  • timestep (torch.LongTensor) — 用于指示去噪步骤。
  • img_ids — (torch.Tensor): 图像标记的位置 ID。
  • txt_ids (torch.Tensor) — 文本 token 的位置 ID。
  • joint_attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将作为参数传递给 diffusers.models.attention_processor 中 self.processor 下定义的 AttentionProcessor。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.transformer_2d.Transformer2DModelOutput 而不是普通的元组。

OvisImageTransformer2DModel 的 forward 方法。

Update on GitHub