Skip to content

Commit

Permalink
Add attentionless VAE support (huggingface#8769)
Browse files Browse the repository at this point in the history
* Add attentionless VAE support

* make style and quality, fix-copies

---------

Co-authored-by: Sayak Paul <[email protected]>
  • Loading branch information
Gothos and sayakpaul authored Jul 23, 2024
1 parent af40004 commit 77c5de2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/diffusers/models/autoencoders/autoencoder_kl.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class AutoencoderKL(ModelMixin, ConfigMixin, FromOriginalModelMixin):
If enabled it will force the VAE to run in float32 for high image resolution pipelines, such as SD-XL. VAE
can be fine-tuned / trained to a lower range without loosing too much precision in which case
`force_upcast` can be set to `False` - see: https://huggingface.co/madebyollin/sdxl-vae-fp16-fix
mid_block_add_attention (`bool`, *optional*, default to `True`):
If enabled, the mid_block of the Encoder and Decoder will have attention blocks. If set to false, the
mid_block will only have resnet blocks
"""

_supports_gradient_checkpointing = True
Expand All @@ -87,6 +90,7 @@ def __init__(
force_upcast: float = True,
use_quant_conv: bool = True,
use_post_quant_conv: bool = True,
mid_block_add_attention: bool = True,
):
super().__init__()

Expand All @@ -100,6 +104,7 @@ def __init__(
act_fn=act_fn,
norm_num_groups=norm_num_groups,
double_z=True,
mid_block_add_attention=mid_block_add_attention,
)

# pass init params to Decoder
Expand All @@ -111,6 +116,7 @@ def __init__(
layers_per_block=layers_per_block,
norm_num_groups=norm_num_groups,
act_fn=act_fn,
mid_block_add_attention=mid_block_add_attention,
)

self.quant_conv = nn.Conv2d(2 * latent_channels, 2 * latent_channels, 1) if use_quant_conv else None
Expand Down

0 comments on commit 77c5de2

Please sign in to comment.