Skip to content

Use negative crop coordinates when building SDXL negative time ids - #14676

Open
Devam0311 wants to merge 1 commit into
huggingface:mainfrom
Devam0311:sdxl-negative-crops-coords
Open

Use negative crop coordinates when building SDXL negative time ids#14676
Devam0311 wants to merge 1 commit into
huggingface:mainfrom
Devam0311:sdxl-negative-crops-coords

Conversation

@Devam0311

@Devam0311 Devam0311 commented Sep 1, 2026

Copy link
Copy Markdown

Issue link: this addresses Issue 2 of #13610.
I have deliberately not used a Fixes keyword: #13610 tracks 7 separate findings, so a closing keyword would close it as soon as this one merges while the others are still open. Happy for the no-issue-needed label to be applied, or I can add a closing keyword if you would rather the review issue be closed and reopened.

What does this PR do?

Fixes Issue 2 of #13610 (stable_diffusion_xl model/pipeline review).

_get_add_time_ids accepts negative_crops_coords_top_left, and the aesthetic-score branch uses it — but the other branch does not:

if self.config.requires_aesthetics_score:
    add_neg_time_ids = list(negative_original_size + negative_crops_coords_top_left + (negative_aesthetic_score,))
else:
    add_neg_time_ids = list(negative_original_size + crops_coords_top_left + negative_target_size)
    #                                                ^^^^^^^^^^^^^^^^^^^^^ positive coordinates

So anyone requesting different positive and negative crop conditioning silently gets the positive crop coordinates on both branches, and negative micro-conditioning is wrong.

Reproduced on main with the script from the issue:

negative time ids: [[32.0, 32.0, 1.0, 2.0, 32.0, 32.0]]   # 1, 2 are the POSITIVE crops
after fix:         [[32.0, 32.0, 9.0, 10.0, 32.0, 32.0]]  # 9, 10 as requested

Solution

Use negative_crops_coords_top_left, matching the aesthetic-score branch directly above it and the separate negative _get_add_time_ids call the text-to-image pipeline already makes.

The issue names three files. Five more carry this method through # Copied from, and utils/check_copies.py requires them to match, so all eight are updated together:

named in the issue pipeline_stable_diffusion_xl_img2img.py, pipeline_stable_diffusion_xl_inpaint.py, modular_pipelines/stable_diffusion_xl/before_denoise.py
# Copied from the above pipeline_controlnet_sd_xl_img2img.py, pipeline_controlnet_union_sd_xl_img2img.py, pipeline_pag_controlnet_sd_xl_img2img.py, pipeline_pag_sd_xl_img2img.py, pipeline_pag_sd_xl_inpaint.py

Testing

test_get_add_time_ids_uses_negative_crops_coords_top_left asserts the negative time ids carry the negative crop coordinates.

It drives the method through a lightweight stand-in rather than the dummy pipeline, as the issue's own reproduction does. The reason is concrete: this branch emits six time ids instead of five, and the dummy UNet's add_embedding.linear_1 is sized for the five-value aesthetic-score layout, so the real dummy pipeline raises on the embedding-dimension check before reaching the logic under test.

Verified it catches the bug: with the fix reverted it fails.

pytest tests/pipelines/stable_diffusion_xl/{img2img,inpaint} -k "not ip_adapter"
  -> 74 passed, 43 skipped
ruff check / ruff format --check   -> clean
git diff --check                   -> clean

Two sets of pre-existing failures in my environment, both reproducing identically on a clean checkout of main and unrelated to this change: the TestStableDiffusionXL*PipelineIPAdapter classes (a ModuleNotFoundError from an optional dependency I don't have installed), and one before_denoise.py _get_add_time_ids copy mismatch against StableDiffusionXLPipeline — a different method from the one changed here.

Before submitting

Self-review notes

Reviewed against .ai/references/review-rules.md and pipelines.md. No blocking issues.

For the reviewer:

  1. This changes generated output for anyone who passes negative_crops_coords_top_left on a non-aesthetic-score model. That is the point — the old output ignored the argument — but it will move pinned outputs for those callers.
  2. The blast radius is eight files, not the three the issue lists. That is forced by # Copied from; touching only the three would break check_copies. Happy to split the copies into a follow-up if you'd rather review them separately.
  3. Scope kept to Issue 2. The other six issues in stable_diffusion_xl model/pipeline review #13610 are untouched.

Who can review?

@yiyixuxu @asomoza @hlky

`_get_add_time_ids` accepts `negative_crops_coords_top_left` and the
aesthetic-score branch uses it, but the other branch built the negative time
ids from `crops_coords_top_left`. Callers asking for different positive and
negative crop conditioning silently got the positive coordinates in both,
so negative micro-conditioning was wrong.

Fixed in the SDXL img2img and inpaint pipelines, the modular SDXL
img2img conditioning step, and the five pipelines that carry this method
via `# Copied from`.

Add a regression test asserting the negative time ids carry the negative
crop coordinates.

Ref huggingface#13610 (Issue 2)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XBYeq5vB4DNZDEaqUsroKR
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Hi @Devam0311, 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. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

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

Once the PR links an issue (or gets the no-issue-needed label), you can ignore this message — it stays here as a comment, but it no longer applies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant