Add RectifiedClassifierFreeGuidance guider with rectified CFG coefficients - #36
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
rectified-diffusion-guidance-for-conditional-generation
branch
from
September 22, 2026 14:29
e0eba77 to
602d240
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 a new
RectifiedClassifierFreeGuidance(ReCFG) guider that relaxes CFG's sum-to-one coefficient constraint by rescaling the unconditional prediction with a rectification coefficientrho, so the two combination coefficients need not sum to one (the paper's central fix). This rectifies the guided prediction toward zero-expectation viagamma_0 = (1 - gamma_1) * rho, restoring the reverse-diffusion correspondence that improper CFG coefficients break, and reduces exactly to standard CFG whenrho == 1.Details:
rhoestimator (rectified_guidance_scale) computed per-sample from the conditional/unconditional prediction norm ratio, requiring no calibration data.rectification_scaleknob to interpolate between standard CFG (0.0) and full rectification (1.0), with full compatibility with the existing guider contract (guidance_rescale,use_original_formulation,start/stop,enabled).src/diffusers/guiders/__init__.pyandsrc/diffusers/__init__.py, with a matching dummy object for torch-less installs, so users canfrom diffusers import RectifiedClassifierFreeGuidance. It sits alongsideClassifierFreeGuidance/ClassifierFreeZeroStarGuidanceand is consumed through the sameBaseGuidanceabstraction (_input_predictions=['pred_cond', 'pred_uncond']).Intentionally out of scope (not required for this contribution):
rholookup table from a dataset pass — the per-step guider interface structurally cannot host it; an online per-sample norm-ratio proxy (in the spirit of CFG-Zero*) is substituted.Test results: the suite could not run in CI because the runner lacks this repo's dependencies (an import/collection error, not a code failure — e.g.
ModuleNotFoundError: No module named 'accelerate'while collectingexamples/). Please run the suite locally to validate.Before submitting
Who can review?
@yiyixuxu @sayakpaul
Drafted by Outrider — paper: arXiv:2410.18737.
Discovery context
Reference: https://github.com/thuxmf/recfg
Implements Rectified Diffusion Guidance for Conditional Generation. Reference license:
MIT(permissive, compat 1.00, source: github) — safe to adopt.Drafted by an autonomous discovery loop: Remyx ranks recent arXiv papers against this team's research interest (
[crossrepo-eval] huggingface/diffusers) and shipping history; Claude Code selects the most directly implementable candidate and drafts it.Why this paper: surfaced by an Outrider deep-search refine query (
guidance distillation classifier-free diffusion single-pass inference acceleration); the audit pass flagged an under-represented theme this paper covers that the normal ranking did not place in the broad pool.Why this candidate: ReCFG rectifies CFG's two-coefficient combination so the coefficients need not sum to one, operating purely on
pred_cond/pred_uncond— exactly the inputsBaseGuidance.forwardalready receives. It maps one-to-one onto the existing guider abstraction alongsideClassifierFreeGuidance/ClassifierFreeZeroStarGuidance, with a permissive-licensed reference implementation. CFG-Zero* from the same audit theme already ships asclassifier_free_zero_star_guidance.py; ReCFG is a strictly new, contract-equivalent guidance variant.Suggested experiment: (none)
Co-Authored-By: remyx-ai[bot] <289541483+remyx-ai[bot]@users.noreply.github.com>