Classifier-Free Guidance
~10 mincode completion
Implement classifier_free_guidance(eps_uncond, eps_cond, w) returning of the same shape.
Examples
w=0 returns the unconditional prediction
- Input
- classifier_free_guidance([1, 2], [9, 9], 0)
- Output
- [1, 2]
w=1 returns the conditional prediction
- Input
- classifier_free_guidance([1, 2], [4, 6], 1)
- Output
- [4, 6]
w=2 overshoots: 1 + 2*(3-1) = 5
- Input
- classifier_free_guidance(1, 3, 2)
- Output
- 5
Hints
Hint 1
Convert the input with before doing elementwise work.
Hint 2
Reach for an extrapolation rather than w as a convex blend.
Requirements
: guidance scale
Return array, same shape
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~10 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 enterprise vendor, 1 defense company, 1 health and bio company, 1 AI product company. Top match scores 87.
Python
import numpy as np
def classifier_free_guidance(eps_uncond, eps_cond, w):
"""
eps = eps_uncond + w * (eps_cond - eps_uncond).
Args:
eps_uncond, eps_cond: arrays of the same shape
w: guidance scale
Returns:
array, same shape
"""
# YOUR CODE HERE
pass