| # 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 |
| ``` |
|
|