Diffusers documentation

GlmImageTransformer2DModel

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

GlmImageTransformer2DModel

用于 2D 数据的 Diffusion Transformer 模型,来自 [GlmImageTransformer2DModel](TODO)。

GlmImageTransformer2DModel

class diffusers.GlmImageTransformer2DModel

< >

( patch_size: int = 2in_channels: int = 16out_channels: int = 16num_layers: int = 30attention_head_dim: int = 40num_attention_heads: int = 64text_embed_dim: int = 1472time_embed_dim: int = 512condition_dim: int = 256prior_vq_quantizer_codebook_size: int = 16384 )

参数

  • patch_size (int,默认为 2) — 用于 patch 嵌入层的 patch 大小。
  • in_channels (int,默认为 16) — 输入数据的通道数。
  • num_layers (int,默认为 30) — 要使用的 Transformer 块层数。
  • attention_head_dim (int,默认为 40) — 每个注意力头中的通道数。
  • num_attention_heads (int,默认为 64) — 多头注意力机制中使用的注意力头数量。
  • out_channels (int,默认为 16) — 输出中的通道数。
  • text_embed_dim (int,默认为 1472) — 文本编码器输出的文本嵌入的输入维度。
  • time_embed_dim (int,默认为 512) — 时间步嵌入的输出维度。
  • condition_dim (int,默认为 256) — 输入 SDXL 风格分辨率条件(original_size、target_size、crop_coords)的嵌入维度。
  • pos_embed_max_size (int,默认为 128) — 位置嵌入的最大分辨率。将从中截取形状为 H x W 的切片,并加到输入的 patch 化潜在变量上,其中 H 和 W 分别表示潜在变量的高度和宽度。值为 128 表示图像生成支持的最大高度和宽度为 128 * vae_scale_factor * patch_size => 128 * 8 * 2 => 2048。
  • sample_size (int,默认为 128) — 输入潜变量的基础分辨率。如果在生成过程中未提供 height/width,则使用该值来确定分辨率,即 sample_size * vae_scale_factor => 128 * 8 => 1024

forward

< >

( hidden_states: Tensorencoder_hidden_states: Tensorprior_token_id: Tensorprior_token_drop: Tensortimestep: LongTensortarget_size: Tensorcrop_coords: Tensorattention_kwargs: dict[str, typing.Any] | None = Nonereturn_dict: bool = Trueattention_mask: typing.Optional[torch.Tensor] = Nonekv_caches: diffusers.models.transformers.transformer_glm_image.GlmImageKVCache | None = Noneimage_rotary_emb: tuple[torch.Tensor, torch.Tensor] | list[tuple[torch.Tensor, torch.Tensor]] | None = None )

参数

  • hidden_states(形状为 (batch_size, in_channels, height, width) 的 torch.Tensor)— 输入的 hidden_states。
  • encoder_hidden_states (torch.Tensor,形状为 (batch_size, sequence_len, embed_dims)) — 要使用的条件嵌入(从输入条件(例如提示词)计算得出的嵌入)。
  • prior_token_id (torch.Tensor) — 用于先前嵌入查找的 token id。
  • prior_token_drop (torch.Tensor) — 布尔掩码,指示应丢弃(置零)哪些先验嵌入。
  • timestep (torch.LongTensor) — 用于指示去噪步骤。
  • target_size (torch.Tensor) — 目标图像尺寸条件。
  • crop_coords (torch.Tensor) — 裁剪坐标条件。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.transformer_2d.Transformer2DModelOutput 而不是普通的元组。
  • attention_mask (torch.Tensor, 可选) — 应用于注意力分数的掩码。
  • kv_caches (GlmImageKVCache,可选) — 预计算的键/值缓存,用于加速推理。
  • image_rotary_emb (tuple of torch.Tensor, 可选) — 预计算的旋转位置嵌入。

GlmImageTransformer2DModel 的前向方法。

Update on GitHub