Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import torch
- from torch.autograd import Variable
- x = Variable(torch.Tensor([1.1]),requires_grad=True)
- y = Variable(torch.Tensor([1.2]),requires_grad=True)
- # define two simple graphs
- z = x * y
- a = torch.exp(x)
- b = torch.exp(a)
- # how can i access x and y starting from z?
- print "x:\n", z.grad_fn.saved_variables[0]
- print "y:\n", z.grad_fn.saved_variables[1]
- # how can i access a and x starting from b?
- # db/da = b, so a doesn't appear in b.grad_fn.saved_varibles
- # rather, b appears there
- print "b:\n", b.grad_fn.saved_variables[0]
- # similarily we have
- print "a:\n", a.grad_fn.saved_variables[0]
- # but what allows me to connect b <- a <- x ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement