Guidance Rescaling to Fix Over-Exposure
Problem Statement
High CFG scales inflate the predicted-noise magnitude, over-exposing images. Lin et al.'s guidance rescale trick renormalizes the guided prediction back toward the conditional prediction's standard deviation. Implement it.
Background
Let eps_cfg be the guided prediction and eps_cond the plain conditional one. Compute their standard deviations (over all elements, population std), rescale the guided prediction to the conditional's std, then blend by a factor phi:
phi = 0 disables the fix; phi = 1 fully rescales. If std(eps_cfg) is 0, skip the rescale (return eps_cfg).
Your Task
Implement:
def guidance_rescale(eps_cfg, eps_cond, phi):
Return the final prediction as a list rounded to 4 decimals.
Input Format
- eps_cfg, eps_cond: lists of equal length D.
- phi (float) in [0, 1].
Output Format
- A list of D floats rounded to 4 decimals.
Sample
print(guidance_rescale([2.0, -2.0], [1.0, -1.0], 1.0))
Output:
[1.0, -1.0]
Example
print(guidance_rescale([2.0, -2.0], [1.0, -1.0], 1.0))
[1.0, -1.0]
- Compute the population standard deviation of the guided prediction
eps_cfg = [2.0, -2.0]. The mean is , so . - Compute the population standard deviation of the conditional prediction
eps_cond = [1.0, -1.0]. The mean is , so . - Since , calculate the rescaled prediction by scaling
eps_cfgby the ratio of the standard deviations: . - Blend the rescaled prediction with the original guided prediction using . This fully applies the rescaling: .
- The final output is [1.0, -1.0]
Constraints
len(eps_cfg) == len(eps_cond),0 <= phi <= 1.- Use population std (ddof=0) over all elements.
- If
std(eps_cfg) == 0, returneps_cfgunchanged. - Round to 4 decimals; avoid
-0.0.