Fix text CFG context for interleaved image conditions - #6
Open
arshiaizd wants to merge 1 commit into
Open
Conversation
arshiaizd
force-pushed
the
fix/preserve-text-cfg-context
branch
from
August 26, 2026 12:51
cdbcc5a to
34f861d
Compare
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
Problem
For an input order such as
[caption, depth],_feed_conditionsfirst created the correct text-free cache before appending the caption. When depth was subsequently appended, it assignedcfg_text_context = deepcopy(gen_context). At that pointgen_contextalready contained both caption and depth, so the text-conditioned and text-unconditional branches became identical. As a result, changingcfg_text_scalehad no effect for this ordering.Simply updating the two caches independently would introduce another inconsistency because VAE conditioning samples a stochastic posterior. The helper in this change replays the RNG state so both branches receive the same sampled image latent while preserving the external random stream.
Validation
Validated locally for both caption-then-image and image-then-caption ordering, identical stochastic samples across CFG branches, single RNG consumption, and Python syntax.