Skip to content

Add RectifiedClassifierFreeGuidance guider with rectified CFG coefficients - #36

Open
remyx-ai[bot] wants to merge 2 commits into
mainfrom
rectified-diffusion-guidance-for-conditional-generation
Open

remyx-ai[bot] wants to merge 2 commits into
mainfrom
rectified-diffusion-guidance-for-conditional-generation

Conversation

@remyx-ai

@remyx-ai remyx-ai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

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 coefficient rho, so the two combination coefficients need not sum to one (the paper's central fix). This rectifies the guided prediction toward zero-expectation via gamma_0 = (1 - gamma_1) * rho, restoring the reverse-diffusion correspondence that improper CFG coefficients break, and reduces exactly to standard CFG when rho == 1.

Details:

  • A parameter-free online rho estimator (rectified_guidance_scale) computed per-sample from the conditional/unconditional prediction norm ratio, requiring no calibration data.
  • A rectification_scale knob 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).
  • Wired into the public API: exported from src/diffusers/guiders/__init__.py and src/diffusers/__init__.py, with a matching dummy object for torch-less installs, so users can from diffusers import RectifiedClassifierFreeGuidance. It sits alongside ClassifierFreeGuidance / ClassifierFreeZeroStarGuidance and is consumed through the same BaseGuidance abstraction (_input_predictions=['pred_cond', 'pred_uncond']).

Intentionally out of scope (not required for this contribution):

  • The paper's offline calibration procedure that precomputes a per-timestep rho lookup 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.
  • The theoretical derivation/proofs that CFG cannot be expressed as a reciprocal diffusion process (informational, not a code deliverable).
  • End-to-end pipeline benchmark / FID reproduction of the paper's quality gains (requires model weights, datasets, and eval infra not hosted here).

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 collecting examples/). Please run the suite locally to validate.

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.)? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
  • Did you read the contributor guideline?

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 inputs BaseGuidance.forward already receives. It maps one-to-one onto the existing guider abstraction alongside ClassifierFreeGuidance/ClassifierFreeZeroStarGuidance, with a permissive-licensed reference implementation. CFG-Zero* from the same audit theme already ships as classifier_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>

@remyx-ai remyx-ai Bot added outrider:needs-judgment Outrider refinement chain stage label outrider:fidelity-done Outrider refinement chain stage label labels Sep 22, 2026
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
remyx-ai Bot force-pushed the rectified-diffusion-guidance-for-conditional-generation branch from e0eba77 to 602d240 Compare September 22, 2026 14:29
@remyx-ai remyx-ai Bot removed the outrider:fidelity-done Outrider refinement chain stage label label Sep 22, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 22, 2026
@remyx-ai
remyx-ai Bot marked this pull request as ready for review September 22, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation guiders outrider:needs-judgment Outrider refinement chain stage label tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants