Views
No views yet




| Sparsity (%) | 0 (Dense) | 10 | 15 | 20 | 25 | 30 |
|---|---|---|---|---|---|---|
| Params (B) | 2.57 | 2.35 | 2.24 | 2.13 | 2.02 | 1.91 |
torch.load to replace the original UNet in the pipeline.1import os
2import torch
3from diffusers import DiffusionPipeline
4from PIL import Image
5
6
7# 1. Load the base SDXL model
8pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
9
10# 2. Swap the original UNet with the pruned UNet checkpoint
11# Note: Ensure the path points to your downloaded .pth file
12pruned_unet_path = "/path/to/sparsity_30/unet_pruned.pth"
13pipe.unet = torch.load(pruned_unet_path, weights_only=False)
14pipe = pipe.to("cuda")
15
16total_params = sum(p.numel() for p in pipe.unet.parameters())
17print(f"Total UNet parameters: {total_params / 1e6:.2f} M")
18
19image = pipe(
20 prompt="A ship sailing through a sea of clouds, golden hour, impasto oil painting, brush strokes visible, dreamlike atmosphere.",
21 negative_prompt=None,
22 height=1024,
23 width=1024,
24 num_inference_steps=30,
25 guidance_scale=7.0,
26 generator=torch.Generator("cuda").manual_seed(42)
27).images[0]
28
29image.save("output_pruned.png")
301@article{zhu2025obs,
2 title={OBS-Diff: Accurate Pruning For Diffusion Models in One-Shot},
3 author={Zhu, Junhan and Wang, Hesong and Su, Mingluo and Wang, Zefang and Wang, Huan},
4 journal={arXiv preprint arXiv:2510.06751},
5 year={2025}
6}