Diffusers documentation
ChromaTransformer2DModel
ChromaTransformer2DModel
来自 Chroma 的改进版 flux Transformer 模型
ChromaTransformer2DModel
class diffusers.ChromaTransformer2DModel
< source >( patch_size: int = 1in_channels: int = 64out_channels: int | None = Nonenum_layers: int = 19num_single_layers: int = 38attention_head_dim: int = 128num_attention_heads: int = 24joint_attention_dim: int = 4096axes_dims_rope: tuple = (16, 56, 56)approximator_num_channels: int = 64approximator_hidden_dim: int = 5120approximator_layers: int = 5 )
参数
- patch_size (
int,默认为1) — 用于将输入数据划分为小块的块大小。 - in_channels (
int,默认为64) — 输入数据的通道数。 - out_channels (
int,可选,默认为None) — 输出通道数。如果未指定,则默认为in_channels。 - num_layers (
int,默认为19) — 要使用的双流 DiT 块层数。 - num_single_layers (
int,默认为38) — 要使用的单流 DiT 块层数。 - attention_head_dim (
int,默认为128) — 每个注意力头使用的维度数。 - num_attention_heads (
int,默认为24) — 要使用的注意力头数量。 - joint_attention_dim (
int,默认为4096) — 用于联合注意力的维度数(encoder_hidden_states的嵌入/通道维度)。 - axes_dims_rope (
tuple[int],默认为(16, 56, 56)) — 用于旋转位置嵌入的维度。
在 Flux 中引入的 Transformer 模型,针对 Chroma 进行了修改。
参考:https://huggingface.co/lodestones/Chroma1-HD
forward
< source >( hidden_states: Tensorencoder_hidden_states: Tensor = Nonetimestep: LongTensor = Noneimg_ids: Tensor = Nonetxt_ids: Tensor = Noneattention_mask: Tensor = Nonejoint_attention_kwargs: dict[str, typing.Any] | None = Nonecontrolnet_block_samples = Nonecontrolnet_single_block_samples = Nonereturn_dict: bool = Truecontrolnet_blocks_repeat: bool = False )
参数
- 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) — 用于计算旋转位置嵌入的文本位置 ID。 - attention_mask (
torch.Tensor, 可选) — 在注意力机制中应用于encoder_hidden_states的掩码。 - controlnet_block_samples(
listoftorch.Tensor,可选)— 一个张量列表,如果指定,将被添加到 transformer 块的残差中。 - controlnet_single_block_samples (
listoftorch.Tensor,可选) — 一个张量列表,如果指定,将被添加到单个 Transformer 块的残差中。 - controlnet_blocks_repeat (
bool,可选,默认为False) — 是否在所有 transformer 块中重复使用 controlnet 块样本。 - joint_attention_kwargs (
dict, 可选) — 一个 kwargs 字典,如果指定,将作为参数传递给 diffusers.models.attention_processor 中self.processor下定义的AttentionProcessor。 - return_dict (
bool,可选,默认为True) — 是否返回~models.transformer_2d.Transformer2DModelOutput而不是普通的元组。
FluxTransformer2DModel 的前向方法。