Fix SEG _gaussian_blur_2d: finite blur_sigma is ignored (inverted infinite-blur branch)#14187
Open
XIONGPEILIN wants to merge 2 commits into
Open
Fix SEG _gaussian_blur_2d: finite blur_sigma is ignored (inverted infinite-blur branch)#14187XIONGPEILIN wants to merge 2 commits into
_gaussian_blur_2d: finite blur_sigma is ignored (inverted infinite-blur branch)#14187XIONGPEILIN wants to merge 2 commits into
Conversation
…d infinite-blur branch) In `_gaussian_blur_2d`, the `is_inf` (sigma > threshold) and finite-sigma branches are swapped relative to both this function's documented behavior and the original SEG-SDXL implementation it is "Copied/Modified from": - The guider/hook docs state "setting `blur_sigma` greater than 9999.0 results in infinite blur, which means uniform queries", i.e. sigma>threshold should yield the spatial mean, and a finite sigma should be an actual Gaussian blur. - Original SEG-SDXL (pipeline_seg.py L171-175): `if not inf_blur: gaussian_blur_2d(...); else: query.mean(...)`. The current code does the opposite: `if is_inf:` runs the Gaussian conv and `else:` (finite sigma) replaces the query with its spatial mean. As a result any finite `blur_sigma` is discarded and collapses to a uniform query, so sweeping finite sigma has no effect (e.g. sigma=4/16/32 produce byte-identical outputs). The bug is masked by the default `seg_blur_sigma=9999999.0`, which always took the conv branch (and with such a large sigma the kernel is ~uniform anyway). Fix: swap the branches so infinite blur -> spatial mean (exact uniform), finite sigma -> real 2D Gaussian blur of std `sigma`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Covers the fixed behavior: different finite `blur_sigma` values produce different outputs (and are not the uniform spatial mean), and `sigma` above the threshold equals the exact spatial mean. These tests fail on the previous (inverted-branch) implementation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 a branch inversion in
SmoothedEnergyGuidanceHook/_gaussian_blur_2d(
src/diffusers/hooks/smoothed_energy_guidance_utils.py) where the finite-sigma andinfinite-blur code paths are swapped. As a result any finite
blur_sigmais silentlydiscarded and replaced by a uniform (spatial-mean) query, so sweeping finite sigma has no effect.
The bug
This is inverted relative to:
seg_blur_sigmastates:"Setting this value greater than 9999.0 results in infinite blur, which means uniform queries."
i.e.
sigma > thresholdshould give the spatial mean, and a finite sigma should be an actualGaussian blur.
(pipeline_seg.py#L171-L175):
Because the default
seg_blur_sigma=9999999.0always takes the (huge-sigma ≈ uniform) conv branch,the bug is masked for default usage and only surfaces when a finite sigma is requested.
Reproduction
On
main, different finite sigmas are byte-identical (max|sig4 - sig32| = 0.0). With this PR theydiffer (larger sigma smooths more), while
sigma > thresholdreturns the exact spatial mean.Fix
Swap the two branches:
is_inf→ spatial mean (exact uniform queries); finite sigma → the real 2DGaussian blur of standard deviation
sigma.Note on behavior change
For the default (
sigma > threshold) the output changes from a huge-kernel Gaussian conv (anapproximate uniform) to the exact spatial mean — matching the documented "uniform queries".
Finite
blur_sigmavalues now actually control the blur amount. SEG is marked experimental in thecode, so this may affect users who relied on the (buggy) finite-sigma-as-uniform behavior.
Before submitting
ruff check/ruff formatpass on the changed file.