Skip to content

Commit

Permalink
Add backwards compatibility w/ older versions of diffusers (<0.25.0) (d…
Browse files Browse the repository at this point in the history
…eepspeedai#5083)

This PR adds backwards compatibility for older versions of `diffusers`
(`<0.25.0`) by updating the `vae` container import logic to account for
changes between the various versions.
  • Loading branch information
lekurile authored and amaurya committed Feb 17, 2024
1 parent 2628424 commit bf091f9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions deepspeed/module_inject/containers/vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ def __init__(self):
super().__init__()
try:
import diffusers
if hasattr(diffusers.models.autoencoders.vae, "AutoencoderKL"):
self._orig_layer_class = diffusers.models.autoencoders.vae.AutoencoderKL
else:
# Diffusers >= 0.12.0 changes location of AutoencoderKL
if hasattr(diffusers.models, "autoencoders"):
# Diffusers >= 0.25.0
# Changes location to 'autoencoders' directory
self._orig_layer_class = diffusers.models.autoencoders.autoencoder_kl.AutoencoderKL
elif hasattr(diffusers.models.vae, "AutoencoderKL"):
# Diffusers < 0.12.0
self._orig_layer_class = diffusers.models.vae.AutoencoderKL
else:
# Diffusers >= 0.12.0 & < 0.25.0
# Changes location of AutoencoderKL
self._orig_layer_class = diffusers.models.autoencoder_kl.AutoencoderKL
except ImportError:
self._orig_layer_class = None

Expand Down

0 comments on commit bf091f9

Please sign in to comment.