tomesd
Token Merging for Stable Diffusion
What it is and what it does
ToMe for SD is a pure-Python patch that accelerates Stable Diffusion by identifying and merging redundant tokens during the diffusion process. It works by reducing the number of tokens the transformer must process, cutting both computation time and memory usage without requiring any model retraining. The patch applies directly to existing Stable Diffusion implementations and downstream UIs that use them.
The trade-off is intentional and controlled: merging tokens is lossy, so generated images will differ slightly from the unpatched baseline. The paper reports that at a 50% merge ratio, generation is 1.35x faster and uses 1.57x less memory with minimal quality loss. More aggressive merging (60%) achieves 2x speedup and 5.7x memory reduction, though quality degradation increases. You control this trade-off via the `ratio` parameter when calling `apply_patch()`.
Use it for:
- Generate images faster on consumer GPUs by trading minor quality loss for 1.5–2x speedup and reduced VRAM pressure.
- Reduce memory footprint when running Stable Diffusion on hardware with limited VRAM, enabling larger batch sizes or higher resolutions.
- Combine with other efficiency techniques to stack speedups without reimplementing transformer modules.
- Patch existing Stable Diffusion workflows with a single function call and no model changes.
- Experiment with token merging ratios to find the sweet spot between speed and quality for your specific use case.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Speeds up Stable Diffusion image generation by merging redundant tokens in the transformer, reducing computation and memory without requiring model retraining.
Yes, if you run Stable Diffusion and want faster inference with controllable quality trade-offs. Installation is trivial, the patch is non-invasive (reversible via `remove_patch`), and it works out-of-the-box on standard Stable Diffusion setups. The main caveat is dormant maintenance—no active development since mid-2023—so compatibility with very recent model releases is unverified. For established workflows, it's a low-risk, high-value optimization.
Install
tomesd on PyPI
pip
pip install tomesduv
uv add tomesdpoetry
poetry add tomesdInstalling tomesd
Before you install
Low install friction; pure Python with torch as the only runtime dependency. Dormant maintenance since May 2023 with last commit in November 2023—no active development, but the implementation is stable and self-contained.
License in practice
MIT license permits commercial and private use with minimal restrictions, making it safe to integrate into any Stable Diffusion workflow.
Quickstart
pip install tomesd
import tomesd
import torch
tomesd.apply_patch(model, ratio=0.5)
Requires pytorch >= 1.12.1 and an existing Stable Diffusion environment (Diffusers, SDv1, SDv2, or Latent Diffusion).
Verify before relying
- Whether the package works with Stable Diffusion v3 or newer models released after the last update.
- Compatibility with recent versions of downstream Stable Diffusion implementations and UIs.
- Performance impact on consumer GPUs with less VRAM than the tested 4090.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — torch |
| Maintenance | dormant — 1,188 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 223,975/month — #9,237 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tomesd-0.1.3-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
cache-ditCache-DiT accelerates inference for Diffusion…
unclear · top 15,000 on PyPI
diffusersDiffusers provides pretrained diffusion models…
permissive · top 5,000 on PyPI
compelCompel lets you re-weight different parts of…
permissive · top 15,000 on PyPI
k-diffusionk-diffusion is a PyTorch library implementing…
permissive · top 15,000 on PyPI
pytorch-fidComputes Fréchet Inception Distance (FID), a…
permissive · top 15,000 on PyPI
f5-ttsF5-TTS generates natural-sounding speech from…
permissive · top 15,000 on PyPI
adam-atan2-pytorchProvides an Adam optimizer variant using atan2…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
lycoris-loraImplements parameter-efficient fine-tuning…
permissive · top 15,000 on PyPI