--- id: tomesd version: "0.1.3" license: MIT license_treatment: permissive maintenance: dormant --- # tomesd — Token Merging for Stable Diffusion License: permissive · Maintenance: dormant · Downloads: 224.0K/mo ## 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 above — 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 pip install tomesd uv add tomesd 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 224.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags stable diffusion optimization, token merging pytorch, diffusion model speedup, transformer token reduction, stable diffusion memory efficient, fast image generation, diffusion inference acceleration, diffusion-models, inference-optimization, transformer-acceleration [View on SkillFed](https://skillfed.io/packages/tomesd) · [View on PyPI](https://pypi.org/project/tomesd/)