TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

201. Backprop: ReLU

Easy

Hand-derive the gradient of L = sum(ReLU(x)) w.r.t. x.

Forward: y = max(0, x) element-wise. L = sum(y).

Implement:

  • relu_forward(x) -> y
  • relu_backward(x) -> dL/dx of the same shape as x

The harness verifies your analytic backward against central-differences of the forward. Note: the gradient at x = 0 is technically undefined; convention is to treat it as 0.

Math

∂x∂ReLU(x)​=1x>0​

Related problems

  • Backprop: ReLU (PyTorch)easyPyTorch

Asked at

NumPy

import numpy as np

 

def relu_forward(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?