Add semantic-aware CFG guider with per-region scale map - #37
Open
remyx-ai[bot] wants to merge 2 commits into
Open
remyx-ai[bot] wants to merge 2 commits into
remyx-ai[bot] wants to merge 2 commits into
Conversation
Convention-shape patches extracted from huggingface/diffusers's recent merged PRs. Algorithm logic is left untouched. Ruff auto-fixed lint-trivial issues on patched files.
remyx-ai
Bot
force-pushed
the
rethinking-the-spatial-inconsistency-in-classifier-free-diff
branch
from
September 23, 2026 14:23
6e26a58 to
5137bfa
Compare
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?
Adds
SemanticAwareGuidance(S-CFG), a newBaseGuidancesubclass exported fromdiffusers.guiders(src/diffusers/guiders/__init__.py) — the same import surface modular pipelines and external users pull guiders from (e.g.from diffusers.guiders import SemanticAwareGuidance). It delivers the paper's core result: a spatially-varying per-region CFG scale map replaces the scalarguidance_scale, boosting under-guided regions and damping over-guided ones to fix the paper's targeted 'spatial inconsistency'.Delivers (from the paper):
semantic_scale_map) that computes local guidance magnitude as the channel-norm ofpred_cond - pred_uncond, pools it over awindow_sizeneighborhood for region-level granularity, rescales each position toward the per-sample mean strength, and clamps to[gs/rescale_clamp, gs*rescale_clamp]for well-conditioned guidance.forwardemitspred = pred_uncond + scale_map*(pred_cond - pred_uncond),_input_predictions,prepare_inputs,num_conditions, start/stop scheduling,guidance_rescale,use_original_formulation), so it drops in wherever the other 12 guiders are used.ndim != 4, e.g. sequence-shaped transformer outputs).Intentionally out of scope (not needed for this contribution):
pred_cond/pred_uncond, and it is architecture-specific (would require per-model attention hooks inprepare_models). A parameter-free local-magnitude pooling proxy stands in for it.HookRegistrywiring analogous toperturbed_attention_guidance.py— deliberately avoided since the magnitude proxy needs no hooks, keeping the guider model-agnostic.diffusers.__init__export and lazy-import registration (the existingMagnitudeAwareGuidanceis likewise only exported from theguiderssubpackage, so this matches repo precedent).Test results
ℹ️ Tests could not run in CI — the runner lacks this repo's dependencies (a collection/import error, not a code failure). Run the suite locally to validate.
Before submitting
Who can review?
@yiyixuxu @sayakpaul
Drafted by Outrider — paper: arXiv:2404.05384.
Discovery context
Research interest: [crossrepo-eval] huggingface/diffusers
Implementation by: Claude Code as autonomous agent
Why this paper for this team: Surfaced by Outrider deep-search refine query
guidance distillation classifier-free single-step diffusion sampling accelerationagainst /search/assets. The engine's normal ranking did not place this paper in the interest's broad pool — it's here because the audit pass identified an under-represented theme this paper covers.Why this candidate (selected from the lookback pool): S-CFG's contribution is a per-region spatial CFG scale map (derived from cross/self-attention to equalize semantic strengths) replacing the scalar guidance_scale — it drops in as a new BaseGuidance subclass whose forward emits pred = pred_uncond + scale_map*(pred_cond-pred_uncond), exactly the existing guider contract. The attention-hook infrastructure it needs already exists (perturbed_attention_guidance.py registers HookRegistry hooks in prepare_models), and spatially/adaptively varying the CFG scale already has precedent in the module (magnitude_aware), so this is a clean net-new guider alongside the existing 12 with no duplication.
Suggested experiment: (none)
License & code availability: 🔴 No LICENSE file detected — no legal permission to redistribute or modify the code. Treat as blocking until upstream adds a license. License:
(none detected)(class:missing, compat: 0.00, source:arxiv_html_retry).Reference: https://github.com/SmilesDZgk/S-CFG
Opened by the Remyx Recommendation orchestrator.
Co-Authored-By: remyx-ai[bot] <289541483+remyx-ai[bot]@users.noreply.github.com>