Initial release of OBS-Diff-SD3.5-Large
Browse files- .gitattributes +3 -0
- .mdl +0 -0
- .msc +0 -0
- .mv +1 -0
- README.md +52 -0
- configuration.json +1 -0
- sd3-5-1.png +3 -0
- sd3-5-2.png +3 -0
- sd3-5-3.png +3 -0
- sparsity_15/pruned_model.pth +3 -0
- sparsity_20/pruned_model.pth +3 -0
- sparsity_25/pruned_model.pth +3 -0
- sparsity_30/pruned_model.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 |
+
sd3-5-1.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
sd3-5-2.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
sd3-5-3.png filter=lfs diff=lfs merge=lfs -text
|
.mdl
ADDED
|
Binary file (53 Bytes). View file
|
|
|
.msc
ADDED
|
Binary file (702 Bytes). View file
|
|
|
.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1764209133
|
README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OBS-Diff Structured Pruning for Stable Diffusion 3.5-Large
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+

|
| 5 |
+

|
| 6 |
+

|
| 7 |
+
|
| 8 |
+
### Pruned Transformer Variants
|
| 9 |
+
| Sparsity (%) | 0 (Dense) | 15 | 20 | 25 | 30 |
|
| 10 |
+
| :--- | :---: | :---: | :---: | :---: | :---: |
|
| 11 |
+
| **Params (B)** | 8.06 | 7.28 | 7.02 | 6.76 | 6.54 |
|
| 12 |
+
|
| 13 |
+
### How to use the pruned model
|
| 14 |
+
|
| 15 |
+
1. Download the base model (SD3.5-Large) from [huggingface](https://huggingface.co/stabilityai/stable-diffusion-3.5-large) or ModelScope.
|
| 16 |
+
|
| 17 |
+
2. Download the pruned weights (.pth files) and use `torch.load` to replace the original Transformer in the pipeline.
|
| 18 |
+
|
| 19 |
+
3. Run inference using the code below.
|
| 20 |
+
|
| 21 |
+
``` python
|
| 22 |
+
import os
|
| 23 |
+
import torch
|
| 24 |
+
from diffusers import StableDiffusion3Pipeline
|
| 25 |
+
from PIL import Image
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# 1. Load the base SD3.5-Large model
|
| 29 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.float16)
|
| 30 |
+
|
| 31 |
+
# 2. Swap the original Transformer with the pruned Transformer checkpoint
|
| 32 |
+
# Note: Ensure the path points to your downloaded .pth file
|
| 33 |
+
pruned_transformer_path = "/path/to/sparsity_30/pruned_model.pth"
|
| 34 |
+
pipe.transformer = torch.load(pruned_transformer_path, weights_only=False)
|
| 35 |
+
pipe = pipe.to("cuda")
|
| 36 |
+
|
| 37 |
+
total_params = sum(p.numel() for p in pipe.transformer.parameters())
|
| 38 |
+
print(f"Total Transformer parameters: {total_params / 1e6:.2f} M")
|
| 39 |
+
|
| 40 |
+
image = pipe(
|
| 41 |
+
prompt="photo of a delicious hamburger with fries and a coke on a wooden table, professional food photography, bokeh",
|
| 42 |
+
negative_prompt=None,
|
| 43 |
+
height=1024,
|
| 44 |
+
width=1024,
|
| 45 |
+
num_inference_steps=30,
|
| 46 |
+
guidance_scale=7.0,
|
| 47 |
+
generator=torch.Generator("cuda").manual_seed(42)
|
| 48 |
+
).images[0]
|
| 49 |
+
|
| 50 |
+
image.save("output_pruned.png")
|
| 51 |
+
|
| 52 |
+
```
|
configuration.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"framework":"Pytorch","task":"text-to-image-synthesis"}
|
sd3-5-1.png
ADDED
|
Git LFS Details
|
sd3-5-2.png
ADDED
|
Git LFS Details
|
sd3-5-3.png
ADDED
|
Git LFS Details
|
sparsity_15/pruned_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a9f04450cac3dc284da522cd8698954d0ad3ad32e9cacdf61ed6d8f4f187104d
|
| 3 |
+
size 14733084213
|
sparsity_20/pruned_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:987eeee4543263a86224d03beb1bfddae5e0c5cf8d6556b5060a850c3a8dcc94
|
| 3 |
+
size 14212550541
|
sparsity_25/pruned_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:036bf191b9b689bbb2d666ea84aa76f7fbec5c4dce3775143753c47ca331c162
|
| 3 |
+
size 13692717381
|
sparsity_30/pruned_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:898b9c868ba0f8d64b018fac8e5e027afa5d3e1085a9f6d4b0c5261a8376b4af
|
| 3 |
+
size 13262563645
|