Fix controlnet_pooled_projections tensor handling in SD3 ControlNet pipelines - #14673
Open
Devam0311 wants to merge 1 commit into
Open
Fix controlnet_pooled_projections tensor handling in SD3 ControlNet pipelines#14673Devam0311 wants to merge 1 commit into
Devam0311 wants to merge 1 commit into
Conversation
…ipelines Both SD3 ControlNet pipelines resolved the public `controlnet_pooled_projections` argument with `controlnet_pooled_projections or pooled_prompt_embeds`. `or` evaluates the truthiness of the left operand, so passing any real pooled projection raises `RuntimeError: Boolean value of Tensor with more than one value is ambiguous`, making the argument unusable. In the text-to-image pipeline, replace the `or` with an explicit `None` check. In the inpainting pipeline the `else` branch is only reachable when the value is not `None`, so it could only ever re-assign the value to itself or raise; drop it. Add a regression test that passes a tensor with a ControlNet configured with `force_zeros_for_pooled_projection=False`, which is the path that raised. Ref huggingface#13611 (Issue 3), huggingface#9686 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XBYeq5vB4DNZDEaqUsroKR
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. 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 |
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.
What does this PR do?
Fixes Issue 3 of #13611, which is also reported independently as #9686.
Both SD3 ControlNet pipelines resolve the public
controlnet_pooled_projectionsargument with:orevaluates the truthiness of the left operand, so passing any real pooled projection raises:The documented argument is therefore unusable on that path.
Solution
pipeline_stable_diffusion_3_controlnet.py— replace theorwith an explicitNonecheck:pipeline_stable_diffusion_3_controlnet_inpainting.py— here theelsebranch is guarded byif controlnet_pooled_projections is None, so it is only reachable when the value is notNone. It could therefore only ever re-assign the value to itself or raise. Removed.Testing
test_controlnet_pooled_projections_accepts_tensorbuilds a ControlNet withforce_zeros_for_pooled_projection=False— the configuration that reaches the broken branch — and passes a tensor.Verified it catches the bug: with the fix reverted it fails with the
RuntimeErrorabove; with it applied it passes.Before submitting
self-reviewskill on the diff?Self-review notes
Reviewed against
.ai/references/review-rules.mdandpipelines.md. No blocking issues.For the reviewer:
controlnet_config.force_zeros_for_pooled_projection; the inpainting pipeline instead zeroes whenever the argument isNoneand never consults that flag. The issue's suggested fix would apply the text-to-image logic to both, but that is a behaviour change beyond fixing the crash, so I kept each pipeline's existing semantics. Happy to align them in a follow-up if you want that.Who can review?
@yiyixuxu @asomoza @hlky