Skip to content

Instantly share code, notes, and snippets.

@abderhasan
Created August 25, 2020 06:32
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 abderhasan/77feccf58bfebc85f685ec1217f3a9d9 to your computer and use it in GitHub Desktop.
Save abderhasan/77feccf58bfebc85f685ec1217f3a9d9 to your computer and use it in GitHub Desktop.
import torch
def f(x):
return x**3 + (2 * x)
x = torch.tensor(2.).requires_grad_()
y = f(x)
y.backward() #derivative
print(x.grad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment