Skip to content

Instantly share code, notes, and snippets.

@tridungduong16
Last active August 11, 2018 14:13
Show Gist options
  • Save tridungduong16/1c079ad2467d41bb7b8d77ae67e288cc to your computer and use it in GitHub Desktop.
Save tridungduong16/1c079ad2467d41bb7b8d77ae67e288cc to your computer and use it in GitHub Desktop.
Pytorch learning

Variable and Tensor

a = torch.Tensor(
    [
        [1,2],
        [3,4]
    ]
)

print(a**2)`
from torch.autograd import Variable

a = Variable(torch.Tensor(
    [
        [1,2],
        [3,4]
    ]
),requires_grad=True)

y = torch.sum(a**2) #y = 30
print(y)

y.backward() #gradient of y on a
print(a.grad) 

Computation Graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment