ermu2001 commited on
Commit
f116630
·
1 Parent(s): 1738707

Upload MODELS/sdxl-vae-fp16-fix/README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. MODELS/sdxl-vae-fp16-fix/README.md +58 -0
MODELS/sdxl-vae-fp16-fix/README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-diffusers
6
+ inference: false
7
+ ---
8
+ # SDXL-VAE-FP16-Fix
9
+
10
+ SDXL-VAE-FP16-Fix is the [SDXL VAE](https://huggingface.co/stabilityai/sdxl-vae)*, but modified to run in fp16 precision without generating NaNs.
11
+
12
+ | VAE | Decoding in `float32` / `bfloat16` precision | Decoding in `float16` precision |
13
+ | --------------------- | -------------------------------------------- | ------------------------------- |
14
+ | SDXL-VAE | ✅ ![](./images/orig-fp32.png) | ⚠️ ![](./images/orig-fp16.png) |
15
+ | SDXL-VAE-FP16-Fix | ✅ ![](./images/fix-fp32.png) | ✅ ![](./images/fix-fp16.png) |
16
+
17
+ ## 🧨 Diffusers Usage
18
+
19
+ Just load this checkpoint via `AutoencoderKL`:
20
+
21
+ ```py
22
+ import torch
23
+ from diffusers import DiffusionPipeline, AutoencoderKL
24
+
25
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
26
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
27
+ pipe.to("cuda")
28
+
29
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
30
+ refiner.to("cuda")
31
+
32
+ n_steps = 40
33
+ high_noise_frac = 0.7
34
+
35
+ prompt = "A majestic lion jumping from a big stone at night"
36
+
37
+ image = pipe(prompt=prompt, num_inference_steps=n_steps, denoising_end=high_noise_frac, output_type="latent").images
38
+ image = refiner(prompt=prompt, num_inference_steps=n_steps, denoising_start=high_noise_frac, image=image).images[0]
39
+ image
40
+ ```
41
+
42
+ ![](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lion_refined.png)
43
+
44
+ ## Details
45
+
46
+ SDXL-VAE generates NaNs in fp16 because the internal activation values are too big:
47
+ ![](./images/activation-magnitudes.jpg)
48
+
49
+ SDXL-VAE-FP16-Fix was created by finetuning the SDXL-VAE to:
50
+ 1. keep the final output the same, but
51
+ 2. make the internal activation values smaller, by
52
+ 3. scaling down weights and biases within the network
53
+
54
+ There are slight discrepancies between the output of SDXL-VAE-FP16-Fix and SDXL-VAE, but the decoded images should be [close enough for most purposes](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/discussions/7#64c5c0f8e2e5c94bd04eaa80).
55
+
56
+ ---
57
+
58
+ \* `sdxl-vae-fp16-fix` is specifically based on [SDXL-VAE (0.9)](https://huggingface.co/stabilityai/sdxl-vae/discussions/6#64acea3f7ac35b7de0554490), but it works with SDXL 1.0 too