Downloads · 30 days
0
wangkanai/sdxl-vae
sdxl-vae is a text-to-image model from wangkanai. Use it when you need an image from a text prompt. It is set up for diffusers. The card lists the license as openrail++.
High-quality Variational Autoencoder (VAE) for Stable Diffusion XL (SDXL) models, featuring enhanced reconstruction quality and improved detail preservation.
Downloads · 30 days
0
Access
Public
Updated Oct 28, 2025
Repo size
335 MB
Likes
4
Public
Click a slice to open those files.
.safetensors335 MB · 100%
From the Hugging Face model README
High-quality Variational Autoencoder (VAE) for Stable Diffusion XL (SDXL) models, featuring enhanced reconstruction quality and improved detail preservation.
The SDXL VAE is an improved variational autoencoder component for Stable Diffusion XL that significantly enhances the quality of generated images. This VAE was specifically retrained by Stability AI with optimized training parameters to improve local, high-frequency details in generated images.
Key Improvements:
This VAE is compatible with all SDXL-based models and can be used as a drop-in replacement for the standard VAE to improve output quality.
E:\huggingface\sdxl-vae\
├── vae\
│ └── sdxl\
│ └── sdxl-vae.safetensors # 320 MB - SDXL VAE weights
├── .cache\ # Cache directory
└── README.md # This file
Total Repository Size: ~320 MB
| File | Size | Format | Description |
|---|---|---|---|
sdxl-vae.safetensors | 320 MB | SafeTensors | SDXL VAE model weights |
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
import torch
# Load the improved SDXL VAE
vae = AutoencoderKL.from_pretrained(
"E:/huggingface/sdxl-vae/vae/sdxl",
torch_dtype=torch.float16
)
# Load SDXL pipeline with custom VAE
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
vae=vae,
torch_dtype=torch.float16,
variant="fp16",
use_safetensors=True
)
pipe = pipe.to("cuda")
# Generate image with improved VAE
prompt = "A majestic mountain landscape at sunset, highly detailed"
image = pipe(
prompt=prompt,
num_inference_steps=50,
guidance_scale=7.5
).images[0]
image.save("output.png")
from diffusers import AutoencoderKL
# Load directly from Hugging Face
vae = AutoencoderKL.from_pretrained(
"stabilityai/sdxl-vae",
torch_dtype=torch.float16
)
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
import torch
# Load your existing SDXL pipeline
pipe = StableDiffusionXLPipeline.from_pretrained(
"your-sdxl-model-path",
torch_dtype=torch.float16
)
# Replace with improved VAE
improved_vae = AutoencoderKL.from_pretrained(
"E:/huggingface/sdxl-vae/vae/sdxl",
torch_dtype=torch.float16
)
pipe.vae = improved_vae
pipe = pipe.to("cuda")
# Generate with improved quality
image = pipe("detailed portrait photograph").images[0]
from diffusers import AutoencoderKL
from PIL import Image
import torch
from torchvision import transforms
# Load VAE
vae = AutoencoderKL.from_pretrained(
"E:/huggingface/sdxl-vae/vae/sdxl",
torch_dtype=torch.float16
).to("cuda")
# Load and preprocess image
image = Image.open("input.png").convert("RGB")
transform = transforms.Compose([
transforms.Resize((1024, 1024)),
transforms.ToTensor(),
transforms.Normalize([0.5], [0.5])
])
image_tensor = transform(image).unsqueeze(0).to("cuda", dtype=torch.float16)
# Encode to latent space
with torch.no_grad():
latents = vae.encode(image_tensor).latent_dist.sample()
latents = latents * vae.config.scaling_factor
# Decode back to image space
with torch.no_grad():
latents = latents / vae.config.scaling_factor
reconstructed = vae.decode(latents).sample
# Convert to PIL image
reconstructed = (reconstructed / 2 + 0.5).clamp(0, 1)
reconstructed = reconstructed.cpu().permute(0, 2, 3, 1).numpy()[0]
output_image = Image.fromarray((reconstructed * 255).astype("uint8"))
output_image.save("reconstructed.png")
# In ComfyUI, use the "Load VAE" node
# Point to: E:\huggingface\sdxl-vae\vae\sdxl\sdxl-vae.safetensors
# Connect to your SDXL model's VAE input
Compared to original SD VAE, SDXL VAE achieves:
Use FP16 for Speed
vae = AutoencoderKL.from_pretrained(
"E:/huggingface/sdxl-vae/vae/sdxl",
torch_dtype=torch.float16 # 2× faster, minimal quality loss
)
Enable Memory-Efficient Attention
pipe.enable_attention_slicing()
pipe.enable_vae_slicing() # Process images in slices
Batch Processing
# Process multiple images efficiently
with torch.no_grad():
latents = vae.encode(batch_images).latent_dist.sample()
Compile for Speed (PyTorch 2.0+)
vae = torch.compile(vae, mode="reduce-overhead")
enable_vae_slicing() for memory-constrained systemsMIT License
Copyright (c) 2023 Stability AI
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If you use this VAE in your research or projects, please cite:
@misc{sdxl-vae-2023,
title={SDXL: Improved Variational Autoencoder},
author={Stability AI},
year={2023},
howpublished={\url{https://huggingface.co/stabilityai/sdxl-vae}},
}
@article{rombach2022high,
title={High-resolution image synthesis with latent diffusion models},
author={Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj{\"o}rn},
journal={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={10684--10695},
year={2022}
}
For issues specific to this VAE:
Version: v1.0 Last Updated: October 2025 Model Version: SDXL VAE 1.0 Maintained By: Local Hugging Face Repository