Metadata-Version: 2.1
Name: sdhelper
Version: 1.0.0
Summary: A helper package for working with stable diffusion models.
Author-email: Jonas Loos <sdhelper@jloos.de>
License: MIT License
        
        Copyright (c) 2025 Jonas Loos
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/JonasLoos/sdhelper
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: diffusers
Requires-Dist: transformers
Requires-Dist: torch
Requires-Dist: datasets
Requires-Dist: accelerate
Requires-Dist: protobuf
Requires-Dist: sentencepiece

# Stable Diffusion Helper

A helper package for working with stable diffusion models. Allows for easy extraction of U-Net (and transformer) representations.


## Installation

```bash
pip install sdhelper
```


## Usage

```python
from sdhelper import SD

# load model
sd = SD('SD-1.5')

# generate image
img = sd('a beautiful landscape').result_image

# extract representations from the `up[1]` block at time step 50
r = sd.img2repr(img, extract_positions=['up_blocks[1]'], step=50)

# compute similarity between all pairs of tokens in `r`
similarities = r.cosine_similarity(r)
```

Available models:

* SD1.1
* SD1.2
* SD1.3
* SD1.4
* SD1.5
* SD2.0
* SD2.1
* SD-Turbo
* SDXL
* SDXL-Turbo
* SDXL-Lightning-1step
* SDXL-Lightning-2step
* SDXL-Lightning-4step
* SDXL-Lightning-8step
* SD3
* FLUX-dev
* FLUX-schnell

Especially for FLUX models, it might make sense to quantize the weights and enable CPU offloading:

```python
flux = SD('FLUX-schnell')
flux.quantize(['transformer', 'text_encoder_2'], model_cpu_offload=True)
```
