tomesd is a Python library that implements Token Merging (ToMe) for Stable Diffusion models. It accelerates inference by merging redundant tokens, reducing the computational load on the transformer blocks without requiring model retraining. The library is pure Python and PyTorch-based, currently at version 0.1.3, with an active development and release cadence focused on performance improvements and compatibility.
pip install tomesdVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to apply `tomesd` to a `diffusers` Stable Diffusion pipeline. It loads a pre-trained model, applies the `tomesd` patch with a specified merging ratio, and then generates an image. The `ratio` parameter is key to balancing speedup and image quality.
Upgrade to `tomesd` v0.1.3 or later. If using older versions, ensure a separate RNG or consistent seed setting for each batch if reproducibility is critical.
Upgrade to `tomesd` v0.1.2 or later, which automatically disables `use_rand` for odd batch sizes to prevent this issue. Alternatively, ensure an even batch size.
Experiment with different `ratio` values (e.g., 0.3 to 0.6) to find a balance between speedup and acceptable image quality for your specific use case.
Benchmark performance with your specific setup and image sizes. `tomesd` generally provides more substantial speedups for larger image resolutions (e.g., 1024x1024 and above) and typically works well in conjunction with other optimizations.
Ensure `tomesd` is installed correctly in the active Python environment: `pip install tomesd`. If using a virtual environment (e.g., `venv`, `conda`), activate it before installing.
Try reinstalling `tomesd`: `pip uninstall tomesd` followed by `pip install tomesd`. If installing from source, ensure `python setup.py build develop` was run successfully. Double-check the import statement is `import tomesd` before calling `tomesd.apply_patch()`.
Upgrade `tomesd` to the latest version, as compatibility with more resolutions was added in v0.1.1. If the problem persists, try adjusting image dimensions to multiples of 16 or using common Stable Diffusion resolutions like 512x512 or 768x768 for better compatibility. [cite: v0.1.1, 10]
Verify that `tomesd` is actually being called (e.g., add print statements). Ensure you are testing with larger image resolutions (e.g., 1024x1024) where `tomesd` typically provides more significant gains. Consider disabling other transformer optimizations temporarily to isolate the effect of `tomesd` and then re-evaluate.