Hi all,
I have some questions that prevent me from understanding PyTorch completely. They relate to how a Computation Graph is created and freed? For example, if I have this following piece of code:
import torch

for i in range(100):
    a = torch.autograd.Variable(torch.randn(2, 3).cuda(), requires_grad=True)
    y = torch.sum(a)
    y.backward()


Does it mean that each time I run the code in a loop, it will create a completely new computation graph and the graph from the previous loop is freed from buffer?
If I call y.backward() like above, will the computation graph within that loop be freed from buffer?
If the graph is not freed, can I treat it as a static computation graph and do something like the code below?

Code:
import torch

# a like a placeholder
a = torch.autograd.Variable(torch.randn(2, 3).cuda(), requires_grad=True)
y = torch.sum(a)

for i in range(100):
    a.data = torch.randn(2, 3).cuda()  # Only modify its data
    y.forward()  # Call a forward over y (computed using pre-built graph)
    y.backward()  # Backward on built graph