Skip to content

anyflow: swap unconditional aliases instead of popping them - #3085

Merged
bghira merged 2 commits into
mainfrom
bugfix/anyflow-uncond-batch-aliases
Aug 15, 2026
Merged

anyflow: swap unconditional aliases instead of popping them#3085
bghira merged 2 commits into
mainfrom
bugfix/anyflow-uncond-batch-aliases

Conversation

@bghira

@bghira bghira commented Aug 15, 2026

Copy link
Copy Markdown
Owner

What

Fixes AnyFlow's unconditional batch construction for families that key text conditioning on prompt_embeds, and completes the negative-conditioning swap for pooled projections.

_unconditional_batch popped the model-specific aliases (prompt_embeds, attention_mask, attention_masks) so swapped unconditional embeds would take effect for families that merely prefer those keys (Ideogram). But Flux requires prompt_embeds in model_predict, so any Flux run with real_score_guidance_scale > 0 crashed with KeyError: 'prompt_embeds' inside _apply_real_score_guidance.

Changes:

  • _unconditional_batch swaps aliases instead of popping: prompt_embeds gets the negative embeds; alias masks get the cached negative mask (or are dropped when none is cached, preserving prior stale-mask behaviour). Ideogram's proxy path reads the same negative tensor it previously reached via fallback.
  • Collation caches the unconditional pooled projection as negative_add_text_embeds, prepare_batch moves it to the accelerator, and the unconditional batch swaps it into add_text_embeds and added_cond_kwargs.text_embeds — the unconditional pass no longer reuses the positive pooled embed for Flux/SDXL-style conditioning.

Testing

.venv/bin/python -m unittest tests.helpers.distillation.test_anyflow_distiller -f — 57 tests pass, including alias-swap coverage, negative-mask swap, and the pooled-embed swap (verifying the original batch's added_cond_kwargs is not mutated).

bghira added 2 commits August 15, 2026 08:58
Flux keys its text conditioning on prompt_embeds, so popping the alias in
_unconditional_batch crashed any run using real_score_guidance_scale > 0
with KeyError at model_predict. Replacing the alias with the negative
embeds (and alias masks with the negative mask when cached) serves both
families: Ideogram's proxy path reads the same negative tensor it used to
fall back to, and Flux keeps the key it requires.

Note: the unconditional pass still reuses the positive pooled projection
for Flux since collation does not cache a negative pooled embed.
…pass

Collation now carries the unconditional pooled projection as
negative_add_text_embeds, prepare_batch moves it to the accelerator, and
_unconditional_batch swaps it into add_text_embeds and
added_cond_kwargs.text_embeds so Flux and SDXL-style conditioning no
longer reuse the positive pooled embed during unconditional scoring.
@bghira
bghira merged commit 33b0326 into main Aug 15, 2026
2 checks passed
@bghira
bghira deleted the bugfix/anyflow-uncond-batch-aliases branch August 15, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant