Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import torch
  2. from torch.autograd import Variable
  3.  
  4. x = Variable(torch.Tensor([1.1]),requires_grad=True)
  5. y = Variable(torch.Tensor([1.2]),requires_grad=True)
  6.  
  7. # define two simple graphs
  8.  
  9. z = x * y
  10.  
  11. a = torch.exp(x)
  12. b = torch.exp(a)
  13.  
  14. # how can i access x and y starting from z?
  15.  
  16. print "x:\n", z.grad_fn.saved_variables[0]
  17. print "y:\n", z.grad_fn.saved_variables[1]
  18.  
  19. # how can i access a and x starting from b?
  20. # db/da = b, so a doesn't appear in b.grad_fn.saved_varibles
  21. # rather, b appears there
  22.  
  23. print "b:\n", b.grad_fn.saved_variables[0]
  24.  
  25. # similarily we have
  26.  
  27. print "a:\n", a.grad_fn.saved_variables[0]
  28.  
  29. # but what allows me to connect b <- a <- x ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement