Initial release
Browse files- .gitattributes +3 -0
- .mdl +0 -0
- .msc +0 -0
- .mv +1 -0
- README.md +51 -0
- configuration.json +1 -0
- sdxl1.png +3 -0
- sdxl2.png +3 -0
- sdxl3.png +3 -0
- sparsity_10/unet_pruned.pth +3 -0
- sparsity_15/unet_pruned.pth +3 -0
- sparsity_20/unet_pruned.pth +3 -0
- sparsity_25/unet_pruned.pth +3 -0
- sparsity_30/unet_pruned.pth +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
sdxl1.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
sdxl2.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
sdxl3.png filter=lfs diff=lfs merge=lfs -text
|
.mdl
ADDED
|
Binary file (44 Bytes). View file
|
|
|
.msc
ADDED
|
Binary file (759 Bytes). View file
|
|
|
.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1764209071
|
README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OBS-Diff Structured Pruning for Stable Diffusion-xl-base-1.0
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+

|
| 5 |
+

|
| 6 |
+

|
| 7 |
+
### Pruned UNet Variants
|
| 8 |
+
| Sparsity (%) | 0 (Dense) | 10 | 15 | 20 | 25 | 30 |
|
| 9 |
+
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
| 10 |
+
| **Params (B)** | 2.57 | 2.35 | 2.24 | 2.13 | 2.02 | 1.91 |
|
| 11 |
+
|
| 12 |
+
### How to use the pruned model
|
| 13 |
+
|
| 14 |
+
1. Download the base model (SDXL) from [huggingface](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) or ModelScope.
|
| 15 |
+
|
| 16 |
+
2. Download the pruned weights (.pth files) and use `torch.load` to replace the original UNet in the pipeline.
|
| 17 |
+
|
| 18 |
+
3. Run inference using the code below.
|
| 19 |
+
|
| 20 |
+
``` python
|
| 21 |
+
import os
|
| 22 |
+
import torch
|
| 23 |
+
from diffusers import DiffusionPipeline
|
| 24 |
+
from PIL import Image
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# 1. Load the base SDXL model
|
| 28 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
| 29 |
+
|
| 30 |
+
# 2. Swap the original UNet with the pruned UNet checkpoint
|
| 31 |
+
# Note: Ensure the path points to your downloaded .pth file
|
| 32 |
+
pruned_unet_path = "/path/to/sparsity_30/unet_pruned.pth"
|
| 33 |
+
pipe.unet = torch.load(pruned_unet_path, weights_only=False)
|
| 34 |
+
pipe = pipe.to("cuda")
|
| 35 |
+
|
| 36 |
+
total_params = sum(p.numel() for p in pipe.unet.parameters())
|
| 37 |
+
print(f"Total UNet parameters: {total_params / 1e6:.2f} M")
|
| 38 |
+
|
| 39 |
+
image = pipe(
|
| 40 |
+
prompt="A ship sailing through a sea of clouds, golden hour, impasto oil painting, brush strokes visible, dreamlike atmosphere.",
|
| 41 |
+
negative_prompt=None,
|
| 42 |
+
height=1024,
|
| 43 |
+
width=1024,
|
| 44 |
+
num_inference_steps=30,
|
| 45 |
+
guidance_scale=7.0,
|
| 46 |
+
generator=torch.Generator("cuda").manual_seed(42)
|
| 47 |
+
).images[0]
|
| 48 |
+
|
| 49 |
+
image.save("output_pruned.png")
|
| 50 |
+
|
| 51 |
+
```
|
configuration.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"framework":"Pytorch","task":"text-to-image-synthesis"}
|
sdxl1.png
ADDED
|
Git LFS Details
|
sdxl2.png
ADDED
|
Git LFS Details
|
sdxl3.png
ADDED
|
Git LFS Details
|
sparsity_10/unet_pruned.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:835b4bd42874ebdf9bfe41d69ac0a35f30a7ee062a0cb4f1341723883f3e795a
|
| 3 |
+
size 4699003163
|
sparsity_15/unet_pruned.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab994c033322639a085f30de037a2a10478fd1bdf3743a8ab608ce5e4ac7c223
|
| 3 |
+
size 4475458027
|
sparsity_20/unet_pruned.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06c42b24f50227134ac7c2970aef3a0d9502dcdc95fd2f2176f975c22cf019ba
|
| 3 |
+
size 4262071263
|
sparsity_25/unet_pruned.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a061c65239480e465abe45122bff07b0515de529e7d957bee0f65af0f1a9b4e6
|
| 3 |
+
size 4048685023
|
sparsity_30/unet_pruned.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7e15fc895c2c251dc2ef9ad2691c7f2428c5164b144290131b13c44beb58f851
|
| 3 |
+
size 3825140703
|