skillfed

tomesd

Token Merging for Stable Diffusion

tomesd v0.1.3 224.0K downloads/30d#9,237 on PyPI1,405
Permissive license MIT DORMANT released

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 tomesd

uv

uv add tomesd

poetry

poetry add tomesd

Installing 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

stable diffusion optimizationtoken merging pytorchdiffusion model speeduptransformer token reductionstable diffusion memory efficientfast image generationdiffusion inference acceleration
diffusion-modelsinference-optimizationtransformer-acceleration

More Artificial Intelligence packages

Further reading