Diffusers documentation

Ideogram4Transformer2DModel

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

Ideogram4Transformer2DModel

来自 Ideogram 4 的用于类图像数据的 transformer。

Ideogram4Transformer2DModel

class diffusers.Ideogram4Transformer2DModel

< >

( in_channels: int = 128num_layers: int = 34attention_head_dim: int = 256num_attention_heads: int = 18intermediate_size: int = 12288adaln_dim: int = 512llm_features_dim: int = 53248rope_theta: int = 5000000mrope_section: tuple = (24, 20, 20)norm_eps: float = 1e-05 )

参数

  • in_channels (int,默认为 128) — 分块处理后的潜在通道数(ae_channels * patch_size ** 2)。
  • num_layers (int,默认为 34) — Transformer 块的数量。
  • attention_head_dim (int,默认为 256) — 每个注意力头的维度;总隐藏层大小为 attention_head_dim * num_attention_heads。
  • num_attention_heads (int,默认为 18) — 注意力头的数量。
  • intermediate_size (int,默认为 12288) — 每个块中 SwiGLU MLP 使用的前馈隐藏层大小。
  • adaln_dim (int,默认为 512) — 供 AdaLN 调制使用的条件向量的维度。
  • llm_features_dim (int,默认为 53248) — 输入模型的每个 token 文本特征的维度(通常是文本编码器多个层隐藏状态的拼接)。
  • rope_theta (int,默认为 5_000_000) — 多轴旋转位置嵌入所使用的基数。
  • mrope_section (tuple[int, int, int],默认为 (24, 20, 20)) — 分配给 MRoPE 的 (t, h, w) 各轴的频率数量。
  • norm_eps (float,默认为 1e-5) — Transformer 块中 RMSNorm 模块使用的 Epsilon 值。

Ideogram 4 流水线所使用的 flow-matching transformer 骨干网络。

Transformer 在一个同时包含文本条件 token(由多模态文本编码器生成)和分块图像潜变量的单个打包序列上运行。逐 token 的指示器用于区分这两种角色,而由 segment_ids 导出的块对角注意力掩码则限制打包批次中的每个样本仅关注其自身。

forward

< >

( hidden_states: Tensortimestep: Tensorencoder_hidden_states: Tensorposition_ids: Tensorsegment_ids: Tensorindicator: Tensorattention_kwargs: dict | None = Nonereturn_dict: bool = True )

参数

  • hidden_states(形状为 (batch_size, sequence_length, in_channels) 的 torch.Tensor)— 打包的、经过分块处理的含噪图像 token 序列。非图像位置会在内部被屏蔽。
  • timestep(形状为 (batch_size,) 或 (batch_size, sequence_length) 的 torch.Tensor)— [0, 1] 范围内的 Flow-matching 时间(0 表示纯噪声,1 表示干净数据)。
  • encoder_hidden_states(形状为 (batch_size, sequence_length, llm_features_dim) 的 torch.Tensor)— 逐 token 的文本条件特征。非文本位置会在内部被屏蔽。
  • position_ids(形状为 (batch_size, sequence_length, 3) 的 torch.Tensor)— 供多轴 RoPE 使用的 (t, h, w) 坐标。
  • segment_ids (torch.Tensor,形状为 (batch_size, sequence_length)) — 打包批次中每个 token 的样本 ID。共享相同 segment_id 的位置会相互关注。
  • indicator(形状为 (batch_size, sequence_length) 的 torch.Tensor)— 每个 token 的角色:LLM_TOKEN_INDICATOR(文本)或 OUTPUT_IMAGE_INDICATOR(图像)。
  • attention_kwargs (dict, 可选) — 传递给注意力处理器的 kwargs 字典。其中的 "scale" 项用于缩放 LoRA 权重(当 PEFT 后端处于激活状态时)。
  • return_dict (bool, 可选,默认为 True) — 是否返回 Transformer2DModelOutput 而不是普通元组。

预测打包序列中图像标记位置的流匹配速度。

Update on GitHub