GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf: cache CPU position embeddings across DiT runners by leejet · Pull Request #2211 · leejet/stable-diffusion.cpp

Conversation

@leejet

@leejet leejet commented Oct 24, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner

Summary

  • 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.

Related Issue / Discussion

N/A

Additional Information

N/A

Checklist

  • I have read and confirmed this PR follows the contribution guidelines.

Summary by CodeRabbit

  • Performance

    • 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@leejet
perf: cache CPU position embeddings across DiT runners
52c34bb
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

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.
Image runner integrations
src/model/diffusion/boogu.hpp, src/model/diffusion/ernie_image.hpp, src/model/diffusion/flux.hpp, src/model/diffusion/krea2.hpp, src/model/diffusion/lens.hpp, src/model/diffusion/mage_flow.hpp, src/model/diffusion/ming_image.hpp, src/model/diffusion/pixart.hpp, src/model/diffusion/qwen_image.hpp, src/model/diffusion/z_image.hpp, src/model/diffusion/z_image_l2p.hpp
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.
Specialized embedding integrations
src/model/diffusion/anima.hpp, src/model/diffusion/fibo2.hpp, src/model/diffusion/flux3.hpp, src/model/diffusion/ideogram4.hpp, src/model/diffusion/iris.hpp, src/model/diffusion/llada_image.hpp, src/model/diffusion/minit2i.hpp, src/model/diffusion/moss_image.hpp, src/model/diffusion/pid.hpp, src/model/diffusion/qwen_image_2_1.hpp
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.

Priority: Not assessed

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

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.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@leejet
leejet merged commit ea209db into master Oct 24, 2026
10 of 11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@leejet
leejet deleted the perf/dit-pe-cache branch October 25, 2026 09:03
@coderabbitai coderabbitai Bot mentioned this pull request Oct 25, 2026
feat: support Fibo2 text-image conditioning #2216
Draft
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@leejet
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.