File size: 1,382 Bytes
aef6fd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# EdgeDiffusion - Distilled

A pruned and distilled Stable Diffusion 1.5 UNet (647.2M params, ~25% smaller than original 858.5M).

## Pipeline

1. **Iterative Pruning**: 4 rounds of ~7% Taylor-importance pruning (858.5M → 647.2M)
2. **Knowledge Distillation**: 15K steps with Realistic Vision v5.1 as teacher (feature + noise MSE loss)

## Files

| File | Description |
|------|-------------|
| `pruned_unet.safetensors` | Pruned + distilled UNet weights |
| `pruned_unet.config.json` | Model config (contains `model_config` for rebuilding) |
| `pruned_rebuild.py` | Script to rebuild the pruned UNet architecture |

## Usage

```python
# 1. Download all 3 files to the same directory, then:
from pruned_rebuild import create_unet_from_safetensors
from diffusers import StableDiffusionPipeline
import torch

# 2. Rebuild the pruned UNet
unet = create_unet_from_safetensors(
    "pruned_unet.safetensors",
    "pruned_unet.config.json"
)

# 3. Load into a standard SD 1.5 pipeline
pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    unet=unet,
    torch_dtype=torch.float16,
    safety_checker=None,
)
pipe = pipe.to("cuda")

# 4. Generate
image = pipe("a beautiful sunset over mountains", num_inference_steps=30).images[0]
image.save("output.png")
```

## Requirements

```
pip install diffusers transformers safetensors torch accelerate
```