Views
No views yet




| Sparsity (%) | 0 (Dense) | 15 | 20 | 25 | 30 |
|---|---|---|---|---|---|
| Params (B) | 8.06 | 7.28 | 7.02 | 6.76 | 6.54 |
torch.load to replace the original Transformer in the pipeline.1import os
2import torch
3from diffusers import StableDiffusion3Pipeline
4from PIL import Image
5
6
7# 1. Load the base SD3.5-Large model
8pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.float16)
9
10# 2. Swap the original Transformer with the pruned Transformer checkpoint
11# Note: Ensure the path points to your downloaded .pth file
12pruned_transformer_path = "/path/to/sparsity_30/pruned_model.pth"
13pipe.transformer = torch.load(pruned_transformer_path, weights_only=False)
14pipe = pipe.to("cuda")
15
16total_params = sum(p.numel() for p in pipe.transformer.parameters())
17print(f"Total Transformer parameters: {total_params / 1e6:.2f} M")
18
19image = pipe(
20 prompt="photo of a delicious hamburger with fries and a coke on a wooden table, professional food photography, bokeh",
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}