Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EdgeDiffusion — Distilled Final (647M params)
|
| 2 |
+
|
| 3 |
+
A pruned and distilled Stable Diffusion 1.5 UNet, reduced from **858M → 647M parameters** (24.6% reduction) while preserving generation quality.
|
| 4 |
+
|
| 5 |
+
## Model Details
|
| 6 |
+
|
| 7 |
+
| | Value |
|
| 8 |
+
|---|---|
|
| 9 |
+
| Base model | Stable Diffusion v1.5 |
|
| 10 |
+
| Pruning method | Iterative structured Taylor pruning (4 rounds × ~7%) |
|
| 11 |
+
| Distillation teacher | DreamShaper v8 |
|
| 12 |
+
| Distillation steps | 40K constant LR (1e-5) + 10K cosine decay (1e-5 → 1e-6) |
|
| 13 |
+
| Loss | L_out (noise MSE) + 0.1 × L_feat (feature MSE) |
|
| 14 |
+
| Parameters | 647.2M (vs 858.5M baseline) |
|
| 15 |
+
| Dataset | 20K images (DiffusionDB 10K + COCO 2017 10K) |
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
import torch
|
| 21 |
+
from diffusers import StableDiffusionPipeline
|
| 22 |
+
from pruned_rebuild import create_unet_from_safetensors
|
| 23 |
+
|
| 24 |
+
# Rebuild the pruned UNet
|
| 25 |
+
unet = create_unet_from_safetensors(
|
| 26 |
+
"pruned_unet.safetensors",
|
| 27 |
+
"pruned_unet.config.json"
|
| 28 |
+
)
|
| 29 |
+
unet = unet.to(dtype=torch.float16, device="cuda")
|
| 30 |
+
|
| 31 |
+
# Load into SD1.5 pipeline
|
| 32 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 33 |
+
"runwayml/stable-diffusion-v1-5",
|
| 34 |
+
unet=unet,
|
| 35 |
+
torch_dtype=torch.float16,
|
| 36 |
+
safety_checker=None,
|
| 37 |
+
requires_safety_checker=False,
|
| 38 |
+
).to("cuda")
|
| 39 |
+
|
| 40 |
+
image = pipe("a beautiful landscape, 4k", num_inference_steps=30).images[0]
|
| 41 |
+
image.save("output.png")
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## Files
|
| 45 |
+
|
| 46 |
+
- `pruned_unet.safetensors` — Pruned + distilled UNet weights
|
| 47 |
+
- `pruned_unet.config.json` — UNet architecture config (channel dimensions)
|
| 48 |
+
- `pruned_rebuild.py` — Script to rebuild the pruned UNet from safetensors
|
| 49 |
+
|
| 50 |
+
## Pipeline
|
| 51 |
+
|
| 52 |
+
1. **Iterative Structured Pruning**: 4 rounds of Taylor importance-based channel pruning (~7% per round)
|
| 53 |
+
2. **Sensitivity-Guided**: Latent Divergence (LD) sensitivity analysis to protect critical blocks
|
| 54 |
+
3. **Knowledge Distillation**: BK-SDM style distillation with DreamShaper v8 teacher
|
| 55 |
+
4. **Fine-grained Recovery**: Final 10K steps with cosine LR decay for quality refinement
|