Classifier-Free Guidance (CFG), which combines the conditional and unconditional score functions with two coefficients summing to one, serves as a practical technique for diffusion model sampling. Theoretically, however, denoising with CFG \textit{cannot} be expressed as a reciprocal diffusion process, which may consequently leave some hidden risks during use. In this work, we revisit the theory behind CFG and rigorously confirm that the improper configuration of the combination coefficients (\textit{i.e.}, the widely used summing-to-one version) brings about expectation shift of the generative distribution. To rectify this issue, we propose ReCFG with a relaxation on the guidance coefficients such that denoising with \method strictly aligns with the diffusion theory. We further show that our approach enjoys a \textbf{\textit{closed-form}} solution given the guidance strength. That way, the rectified coefficients can be readily pre-computed via traversing the observed data, leaving the sampling speed barely affected. Empirical evidence on real-world data demonstrate the compatibility of our post-hoc design with existing state-of-the-art diffusion models, including both class-conditioned ones (\textit{e.g.}, EDM2 on ImageNet) and text-conditioned ones (\textit{e.g.}, SD3 on CC12M), without any retraining. Code is available at \href{https://github.com/thuxmf/recfg}{https://github.com/thuxmf/recfg}.
翻译:无分类器引导(CFG)通过将条件与无条件评分函数以系数和为1的方式结合,已成为扩散模型采样的实用技术。然而,理论上,使用CFG进行去噪*无法*表示为逆向扩散过程,这可能在应用中带来潜在风险。本文重新审视CFG的理论基础,严格证实组合系数的不当配置(即广泛使用的系数和为1版本)会导致生成分布的期望偏移。为修正此问题,我们提出ReCFG,通过放宽引导系数约束,使得使用\method的去噪过程严格符合扩散理论。我们进一步证明,给定引导强度时,该方法存在*闭式解*。因此,修正后的系数可通过遍历观测数据预先计算,几乎不影响采样速度。真实数据上的实证研究表明,我们的后验设计兼容现有最先进的扩散模型,包括类别条件模型(如ImageNet上的EDM2)和文本条件模型(如CC12M上的SD3),且无需重新训练。代码发布于\href{https://github.com/thuxmf/recfg}{https://github.com/thuxmf/recfg}。