You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: cache CPU position embeddings across DiT runners - #2211
Add a reusable CPU PE cache that retains the latest tensor per named input and regenerates it when its key changes.
Integrate the cache into 25 DiT implementations, including Flux, Qwen Image, Z-Image, Wan, LTX, and MiniT2I. Each graph creates inputs through the existing make_input() path.
Positional embeddings are now reused across repeated runs when the relevant inputs and settings match, reducing redundant generation work across many image and video models.
Embeddings are regenerated when those inputs or settings change, preserving results for different configurations.
Documentation
Added guidance on how positional-embedding caching behaves and the conditions required for cache reuse.
The change adds a shared positional-encoding tensor cache and integrates it into diffusion model runners. Cache keys encode relevant values and tensor shapes. The runners reuse matching embeddings or generate and store them on a cache miss.
Changes: Positional-encoding cache
Layer / File(s)
Summary
Cache key and lookup src/core/pe_cache.h, src/core/pe_cache.cpp, docs/pe_cache.md
Adds PECacheKey value and shape encoding, plus PECache::get_or_create lookup and insertion behavior. The documentation describes cache keys, tensor requirements, and lifetime constraints.
These runners use keyed cache lookups for positional embeddings instead of storing embedding vectors and setting up backend tensors on each graph build or computation.
These runners cache one or more positional embeddings using keys based on their inputs and generation settings. MiniT2I also removes its runner-local backend cache and cleanup code.
Video and audio integrations src/model/diffusion/hunyuan.hpp, src/model/diffusion/lingbot_video.hpp, src/model/diffusion/ltxv.hpp, src/model/diffusion/wan.hpp
These runners use PECache for video, audio, cross-attention, or connector positional embeddings. LTXAV caches six embedding types.
sequenceDiagram
participant Runner as Model runner
participant PECache
participant Builder as Embedding builder
participant Graph as Model graph
Runner->>PECache: get_or_create with key and builder
PECache->>PECache: Compare name and encoded key
PECache->>Builder: Build tensor on cache miss
Builder-->>PECache: Return positional-encoding tensor
PECache-->>Runner: Return cached or newly built tensor
Runner->>Graph: Pass tensor as graph input
Loading
Possibly related PRs
leejet/stable-diffusion.cpp#2201: Adds MOSS-Image positional-embedding reuse with a model-specific cache; this PR uses the shared PECache for the same model behavior.
Merge Risk: Minimal · up to 52c34
The reviewed cache changes are mergeable after normal checks; no actionable issue remains.
Finishing Touches
📝 Generate docstrings
Commit to this branch
Create a new PR
🧪 Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
🔧 Cppcheck (2.22.0)
src/pipeline/image.cpp
Cppcheck timed out; analysis of this file is incomplete
src/pipeline/diffusion_engine.cpp
Cppcheck timed out; analysis of this file is incomplete
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make_input()path.Related Issue / Discussion
N/A
Additional Information
N/A
Checklist
Summary by CodeRabbit
Performance
Documentation