Repository navigation
Studio diffusion: do not let functools.wraps copy the prompt-cache transparent-wrapper marker - #17348
Merged
Merged
Conversation
…ansparent-wrapper marker
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The prompt cache reuses text embeddings across a denoiser-only LoRA change when it can prove
encode_promptnever runs the denoiser. Instance wrappers that only forward to the same-named class method (the Qwen-Image-2.1 no-K/V wrapper) are skipped in that proof through a marker attribute. The marker was a plainTrue, andfunctools.wrapscopies a function's__dict__onto the outer wrapper, so any later decorator around the marked wrapper inherited "transparent" without opting in. A decorator that reads the denoiser then got stale embeddings after a LoRA strength change.Root cause
Introduced in #17192:
_transparent_wrappertrustedgetattr(fn, TRANSPARENT_WRAPPER_ATTR, False)on every link of the__wrapped__chain.Fix
mark_transparent_wrapper(fn)stores a reference tofnitself;is_transparent_wrapper(fn)accepts only when the stored value is that same function. A copy made byfunctools.wrapsnames the inner function, so the outer wrapper is not trusted and keeps the full adapter key.Flip test
studio/backend/tests/test_diffusion_prompt_cache.py:test_a_wraps_copy_of_the_transparent_marker_keeps_the_full_key: installs the no-K/V wrapper, adds afunctools.wrapswrapper that scales by a denoiser weight, then changes LoRA strength and weight. Fails on main (scoped key accepted, one encode, stale value), passes with the fix (two encodes, fresh value).test_final_state_wrapper_over_the_no_kv_wrapper_keeps_the_scoped_key: the stock no-K/V + final-hidden-state chain still passes the static check (passes on both; guards the explicit re-marking).Tests run
tests/test_diffusion_prompt_cache.py tests/test_diffusion_qwenimage21_te_no_kv.pywith-o addopts= -m "not server and not native_mxc": 55 passed, 3 skipped, 1 failed. The failure istest_the_static_check_on_real_pipelines, which fails identically on origin/main because of a local diffusers / huggingface_hub version mismatch (cannot import name 'get_cached_repo_tree').functools.wrapswrapper, strength 0.25 then 0.75): main returns[1.25, 1.25]with 1 encode; the fix returns[1.25, 1.75]with 2 encodes, matching the pre-Studio diffusion: keep Qwen-Image-2.1 scoped LoRA prompt reuse after the no-K/V wrapper, and key callable helpers fully #17192 parent.Not proven
test_the_static_check_on_real_pipelinescould not run here because of the local diffusers / huggingface_hub mismatch.