Text-to-Image
Diffusers
Safetensors
sdxl
stable-diffusion-xl
diffusion
obs-diff
pruning
unstructured-pruning
sparse-model
Instructions to use ApacheOne/OBS-Diff-SDXL-creaprompthyper1.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use ApacheOne/OBS-Diff-SDXL-creaprompthyper1.2 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("ApacheOne/OBS-Diff-SDXL-creaprompthyper1.2", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
File size: 10,896 Bytes
39676cc | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | ---
library_name: diffusers
pipeline_tag: text-to-image
tags:
- sdxl
- stable-diffusion-xl
- diffusion
- text-to-image
- obs-diff
- pruning
- unstructured-pruning
- sparse-model
- safetensors
- diffusers
---
<div align="center">
# OBS-Diff SDXL β CreaPrompt Hyper 1.2
### Full-shape sparse SDXL UNets pruned with OBS-Diff at 20%, 30%, 40%, and 50%
**Base checkpoint:** CreaPrompt Hyper SDXL 1.2
**Inference:** 4 steps Β· CFG 0.0 Β· DPM++ SDE normal Β· 1024Γ1024
**Format:** Diffusers `UNet2DConditionModel` components
</div>
> [!IMPORTANT]
> These are **complete loadable SDXL UNet components**, not complete text-to-image pipelines.
> You still need the original checkpoint's two text encoders, tokenizers, VAE, and scheduler.
> [!NOTE]
> OBS-Diff applied **unstructured pruning**. The selected weights are stored as exact zeros, but the tensor shapes and parameter count remain unchanged. The folders are therefore approximately the same extracted size and do not automatically run faster with ordinary dense CUDA kernels.
---
## Overview
This repository contains four independently pruned versions of the CreaPrompt Hyper SDXL 1.2 UNet:
| Variant | Targeted-weight sparsity | Whole-UNet zeros | Mean ImageReward | Delta vs. dense | Wins vs. dense | Mean generation time |
|---|---:|---:|---:|---:|---:|---:|
| **Dense reference** | 0.0000% | 0.0001% | **+0.771080** | +0.000000 | β | 1.9656 s |
| **OBS 20%** | 20.0004% | 17.0132% | **+0.758518** | -0.012563 | 2/4 | 1.9399 s |
| **OBS 30%** | 30.0004% | 25.5196% | **+0.731054** | -0.040026 | 2/4 | 1.9611 s |
| **OBS 40%** | 40.0004% | 34.0260% | **+0.687856** | -0.083225 | 3/4 | 1.9567 s |
| **OBS 50%** | 50.0004% | 42.5324% | **+0.380332** | -0.390748 | 1/4 | 1.9403 s |
<div align="center">
### Preliminary interpretation
| Variant | Practical reading |
|---|---|
| **20%** | Best overall fidelity/quality tradeoff in this small evaluation |
| **30%** | Moderate quality decline with stronger output changes |
| **40%** | More aggressive; won 3/4 individual comparisons but had a lower overall mean |
| **50%** | Experimental; substantial quality instability and one severe failure |
</div>
The evaluation contains only four prompts, so these results are a **screening benchmark**, not a universal quality guarantee.
---
## Repository structure
```text
obs_diff_sdxl_results/
βββ images/
β βββ dense/
β βββ sparsity_20/
β βββ sparsity_30/
β βββ sparsity_40/
β βββ sparsity_50/
βββ unets/
β βββ sparsity_20/
β βββ sparsity_30/
β βββ sparsity_40/
β βββ sparsity_50/
βββ obs_sdxl_compare.html
βββ obs_sdxl_compare.json
βββ obs_sdxl_compare_scored.html
βββ obs_sdxl_compare_scored.json
βββ obs_diff_sdxl_prune.log
βββ obs_diff_sdxl_imagereward.log
```
Each `unets/sparsity_*` directory is a complete Diffusers UNet component produced with `save_pretrained()`.
---
# Visual comparisons
## Adult bear standing in a field
| Dense | OBS 20% | OBS 30% | OBS 40% | OBS 50% |
|---|---|---|---|---|
| IR **+1.138650** | IR **+1.165112** | IR **+1.243169** | IR **+1.197060** | IR **+1.149614** |
|  |  |  |  |  |
---
## Odd-looking toilet against a wall
| Dense | OBS 20% | OBS 30% | OBS 40% | OBS 50% |
|---|---|---|---|---|
| IR **+0.776347** | IR **+0.756794** | IR **+0.515587** | IR **+0.180844** | IR **-0.667451** |
|  |  |  |  |  |
---
## Bathroom with a tub and counter
| Dense | OBS 20% | OBS 30% | OBS 40% | OBS 50% |
|---|---|---|---|---|
| IR **+0.458368** | IR **+0.508567** | IR **+0.511803** | IR **+0.560043** | IR **+0.362720** |
|  |  |  |  |  |
---
## Large plane flying in the sky
| Dense | OBS 20% | OBS 30% | OBS 40% | OBS 50% |
|---|---|---|---|---|
| IR **+0.710957** | IR **+0.603597** | IR **+0.653658** | IR **+0.813476** | IR **+0.676448** |
|  |  |  |  |  |
---
# Loading a pruned UNet
The saved folders can be loaded independently as `UNet2DConditionModel` components.
```python
import torch
from diffusers import UNet2DConditionModel
REPO_ID = "ApacheOne/OBS-Diff-SDXL-creaprompthyper1.2"
unet = UNet2DConditionModel.from_pretrained(
REPO_ID,
subfolder="obs_diff_sdxl_results/unets/sparsity_20",
torch_dtype=torch.float16,
)
unet.eval()
print(type(unet).__name__)
print(f"Parameters: {sum(p.numel() for p in unet.parameters()):,}")
```
Available subfolders:
```text
obs_diff_sdxl_results/unets/sparsity_20
obs_diff_sdxl_results/unets/sparsity_30
obs_diff_sdxl_results/unets/sparsity_40
obs_diff_sdxl_results/unets/sparsity_50
```
---
# Text-to-image usage
These repositories contain the UNet only. Load the original complete CreaPrompt Hyper SDXL 1.2 checkpoint for the remaining SDXL components, then replace its UNet.
```python
import torch
from diffusers import (
DPMSolverSinglestepScheduler,
StableDiffusionXLPipeline,
UNet2DConditionModel,
)
REPO_ID = "ApacheOne/OBS-Diff-SDXL-creaprompthyper1.2"
# Local copy of the original complete single-file checkpoint.
BASE_CHECKPOINT = (
"/content/models/hyper_sdxl_4step_471056.safetensors"
)
# Change to sparsity_20, sparsity_30, sparsity_40, or sparsity_50.
SPARSITY = "sparsity_20"
unet = UNet2DConditionModel.from_pretrained(
REPO_ID,
subfolder=f"obs_diff_sdxl_results/unets/{SPARSITY}",
torch_dtype=torch.float16,
)
pipe = StableDiffusionXLPipeline.from_single_file(
BASE_CHECKPOINT,
unet=unet,
torch_dtype=torch.float16,
use_safetensors=True,
)
pipe.scheduler = DPMSolverSinglestepScheduler.from_config(
pipe.scheduler.config,
algorithm_type="sde-dpmsolver++",
solver_order=2,
solver_type="midpoint",
lower_order_final=True,
use_karras_sigmas=False,
use_exponential_sigmas=False,
use_beta_sigmas=False,
final_sigmas_type="zero",
)
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()
pipe.to("cuda")
generator = torch.Generator("cuda").manual_seed(1234)
image = pipe(
prompt=(
"a cinematic photograph of a red fox standing in snow, "
"detailed fur, natural lighting"
),
width=1024,
height=1024,
num_inference_steps=4,
guidance_scale=0.0,
generator=generator,
).images[0]
image.save("obs_diff_sdxl_test.png")
```
---
# Technical details
## Pruning method
OBS-Diff uses second-order information to select and compensate pruned weights. This adaptation calibrated the SDXL UNet using its four-step denoising trajectory and independently exported four sparsity targets.
```text
Method: OBS-Diff / second-order unstructured pruning
Checkpoint format: Complete single-file SDXL checkpoint
UNet parameters: 2,567,463,684
Targeted parameters: 2,183,987,200
Calibration prompts: 16
Calibration size: 512Γ512
Comparison size: 1024Γ1024
Scheduler: DPM++ SDE normal
Inference steps: 4
Guidance scale: 0.0
OBS damping: 0.01
Column block: 128
Maximum tokens: 128
Evaluation seeds: 1234β1237
Quality metric: ImageReward
```
## What β20β50%β means
The percentage names refer to sparsity among the **targeted attention and feed-forward weights**, not the percentage of the complete UNet file physically deleted.
| Variant | Targeted zeros | Whole-UNet zeros |
|---|---:|---:|
| OBS 20% | 20.0004% | 17.0132% |
| OBS 30% | 30.0004% | 25.5196% |
| OBS 40% | 40.0004% | 34.0260% |
| OBS 50% | 50.0004% | 42.5324% |
## Why the files are not smaller
The pruning is unstructured:
```text
Original dense tensor shape β same tensor shape
Selected FP16 values β replaced by exact zero
Parameter count β unchanged
```
An FP16 zero still occupies two bytes in a normal dense SafeTensors tensor. Therefore:
- all four UNets have approximately the same extracted size;
- normal dense CUDA kernels still execute the same matrix dimensions;
- standard inference does not receive a proportional speedup;
- specialized sparse storage and sparse kernels would be needed to convert the zero pattern into storage or runtime gains.
---
# Benchmark notes
The comparison used only four prompts. Individual outputs can improve even when the aggregate mean declines:
- OBS 40% achieved the best ImageReward on the bathroom and plane examples.
- OBS 30% achieved the best ImageReward on the bear example.
- OBS 50% produced a major failure on the toilet example.
- OBS 20% stayed closest to the dense aggregate result.
Use the provided HTML and JSON reports for the full per-image metrics:
```text
obs_diff_sdxl_results/obs_sdxl_compare_scored.html
obs_diff_sdxl_results/obs_sdxl_compare_scored.json
```
---
# Limitations
- These are **UNet components**, not complete SDXL pipelines.
- The original text encoders, tokenizers, VAE, and scheduler are not included.
- The original CreaPrompt Hyper SDXL 1.2 checkpoint is required for matching T2I behavior.
- Sparsity is unstructured and does not physically shrink dense tensor dimensions.
- No retraining or recovery fine-tuning was performed.
- The benchmark is small and should not be treated as a general quality ranking.
- Results may change with prompt, seed, resolution, sampler, scheduler, and inference step count.
- The models were evaluated specifically at four steps and CFG 0.0.
---
# Credits
- **OBS-Diff:** pruning method and reference implementation
- **Diffusers:** SDXL pipeline and UNet serialization
- **ImageReward:** prompt-image quality evaluation
- **CreaPrompt Hyper SDXL 1.2:** source checkpoint used for this experiment
---
<div align="center">
### Recommended starting point: `sparsity_20`
It produced the smallest aggregate ImageReward decline in this initial comparison while retaining approximately **17.01% whole-UNet zeros**.
</div> |