Adaptive CFG Scheduling over the Trajectory
Problem Statement
A single fixed guidance scale is suboptimal: strong guidance early adds detail, strong guidance late over-saturates. Implement a linearly interpolated CFG schedule and apply it across a batch of per-step noise predictions.
Background
Given K sampling steps ordered from first (high noise) to last (low noise), the guidance scale ramps linearly from w_start at step 0 to w_end at step K-1:
(with w_0 = w_start when K == 1). At each step apply CFG with that step's scale:
Your Task
Implement:
def scheduled_cfg(eps_uncond, eps_cond, w_start, w_end):
- eps_uncond[k], eps_cond[k]: the per-step predictions (each a list of length D), K steps total.
Return the list of K guided predictions, each a list rounded to 4 decimals.
Input Format
- eps_uncond, eps_cond: K x D nested lists.
- w_start, w_end (float).
Output Format
- A K x D nested list rounded to 4 decimals.
Sample
u = [[0.0], [0.0], [0.0]]
c = [[1.0], [1.0], [1.0]]
print(scheduled_cfg(u, c, 10.0, 2.0))
Output:
[[10.0], [6.0], [2.0]]
Example
u = [[0.0], [0.0], [0.0]] c = [[1.0], [1.0], [1.0]] print(scheduled_cfg(u, c, 10.0, 2.0))
[[10.0], [6.0], [2.0]]
- Determine the number of steps and compute the linearly interpolated guidance scales for using , yielding , , and .
- Calculate the difference between conditional and unconditional predictions for each step: for all .
- Apply the CFG formula at step 0 to get .
- Apply the formula at step 1 to get .
- Apply the formula at step 2 to get .
- The final output is [[10.0], [6.0], [2.0]]
Constraints
len(eps_uncond) == len(eps_cond) == K,K >= 1; rows share lengthD.w_kramps linearly fromw_start(k=0) tow_end(k=K-1);K==1usesw_start.- Per step:
eps_uncond + w_k*(eps_cond - eps_uncond); round to 4 decimals; avoid-0.0.