Diffusers documentation

CogView4Transformer2DModel

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

CogView4Transformer2DModel

来自 CogView4 的用于 2D 数据的 Diffusion Transformer 模型

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

from diffusers import CogView4Transformer2DModel

transformer = CogView4Transformer2DModel.from_pretrained("THUDM/CogView4-6B", subfolder="transformer", dtype=torch.bfloat16).to("cuda")  # or "mps", "xpu", "cpu"

CogView4Transformer2DModel

类 diffusers.CogView4Transformer2DModel

< >

( patch_size: int = 2in_channels: int = 16out_channels: int = 16num_layers: int = 30attention_head_dim: int = 40num_attention_heads: int = 64text_embed_dim: int = 4096time_embed_dim: int = 512condition_dim: int = 256pos_embed_max_size: int = 128sample_size: int = 128rope_axes_dim: tuple[int, int] = (256, 256) )

参数

  • 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,默认为 4096) — 来自文本编码器的文本嵌入的输入维度。
  • 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: Tensortimestep: LongTensororiginal_size: Tensortarget_size: Tensorcrop_coords: Tensorattention_kwargs: dict[str, typing.Any] | None = Nonereturn_dict: bool = Trueattention_mask: typing.Optional[torch.Tensor] = 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)) — 要使用的条件嵌入(从输入条件(例如提示词)计算得出的嵌入)。
  • timestep (torch.LongTensor) — 用于指示去噪步骤。
  • original_size (torch.Tensor) — 原始图像尺寸条件。
  • 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, 可选) — 应用于注意力分数的掩码。
  • image_rotary_emb (tuple of torch.Tensor, 可选) — 预计算的旋转位置嵌入。

CogView4Transformer2DModel 的前向方法。

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