Diffusers documentation

UVit2DModel

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

UVit2DModel

U-ViT 模型是一种基于视觉 Transformer(ViT)的 UNet。该模型融合了 ViT 的元素(将时间、条件以及含噪图像块等所有输入视为 token)和 UNet 的元素(在浅层与深层之间建立长跳跃连接)。跳跃连接对于预测像素级特征至关重要。在最终输出之前,还会应用一个额外的 3x3 卷积块以提升图像质量。

该论文的摘要如下:

目前,在高分辨率图像的像素空间中应用扩散模型颇具挑战。现有的方法通常专注于在低维空间(潜在扩散)中进行扩散,或者采用被称为级联的多级超分辨率生成策略。这些方法的缺点在于它们为扩散框架引入了额外的复杂性。本文旨在改进高分辨率图像的降噪扩散,同时尽可能保持模型的简洁性。本文围绕以下研究问题展开:如何对标准降噪扩散模型进行训练,使其在高分辨率图像上仍能取得与上述替代方法相当的性能?本文的四个主要发现是:1)噪声调度应针对高分辨率图像进行调整;2)只需扩展架构的特定部分即可;3)应在架构的特定位置添加 dropout;4)下采样是避免高分辨率特征图的有效策略。结合这些简单而有效的技术,我们在 ImageNet 上实现了扩散模型中图像生成的最先进性能,且未使用采样修正器。

UVit2DModel

class diffusers.UVit2DModel

< >

( hidden_size: int = 1024use_bias: bool = Falsehidden_dropout: float = 0.0cond_embed_dim: int = 768micro_cond_encode_dim: int = 256micro_cond_embed_dim: int = 1280encoder_hidden_size: int = 768vocab_size: int = 8256codebook_size: int = 8192in_channels: int = 768block_out_channels: int = 768num_res_blocks: int = 3downsample: bool = Falseupsample: bool = Falseblock_num_heads: int = 12num_hidden_layers: int = 22num_attention_heads: int = 16attention_dropout: float = 0.0intermediate_size: int = 2816layer_norm_eps: float = 1e-06ln_elementwise_affine: bool = Truesample_size: int = 64 )

forward

< >

( input_idsencoder_hidden_statespooled_text_embmicro_condscross_attention_kwargs = None ) → torch.Tensor

参数

  • input_ids (torch.LongTensor) — 被掩码的潜在图像令牌的 token id,形状为 (batch_size, height, width)。
  • encoder_hidden_states (torch.Tensor) — 要使用的条件嵌入(从输入条件(例如提示词)计算得出的嵌入)。
  • pooled_text_emb (torch.Tensor) — 用于额外条件控制的池化文本嵌入。
  • micro_conds (torch.Tensor) — 微条件值,会被嵌入并与 pooled_text_emb 进行组合。
  • cross_attention_kwargs (dict,可选) — 一个 kwargs 字典,如果指定,将传递给 AttentionProcessor。

返回值

torch.Tensor

每个图像 token 在码本上的 logits,形状为 (batch_size, codebook_size, height, width)。

set_default_attn_processor

< >

( )

禁用自定义注意力处理器并设置默认的注意力实现。

UVit2DConvEmbed

class diffusers.models.unets.uvit_2d.UVit2DConvEmbed

< >

( in_channelsblock_out_channelsvocab_sizeelementwise_affineepsbias )

UVitBlock

class diffusers.models.unets.uvit_2d.UVitBlock

< >

( channelsnum_res_blocks: inthidden_sizehidden_dropoutln_elementwise_affinelayer_norm_epsuse_biasblock_num_headsattention_dropoutdownsample: boolupsample: bool )

ConvNextBlock

class diffusers.models.unets.uvit_2d.ConvNextBlock

< >

( channelslayer_norm_epsln_elementwise_affineuse_biashidden_dropouthidden_sizeres_ffn_factor = 4 )

ConvMlmLayer

class diffusers.models.unets.uvit_2d.ConvMlmLayer

< >

( block_out_channels: intin_channels: intuse_bias: boolln_elementwise_affine: boollayer_norm_eps: floatcodebook_size: int )

Update on GitHub