Skip to content

Fix batched prompt/image pairing in the Kandinsky combined pipelines (item 1 of #15465) - #15488

Open
amarjithkumar2007-wq wants to merge 2 commits into
huggingface:mainfrom
amarjithkumar2007-wq:fix-kandinsky-combined-prompt-pairing
Open

amarjithkumar2007-wq wants to merge 2 commits into
huggingface:mainfrom
amarjithkumar2007-wq:fix-kandinsky-combined-prompt-pairing

Conversation

@amarjithkumar2007-wq

Copy link
Copy Markdown

What

Fixes item 1 of #15465, as agreed with @nyxbyb on the issue.

KandinskyPriorPipeline expands image_embeds per prompt with repeat_interleave, so a batch of prompts ["cat", "dog"] with num_images_per_prompt=2 produces embeddings ordered [cat, cat, dog, dog]. The three combined pipelines (KandinskyCombinedPipeline, KandinskyImg2ImgCombinedPipeline, KandinskyInpaintCombinedPipeline) instead expanded the prompt list with list multiplication, giving [cat, dog, cat, dog]. With more than one prompt and num_images_per_prompt > 1, half of the images were therefore generated with another prompt's text. The image and mask_image lists in the Img2Img/Inpaint variants were expanded with the same mismatched pattern and are fixed the same way.

The expansion now repeats each entry per prompt, matching the prior's ordering. Nothing changes for a single prompt or num_images_per_prompt=1 (the expansion is a no-op there).

Tests

  • New CPU-only tests in tests/pipelines/kandinsky/test_kandinsky_combined.py: a stub prior returns embeddings that record which prompt produced them (expanded with repeat_interleave, as the real prior does), and a stub decoder records what the combined pipeline hands it. The tests assert that every prompt, image and mask stays paired with its own embeddings in all three combined pipelines. All three fail on current main and pass with this change.
  • pytest tests/pipelines/kandinsky/test_kandinsky_combined.py (whole file, CPU): 45 passed, 60 skipped, 3 xfailed with this change. On unmodified main the same file gives 42 passed, 60 skipped, 3 xfailed, so the only difference is the 3 new tests. The skips and xfails are pre-existing and were not investigated further.
  • ruff format --check, ruff check and utils/check_copies.py pass on the changed files.

AI contribution disclosure (per this repo's guidelines)

This contribution was prepared with AI assistance (Instinct). I reviewed the final diff and the test results myself before submitting.

Self-review notes:

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Hi @amarjithkumar2007-wq, thanks for the PR! It does not appear to link an issue it fixes.

  • If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked.
  • If you are the author of the model/pipeline this PR relates to, or part of the team we work with on it, tick the Are you the author (or part of the team we work with) of the model/pipeline this PR relates to? box in the PR description (if you removed the template, paste that line back, checked). This reminder then no longer applies.
  • Otherwise there is nothing you need to do: a maintainer will look at the PR and add the no-issue-needed label to silence this reminder if it should stay open without an issue.

See the contribution guide for more details.

Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice.

Once the PR links an existing issue, the author box is ticked, or the no-issue-needed label is added, you can ignore this message — it stays here as a comment, but it no longer applies.

This branch has not been deployed

No deployments
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