home/ atoms/ residual-cfg

Residual CFG approximates classifier-free guidance at near-zero extra cost by recycling a stored noise residual

Classifier-Free Guidance (CFG) normally doubles the UNet workload: every step runs an unconditional pass and a conditional pass, then linearly combines them. StreamDiffusion’s Residual CFG (RCFG) avoids the repeated unconditional forward pass by keeping a running stock_noise buffer. Two modes: RCFG Self-Negative (cfg_type='self') uses the stored stock noise as the unconditional signal, computing in N steps (same cost as no-CFG); RCFG Onetime-Negative (cfg_type='initialize') runs one real unconditional pass at the first step only and then caches it, costing N+1 steps vs. the standard 2N. Full CFG (cfg_type='full') doubles the batch for every step. The delta parameter scales the stock noise, moderating guidance strength without a full unconditional forward. The paper reports RCFG Self-Negative at up to 2.05× faster than conventional CFG.

Examples

# RCFG Self-Negative — fastest, no negative prompt
stream = StreamDiffusion(pipe, [32,45], cfg_type='self')
stream.prepare(prompt='...', guidance_scale=1.2, delta=1.0)

# RCFG Onetime-Negative — one extra step, accepts negative_prompt
stream = StreamDiffusion(pipe, [32,45], cfg_type='initialize')
stream.prepare(prompt='...', negative_prompt='blurry', guidance_scale=1.4, delta=0.5)

Assessment

A practitioner wants guidance but no negative prompt and maximum speed. Which cfg_type should they choose, and what is its computational cost relative to cfg_type='full'? Then identify what delta controls.

“RCFG Self-Negative can be computed in N steps, while RCFG Onetime-Negative can be computed in N+1 steps.”
corpus · streamdiffusion-pipeline-for-real-time-interactive-image-gen · chunk 7