| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The official CFG cutoff callbacks kept only the last row of the `[negative, conditional]` batch when they disabled CFG, so with `num_images_per_prompt > 1` or several prompts the SD, SDXL and SDXL ControlNet pipelines crashed on the next step and SD3 silently conditioned every sample on the last prompt. Keep the conditional half of each tensor instead, skip the slicing when CFG is off, and add a test per pipeline. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
Fixes #14907
What does this PR do?
The official CFG cutoff callbacks (SDCFGCutoffCallback, SDXLCFGCutoffCallback, SDXLControlnetCFGCutoffCallback, SD3CFGCutoffCallback) kept only the last row ([-1:]) of the [negative, conditional] batch when they disabled CFG. With num_images_per_prompt > 1 or several prompts the next step ran the UNet with batch_size latents and one embedding row and crashed (SD, SDXL, SDXL ControlNet), or, for SD3, silently conditioned every sample on the last prompt.
The callbacks now keep the conditional half of each tensor (x[-batch_size:] with batch_size = prompt_embeds.shape[0] // 2) and skip the slicing when CFG is off, since there is no negative batch to drop then. In guess mode the ControlNet image is not duplicated for CFG and [-batch_size:] keeps it whole.
Tests: test_cfg_cutoff_callback in the SD, SDXL, SDXL ControlNet and SD3 pipeline test files runs two prompts with a cutoff at step 1 and, through a second callback composed with MultiPipelineCallbacks, checks that prompt_embeds and latents keep the same batch size after the cutoff (plus the CFG-off and guess-mode cases). All four tests fail on main with assert 1 == 2.
Coordination: #14907 (issue filed with a reproduction and the proposed fix; no maintainer response yet, so this PR is opened early and I am happy to adjust or close it if you would prefer a different approach).
Test commands and results (CPU, macOS, torch 2.14.0):
Self-review notes (final round, verdict: READY):
Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.
Before submitting
Who can review?
@asomoza @yiyixuxu
🤖 Generated with Claude Code