Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-126

Yogi Update

Problem

Perform one Yogi update on a scalar parameter.

Update m as usual, then update v with v - (1 - beta2) * g ** 2 when v - g ** 2 > 0, otherwise v + (1 - beta2) * g ** 2. Bias-correct both moments and set x = x - lr * m_hat / (sqrt(v_hat) + eps). Return [x, m, v].

Hint

Yogi replaces the squared-gradient accumulation with a sign-based update.

Test cases

case 1
in: [1,0,0,0.5,1,0.1,0.9,0.999,1e-8]
expected: [0.900000002,0.04999999999999999,0.0002500000000000002]
case 2
in: [1,0.1,0.01,0.5,5,0.01,0.9,0.999,1e-8]
expected: [0.997614648985986,0.14,0.01025]
case 3
in: [-2,-0.3,0.4,1.2,10,0.05,0.8,0.99,1e-8]
expected: [-2,-5.551115123125783e-17,0.41440000000000005]
Starter codePython
def yogi_update(x, m, v, g, t, lr, beta1, beta2, eps):
    # Returns [x, m, v]
    # Your code here
    pass

3 test cases · run your code against them in the editor