Skip to main content

TinySD

TinySD is a small Python wrapper around 🤗 diffusers for Stable Diffusion 1.x and SDXL. It lets you generate images with a few lines of code while keeping the conveniences of the AUTOMATIC1111 (A1111) WebUI:

  • A1111 prompt syntax: (word:1.3), [word], ((word)), BREAK, and <lora:...> tags are converted automatically to Compel syntax. Long prompts are not truncated.
  • A1111 sampler names: "Euler a", "DPM++ 2M Karras", "DPM++ 2M SDE Karras", "UniPC", and others.
  • Flexible model loading: Hugging Face Hub IDs, local diffusers folders, or single .safetensors / .ckpt checkpoints (e.g. from Civitai).
  • Add-ons: custom VAE, LoRA weights, textual inversion embeddings, custom text encoder/tokenizer.
  • CLIP skip for SD 1.x models, and reproducible seeds.

Installation

Requires Python ≥ 3.9. A CUDA GPU is strongly recommended; TinySD falls back to CPU (float32) otherwise.

git clone <this-repo> TinySD
cd TinySD
pip install -e .

If you need a specific CUDA build of PyTorch, install it first (see pytorch.org).

Quick start

from tinysd import SDImageGenerator

generator = SDImageGenerator(
    base_model_id="stabilityai/stable-diffusion-xl-base-1.0",
    lora_weight_path=None,
    vae_weight_path=None,
    scheduler_name="DPM++ 2M Karras",
)

result = generator.generate_images(
    positive_prompt="a (fluffy cat:1.3) sitting on a windowsill, golden hour, ((highly detailed))",
    negative_prompt="blurry, [low quality], watermark",
    height=1024,
    width=1024,
    steps=30,
    guidance_scale=7.0,
    seed=42,
    nbimages=2,
)

for i, image in enumerate(result.images):
    image.save(f"cat_{i}.png")

print(result.seed, result.steps, result.base_model_id)

generate_images returns a StableDiffusionOutput dataclass that holds the generated PIL images and the settings used to produce them (model, LoRA/VAE file names, prompts, size, steps, guidance scale, seed). When seed is given, image i uses seed + i, so results are reproducible.

Usage examples

Stable Diffusion 1.5 with LoRA, VAE and CLIP skip

from pathlib import Path
from tinysd import SDImageGenerator

generator = SDImageGenerator(
    base_model_id="stable-diffusion-v1-5/stable-diffusion-v1-5",  # "runwayml/..." is aliased automatically
    lora_weight_path=Path("loras/my_style.safetensors"),          # file, folder, or Hub repo ID
    vae_weight_path="vae/vae-ft-mse-840000-ema-pruned.safetensors",
    scheduler_name="Euler a",
)

result = generator.generate_images(
    positive_prompt="portrait of a knight, (intricate armor:1.2), BREAK dramatic lighting, castle background",
    negative_prompt="(worst quality:1.4), lowres, bad anatomy",
    seed=1234,
    clip_skip=2,
)
result.images[0].save("knight.png")

Local single-file checkpoint and textual inversion

from tinysd import SDImageGenerator

generator = SDImageGenerator(
    base_model_id="checkpoints/myModel_v10.safetensors",  # "xl" in the name selects the SDXL pipeline
    lora_weight_path=None,
    vae_weight_path=None,
    text_inversion_embedding_path="embeddings/ng_deepnegative_v1_75t.pt",
)

result = generator.generate_images(
    positive_prompt="a cozy cabin in a snowy forest",
    negative_prompt="ng_deepnegative_v1_75t, blurry",  # embedding is registered under this token
)

Lower-level API

If you want to manage the pipeline yourself, for example to change the scheduler between runs or generate a batch in one call:

from tinysd import get_stable_diffusion_pipeline, generate_image, set_scheduler

pipe = get_stable_diffusion_pipeline(
    "stabilityai/stable-diffusion-xl-base-1.0",
    lora_weights_path=None,
    vae_input_path=None,
    cuda=True,
)

set_scheduler(pipe, "UniPC")

images = generate_image(
    positive_prompt=["a red apple", "a green pear"],   # one image per prompt
    negative_prompt=["blurry", "blurry"],
    stable_diffusion_pipeline=pipe,
    height=1024,
    width=1024,
    steps=25,
    seed=7,                                            # prompt i uses seed + i
)

Prompt conversion only

from tinysd import convert_a1111_to_compel

convert_a1111_to_compel("a (cat:1.3) on a [mat]")
# 'a (cat)1.3 on a (mat)-'

convert_a1111_to_compel("a ((red)) car <lora:style:0.8>")
# 'a ((red)+)+ car'

convert_a1111_to_compel("a cat BREAK a dog")
# '("a cat", "a dog").and()'

Pass convert_a1111_syntax=False to generate_image if your prompts are already written in Compel syntax.

Available schedulers

from tinysd import SCHEDULERS
print(list(SCHEDULERS))
# ['Euler a', 'Euler', 'DPM++ 2M', 'DPM++ 2M Karras', 'DPM++ 2M SDE', 'DPM++ 2M SDE Karras',
#  'DPM++ SDE', 'DPM++ SDE Karras', 'Heun', 'KDPM2', 'KDPM2 a', 'DDIM', 'UniPC']

Package layout

src/tinysd/
├── __init__.py     # public API
├── prompt.py       # A1111 -> Compel prompt conversion
├── schedulers.py   # SCHEDULERS registry and set_scheduler()
├── pipeline.py     # get_stable_diffusion_pipeline(): model, VAE, LoRA, embeddings
├── generation.py   # generate_image(): Compel encoding + inference
├── generator.py    # SDImageGenerator high-level class
├── schemas.py      # StableDiffusionOutput dataclass
├── utils.py        # internal helpers
└── sd.py           # backward-compatible re-exports

Running tests

The unit tests mock all model loading, so they run quickly and need neither a GPU nor network access:

PYTHONPATH=src python -m unittest discover -s tests -t .
# or, with pytest installed:
pytest

Notes

  • The safety checker is disabled for SD 1.x pipelines.
  • The SD vs. SDXL choice is based on whether "xl" appears in the model ID or path.
  • clip_skip applies only to SD 1.x. SDXL always uses the penultimate hidden states.

Metadata

Release files for tinysd 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinysd 0.0.1
File Size Uploaded Provenance Actions
tinysd-0.0.1.tar.gz 18.8 kB Without provenance Details for tinysd-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tinysd 0.0.1
File Interpreter ABI Platform Actions
tinysd-0.0.1-py3-none-any.whl Python 3 none any Details for tinysd-0.0.1-py3-none-any.whl

Total release size: 33.6 kB

Release files / tinysd-0.0.1.tar.gz

Download URL tinysd-0.0.1.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
38d9f5e476f2bf711798ac254b678c30571af82bff9a53f62ee705571d8c7600
BLAKE2b-256 checksum
How to use checksums
a56656eed820403466d7063e136f73d8f6603dd7cc57c01075b05383543ec083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tinysd-0.0.1-py3-none-any.whl

Download URL tinysd-0.0.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce339d3d78134d82a6982b2b762a3c5e7afc0246cda53cedd9834bcfe2db3c43
BLAKE2b-256 checksum
How to use checksums
d1d7dd65bd49ee19f138190de77739255cef37c89f8adba18f0102f2b45c7ed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tinysd 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page