Spaces:
Paused
Paused
Download toolkit/util/vae.py from StaticExposure/ai-toolkit: direct link, hf CLI and curl.
- Browser
- Download file 520 Bytes
-
https://huggingface.co/spaces/StaticExposure/ai-toolkit/resolve/main/toolkit/util/vae.py
- Command line
-
hf download hf://spaces/StaticExposure/ai-toolkit/toolkit/util/vae.py
-
curl -L -o vae.py https://huggingface.co/spaces/StaticExposure/ai-toolkit/resolve/main/toolkit/util/vae.py
520 Bytes
| from diffusers import AutoencoderKL | |
| def load_vae(vae_path, dtype): | |
| try: | |
| vae = AutoencoderKL.from_pretrained( | |
| vae_path, | |
| torch_dtype=dtype, | |
| ) | |
| except Exception as e: | |
| try: | |
| vae = AutoencoderKL.from_pretrained( | |
| vae_path, | |
| subfolder="vae", | |
| torch_dtype=dtype, | |
| ) | |
| except Exception as e: | |
| raise ValueError(f"Failed to load VAE from {vae_path}: {e}") | |
| vae.to(dtype) | |
| return vae | |