Last active
October 28, 2020 19:14
-
-
Save bpesquet/0fdd5f0f7c2f569d906635038b63b9f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from micrograd.engine import Value | |
# Create a managed scalar value | |
x = Value(-4.0) | |
z = 2 * x + 2 + x # z = -10 | |
q = z.relu() + z * x # q = 40 | |
h = (z * z).relu() # h = 100 | |
y = h + q + q * x # y = -20 | |
# Compute gradients w.r.t. input values | |
y.backward() | |
print(x.grad) # dy/dx = 46 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment