Skip to content

Instantly share code, notes, and snippets.

@bpesquet
Last active October 28, 2020 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpesquet/0fdd5f0f7c2f569d906635038b63b9f8 to your computer and use it in GitHub Desktop.
Save bpesquet/0fdd5f0f7c2f569d906635038b63b9f8 to your computer and use it in GitHub Desktop.
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